我不明白爲什麼我的列表dosn't沒有返回到類,並在我呼叫第二個函數後停留在這裏,這裏是我的代碼:將在一個變量中創建的列表傳遞給類中的另一個變量(PYTHON)
class ShockAbsorber:
'''create Proxy, based of 2 locators'''
def createProxy(self):
self.allLoc = {}
self.allLoc["CylinderLoc"] = pm.spaceLocator (n = "Cylinder_Loc")
self.allLoc["PistonLoc"] = pm.spaceLocator (n = "Piston_Loc", p =[0,30,0])
pm.CenterPivot()
'''create bones on locators'''
def createRig(self):
for name,loc in self.allLoc.items():
print Loc
我有一個分離文件的接口,爲每個函數創建2個按鈕。
#define button Create Proxy
def CreateProxyPressed(self):
csa = sa.ShockAbsorber()
csa.createProxy()
#define button Create Proxy
def CreateRigPressed(self):
csa = sa.ShockAbsorber()
csa.createRig()
如果我跑我的代碼我recive此錯誤消息:
AttributeError: ShockAbsorber instance has no attribute 'allLoc'
我希望這是足夠多的信息,讓你瞭解我的問題,I'm besically書寫工具對於「歐特克瑪雅」 。我很確定我的觀念是正確的,所以我做錯了什麼?
預先感謝您!
P.S.對於混淆,我很抱歉,但是我發現我的錯字後,現在編輯了我的代碼以保持正確!
在'CreateRigPressed'中,創建'ShockAbsorber'的新實例並調用'csa.createRig()'。這個實例沒有'allLoc'。 – Matthias
好吧,謝謝! 解決方案應該是這樣對我的按鈕功能: 'code' \t#定義按鈕,創建代理 \t高清CreateProxyPressed(個體經營): \t \t self.csa = sa.ShockAbsorber() \t \t self.csa.createProxy( ) \t \t#定義按鈕,創建代理 \t高清CreateRigPressed(個體經營): \t \t self.csa.createRig() – user2042999