2015-07-20 31 views
0

我正在爲Maya編寫一個簡單的工具,我嘗試在另一個函數中調用基本函數。但我總是得到:global name "baseShape" is not defined「全局名稱未定義」 - 在maya python中

這裏是我的代碼有錯誤的代碼段:

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] 

Python將不會讓我在def buildUI執行c = baseShape命令,我不知道爲什麼。

回答

4

您需要使用self引用的實例方法:

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

方法是不是全局。通過使用,您將獲得一個綁定方法,該對象知道如何在調用實例時將該實例傳遞給該方法。