Get length of object's animation in frames (not number of total keyframes)

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
Old 04 April 2013   #1
Get length of object's animation in frames (not number of total keyframes)

I'm trying to get the length of an object's animation in frames.

let's say it's 100 frames long. I can use:
mc.keyframe( 'object', query=True, keyframeCount=True )

but if I have 6 attributes keyed (translation and rotation attributes), keyframeCount will return 600 instead of 100. My though it to just take this number and divide by the number of attributes keyed on the object, but I'm not sure how to retrieve this number (which would be 6 in this case).

Thanks to everyone who has already answered my other couple of questions. This forum has been very helpful.

Brian
 
Old 04 April 2013   #2
Quote:
Originally Posted by brianharms
I'm trying to get the length of an object's animation in frames.

let's say it's 100 frames long. I can use:
mc.keyframe( 'object', query=True, keyframeCount=True )

but if I have 6 attributes keyed (translation and rotation attributes), keyframeCount will return 600 instead of 100. My though it to just take this number and divide by the number of attributes keyed on the object, but I'm not sure how to retrieve this number (which would be 6 in this case).

Thanks to everyone who has already answered my other couple of questions. This forum has been very helpful.

Brian


what about listing the keyable attribute , then you loop that list checking which ones are actually keyed , and then you get the first and last key for each? once you have that you can make a simple subtraction and get the range length
__________________
My website/blog , with a lot of tips&tricks about maya API,python,and pyqt , and tutorials
www.marcogiordanotd.com
llinkedin
 
Old 04 April 2013   #3
Hey Giordi, thanks for the reply.

I'm just not sure how to check which attributes listed are keyed.

Thanks,

Brian
 
Old 04 April 2013   #4
well you first need to list all the keyable attributes with cmds.listAttribute and k = True
I am pretty sure thene there is a command to query whether is keyed or not , probably in the keyframe cmds , or if for any reason there is not you can always list incoming connection and see if is an animation curve or a blend value node
__________________
My website/blog , with a lot of tips&tricks about maya API,python,and pyqt , and tutorials
www.marcogiordanotd.com
llinkedin
 
Old 05 May 2013   #5
Might not be the most optimised way, but worth a try?

Code:
# Get value between two keyframes on given node def getAnimLength(node): # A set is like a list but can't hold duplicates (Pyhton set, not Maya set) keyframeSet=set() # Loop through all keyframe time values from control points on anim curves for keyTimeValue in cmds.keyframe(node, query=True, controlPoints=True): keyframeSet.add(keyTimeValue) # If transform has any keyframes between two time values, get difference result=0 if len(keyframeSet) >= 2: result=max(keyframeSet)-min(keyframeSet) # Return result return result
__________________
~
 
Old 05 May 2013   #6
Try this also:

Code:
import maya.cmds as mc item = 'yourObject.putAttributeHere' listcon = mc.listConnections(item)[0].encode('ascii') controlPoints = mc.keyframe(listcon, q = True, cp = True) startPnt = mc.getAttr('%s.keyTimeValue[0]' % listcon) end = len(controlPoints) - 1 endPoint = mc.getAttr('%s.keyTimeValue[%s]' % (listcon, end)) print 'Keframes of %s is from frame %s to frame %s' % (item, startPoint, endPoint)
__________________
We are the captives of our own identities,
living in the prisons of our own creations.
 
Old 05 May 2013   #7
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.
 
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 08:53 PM.


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