"全局名称未定义" - 在maya python中

0 python maya

我正在为Maya编写一个简单的工具,我尝试在另一个中调用基本函数.但我总是得到:global name "baseShape" is not defined.

以下是我的代码片段,其中包含错误:

class correctiveShaper():
    def __init__(self):
        #class variable
         self.app = {}

        #call on the build UI
         self.buildUI()

    def buildUI(self, *args):
        cmds.separator(h=30)
        cmds.button(label="Create Shape", w=295, h=30, al="right", c= baseShape)

    def baseShape (self, *args) : 
        self.app["sel"]=cmds.ls(sl=True)[0]
Run Code Online (Sandbox Code Playgroud)

Python不会让我执行c = baseShape命令def buildUI,我不知道为什么.

Mar*_*ers 5

您需要使用它self来引用实例上的方法:

cmds.button(label="Create Shape", w=295, h=30, al="right", c=self.baseShape)
Run Code Online (Sandbox Code Playgroud)

方法不是全局变量.通过使用,self.baseShape您将获得一个绑定方法,一个知道如何在调用时将实例传递给方法的对象.