animation - Using keyframe() to display nested dictionary info using Python in Maya -


i need doing following:

using keyframe method (and flags) extract information selected set of keys store them in nested dictionary. these keyframes correspond animation has keyframes copied pasting onto other joints needed. i've been combing through documentation , different sources on net running animation terms , concepts i'm not familiar with. later access dictionary display keyframe information in nicely formatted window artist i'm writing can see effect before pasting animation.

my code part far:

else:     key_list = mc.copykey()      # check see if window exists     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 layout 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 info transferred - here use        #keyframe() instead -- getting error because copykey() returns     #int not iterable. can see return value copykey      #is being stored in key_list.     key in key_list:     display_info = mc.textfieldgrp(label="copy value", editable=false, text=key_list[item]) 

link documentation: http://download.autodesk.com/us/maya/2011help/commandspython/keyframe.html

it sounds flags need application -vc, gets values , -tc, times (when combined -q flag query.

if want dictionary of keys values, it's using dict() , zip():

def keys_as_dictionary(channel):     """return dictionay of times:values <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 dictionary of <plug>:<channel_dict> each animated plug on <object>"""     keys = cmds.keyframe(object, n=true, q=true)     result = {}      k in keys:         plugs = cmds.listconnections(k, p=true)[0]         result[plugs]= keys_as_dictionary(k)     return result 

calling channels() on object give dictionary keyed animation curve values dictionaries of times , values:

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}} 

word of warning: should work plain animated objects, not doing smart shared animation curves, instanced nodes, constraints or locked channels.... fyi....


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -