Вопрос

I get this error in maya 2012 and not sure how to fix, I am trying to have python ignore the init file when searching for the other files within the folder. Any suggestions would be much appreciated.

Error: 'NoneType' object is not iterable
Traceback (most recent call last):
  File "<maya console>", line 18, in <module>
  File "E:/3D/maya/2012-x64/scripts/RiggingTool/Modules\System\blueprint_UI.py" line 28, in __init__
    self.initialiseModuleTab(tabHeight, tabWidth)
  File "E:/3D/maya/2012-x64/scripts/RiggingTool/Modules\System\blueprint_UI.py", line 50, in initialiseModuleTab
    for module in utils.findAllModules("Modules/Blueprint"):
  File "E:/3D/maya/2012-x64/scripts/RiggingTool/Modules\System\utils.py", line 8, in findAllModules
    for file in allPyFiles:
TypeError: 'NoneType' object is not iterable

Main code is

import maya.cmds as cmds

import System.utils as utils
reload(utils)

class Blueprint_UI:
    def __init__(self):
        # Store UI elements in a dictionary
        self.UIElements = {}

        if cmds.window("blueprint_UI_window", exists=True):
            cmds.deleteUI("blueprint_UI_window")

        windowWidth = 400
        windowHeight = 598

        self.UIElements["window"] = cmds.window("blueprint_UI_window", width=windowWidth, height=windowHeight, title="Blueprint Module UI", sizeable=False)

        self.UIElements["topLevelColumn"] = cmds.columnLayout(adjustableColumn=True, columnAlign="center")

        # Setup tabs
        tabHeight = 500
        self.UIElements["tabs"] = cmds.tabLayout(height=tabHeight, innerMarginWidth=5, innerMarginHeight=5)

        tabWidth = cmds.tabLayout(self.UIElements["tabs"], q=True, width=True)
        self.scrollWidth = tabWidth - 40

        self.initialiseModuleTab(tabHeight, tabWidth)

        cmds.tabLayout(self.UIElements["tabs"], edit=True, tabLabelIndex=([1, "Modules"]))


        # Display window
        cmds.showWindow( self.UIElements["window"] )

    def initialiseModuleTab(self, tabHeight, tabWidth):
        scrollHeight = tabHeight # temp value

        self.UIElements["moduleColumn"] = cmds.columnLayout(adj=True, rs=3)

        self.UIElements["moduleFrameLayout"] = cmds.frameLayout(height=scrollHeight, collapsable=False, borderVisible=False, labelVisible=False)

        self.UIElements["moduleList_Scroll"] = cmds.scrollLayout(hst=0)

        self.UIElements["moduleList_column"] = cmds.columnLayout(columnWidth = self.scrollWidth, adj=True, rs=2)

        # First separator
        cmds.separator()

        for module in utils.findAllModules("Modules/Blueprint"):    
            print module

the code that searches for files within the folder:

def findAllModules(relativeDirectory):
    # Search the relative directory for all available modules
    # Return a list of all module names (excluding the ".py" extension)
    allPyFiles = findAllFiles(relativeDirectory, ".py") 

    returnModules = []

    for file in allPyFiles:
        if file != "__init__":
            returnModules.append(file)

    return returnModules    


def findAllFiles(relativeDirectory, fileExtension):
    # Search the relative directory for all files with the given extension
    # Return a list of all file names, excluding the file extension
    import os

    fileDirectory = os.environ["RIGGING_TOOL_ROOT"] + "/" + relativeDirectory + "/"

    allFiles = os.listdir(fileDirectory)

    # refine all files, listing only those of the specified file extension
    returnFiles = []
    for f in allFiles:
        splitString = str(f).rpartition(fileExtension)

        if not splitString[1] == "" and splitString[2] == "":
            returnFiles.append(splitString[0])


      print returnFiles

when I add this code within the main it breaks

  for module in utils.findAllModules("Modules/Blueprint"):

also within the __init__ file search code if I add the bottom code I get the error

returnModules = []

for file in allPyFiles:
    if file != "__init__":
        returnModules.append(file)

return returnModules

I'm not sure exactly how I am getting the NoneType Error because the bottom two codes look correct to me can anyone help please?

Это было полезно?

Решение

Change print returnFiles to return returnFiles.

Другие советы

You're not returning returnFiles from findAllFiles(), so it's returning None--which is not iterable.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top