2013-02-05 21 views
0

我不明白爲什麼我的列表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.對於混淆,我很抱歉,但是我發現我的錯字後,現在編輯了我的代碼以保持正確!

+0

在'CreateRigPressed'中,創建'ShockAbsorber'的新實例並調用'csa.createRig()'。這個實例沒有'allLoc'。 – Matthias

+0

好吧,謝謝! 解決方案應該是這樣對我的按鈕功能: '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

回答

0

您需要存儲allLoc的類的實例,並沒有返回它:

def createProxy(self, *args): 
    allLoc = {} 
    allLoc["CylinderLoc"] = pm.spaceLocator (n = "Cylinder_Loc") 
    allLoc["PistonLoc"] = pm.spaceLocator (n = "Piston_Loc", p =[0,30,0]) 
    pm.CenterPivot() 
    self.allLoc = allLoc 
+0

我很抱歉,你是正確的是絕對有關(我忘了改變的代碼位後,許多嘗試),但是這不是解決同樣的問題。 (無論如何,我會編輯我的代碼,看看你是否更好理解。 – user2042999

0

createProxy需要設置self.allLoc。您只設置當地名稱allLoc

相關問題