[Python Script Development] Return True or False if that attribute is keyframed

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  06 June 2013
[Python Script Development] Return True or False if that attribute is keyframed

Hi guys, i'm trying to complete my script and i had some issues.
Here my script :
-------------------------------------------------------------------------------------------------------------------------------------
from maya import cmds
def correct_value(selection=None, prefix='', suffix=''):

newSel = []
if selection is None:
selection = cmds.ls ('*_control')

if selection and not isinstance(selection, list):
newSel = [selection]

for each_obj in selection:
if each_obj.startswith(prefix) and each_obj.endswith(suffix) :
newSel.append(each_obj)
return newSel

def save_pose(selection):

pose_dictionary = {}

for each_obj in selection:
pose_dictionary[each_obj] = {}
for each_attribute in cmds.listAttr (each_obj, k=True):
pose_dictionary[each_obj][each_attribute] = cmds.getAttr (each_obj + "." + each_attribute)

return pose_dictionary


controller = correct_value(None,'left' ,'control' )


save_pose(controller)


def save_animation(selection, **keywords ):
if "framesWithKeys" not in keywords:
keywords["framesWithKeys"] = [0,1,2,3]

animation_dictionary = {}
for each_frame in keywords["framesWithKeys"]:
cmds.currentTime(each_frame)
animation_dictionary[each_frame] = save_pose(selection)

return animation_dictionary

frames = save_animation (save_pose(controller) )
print frames


Now when i'm querying an attribute, i want to store a True or False value in the dictionary that says if that attribute has a keyframe at that frame you are checking, but only if it has a key on that frame.
For example let say I have keys on my control's tx attribute at frames 1 and 5,i want to have a dictionary key that I can check later to see if there were keys at those frames, when there is a key at that frame return true, when there isn't return false.
If True , i also want to save the tangent types of the keys.

Is there anyone who can help me ?
Thank You.
 
  06 June 2013
BTW use the code # tag to wrap your script it will make it more readable here.

Well to do what you want you'll need to test the attribute to see if it's connected to an animCurve, then get an index of keyframes from that curve and if there is a keyframe at the current time and store the othe rinfo you want.

This should on list animation curves connected to the given node and attribute.
list = cmds.listConnections('BALL.tx', source=True, type='animCurve')

or maybe just use keyframe..

# Query all keyframes of object "surface1" within the time range 0 to 20. # cmds.keyframe( 'surface1', time=(0,20), query=True, valueChange=True, timeChange=True); 


etc...
__________________
blah blah blah
 
  06 June 2013
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 11:03 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.