2015-04-25 35 views
0

我需要幫助做以下幾點:使用關鍵幀(),以顯示嵌套使用Python字典信息在Maya

使用關鍵幀方法(和標誌)來提取選定的一組按鍵的信息將它們存儲在嵌套字典。這些關鍵幀對應於動畫,根據需要將所有關鍵幀複製粘貼到其他關節上。我一直在梳理網絡上的文檔和不同的資源,但我正在使用我不熟悉的動畫術語和概念。 我稍後將訪問此字典,以在格式良好的窗口中顯示關鍵幀信息,以便我爲此寫作的藝術家可以在粘貼動畫之前查看效果。

我給這部分至今代碼:

else: 
    key_list = mc.copyKey() 

    # check to see if window exists already 
    if mc.window(copyAnim, exists = True): 
     mc.deleteUI(copyAnim) 

    # create window 
    copyAnim = mc.window(title="Transfer Animation Tool", backgroundColor= [0.3,0.3,0.3],sizeable=False,resizeToFitChildren=True) 

    #set the layout for UI 
    mc.columnLayout(adjustableColumn=True) 
    tx_src = mc.textFieldGrp(label="Source Object", editable=False, text=sel[0]) 
    int_offset = mc.intFieldGrp(label="Frame Offset Amount", value1=0) 

    #displaying what info will be transferred - here is where I would use 
    #keyframe() instead -- getting an error because copyKey() returns an 
    #int which is not iterable. As you can see the return value for copyKey 
    #is being stored in key_list. 
    for key in key_list: 
    display_info = mc.textFieldGrp(label="Copy Value", editable=False, text=key_list[item]) 

鏈接到文件: http://download.autodesk.com/us/maya/2011help/CommandsPython/keyframe.html

+0

您是否在尋找關於如何在UI中顯示信息或者如何解釋信息的建議? – theodox

+0

我在尋找的是如何使用關鍵幀方法(或其他適當的方法)將關鍵幀信息存儲在嵌套字典中。我不確定如何使用此方法的標誌。稍後我將處理GUI顯示問題。 – BakMamba74

回答

1

這聽起來像你需要爲這個應用程序的唯一標誌是-vc,它可以讓你的價值觀和-tc ,這會得到你的時間(當與-q標誌組合在一起,梅毒,它基本上只是使用dict()zip()

def keys_as_dictionary(channel): 
    """return a dictionay of times:values for <channel>""" 
    keys = cmds.keyframe(channel, q=True, tc=True) or [] 
    values = cmds.keyframe(channel, q=True, vc=True) or [] 
    return dict(zip(keys, values)) 

def channels(object): 
    """return a dictionary of <plug>:<channel_dict> for each animated plug on <object>""" 
    keys = cmds.keyframe(object, n=True, q=True) 
    result = {} 

    for k in keys: 
     plugs = cmds.listConnections(k, p=True)[0] 
     result[plugs]= keys_as_dictionary(k) 
    return result 

的對象上調用channels()會給你回來動畫曲線鍵一本字典其中的值的時間和值的字典:

import pprint 
pprint.pprint(channels('pCube2')) 

{u'pCube2.translateX': {4.955: 4.164464499411458, 
         10.89: -0.8212519883789916, 
         15.465: -0.6405074625130949, 
         22.65: -1.7965970091598258}, 
u'pCube2.translateY': {4.955: 8.271115169656772, 
         10.89: 0.3862609404272041, 
         15.465: 7.77669517461548, 
         22.65: 0.6892861215369379}, 
u'pCube2.translateZ': {4.955: -1.4066258181614297, 
         10.89: -4.891368771063121, 
         15.465: 4.340776804349586, 
         22.65: -3.5676492042261776}} 

警告詞:這應該適用於普通動畫對象,但對共享動畫曲線,實例化節點,約束或鎖定通道沒有做任何明智之舉....僅供參考....