0

我在 Maya 2012 中收到此错误,不知道如何修复,我试图让 python在搜索文件夹中的其他文件时忽略初始化文件。任何建议将不胜感激。

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

主要代码是

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

在文件夹中搜索文件的代码:

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

当我在 main 中添加此代码时,它会中断

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

__init__如果我添加底部代码,也会在文件搜索代码中出现错误

returnModules = []

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

return returnModules

我不确定我到底是如何得到 NoneType 错误的,因为底部的两个代码对我来说看起来是正确的,有人可以帮忙吗?

4

2 回答 2

2

更改print returnFilesreturn returnFiles

于 2013-04-06T09:29:12.160 回答
1

你没有returnFiles从回来findAllFiles(),所以它正在返回——这None是不可迭代的。

于 2013-04-06T09:29:50.937 回答