CGTalk > Software > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 04-30-2013, 12:40 AM   #1
brianharms
New Member
portfolio
USA
 
Join Date: Apr 2013
Posts: 10
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-30-2013, 05:58 AM   #2
giordi
Lord of the posts
 
giordi's Avatar
portfolio
Marco Giordano
Creature TD
Double Negative
London, United Kingdom
 
Join Date: Aug 2008
Posts: 618
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-30-2013, 07:08 AM   #3
brianharms
New Member
portfolio
USA
 
Join Date: Apr 2013
Posts: 10
Hey Giordi, thanks for the reply.

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

Thanks,

Brian
 
Old 04-30-2013, 07:32 AM   #4
giordi
Lord of the posts
 
giordi's Avatar
portfolio
Marco Giordano
Creature TD
Double Negative
London, United Kingdom
 
Join Date: Aug 2008
Posts: 618
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-06-2013, 01:03 AM   #5
Koochy
Veteran
Eddie Hoyle
Character TD
Okotobor
Auckland, New Zealand
 
Join Date: Nov 2004
Posts: 66
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
__________________
Eddie H. - Portfolio
 
Old 05-06-2013, 11:19 AM   #6
kosingcg
Tatlong Dimension
 
kosingcg's Avatar
portfolio
Oliver Magno
Render TD
MPC - Montreal
Canada
 
Join Date: Feb 2013
Posts: 88
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-06-2013, 11:19 AM   #7
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,480
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 03:33 PM.


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