How to check if objects have more than 1 keyframe in the time slider

1,168 views
Skip to first unread message

likage

unread,
Aug 7, 2018, 7:39:33 PM8/7/18
to Python Programming for Autodesk Maya
What is the best way to check and see if an object (or multiple objects) have more than 1 animated keyframes as denoted by the red ticks in the time slider...

I tried using "cmds.keyframe(sl=False, q=True, tc=True)", however that returns me the amount of attributes that are keyframed etc.

My objective here will be, if an object is found to have 1 or no animated keyframes/ the red ticks, skip it. 

Justin Israel

unread,
Aug 7, 2018, 9:20:41 PM8/7/18
to python_in...@googlegroups.com
On Wed, Aug 8, 2018 at 11:39 AM likage <dissid...@gmail.com> wrote:
What is the best way to check and see if an object (or multiple objects) have more than 1 animated keyframes as denoted by the red ticks in the time slider...

I tried using "cmds.keyframe(sl=False, q=True, tc=True)", however that returns me the amount of attributes that are keyframed etc.

What about:

if cmds.keyframe(obj, q=True, keyframeCount=True) > 1:
    skip()
 

My objective here will be, if an object is found to have 1 or no animated keyframes/ the red ticks, skip it. 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1d2f95a1-ed87-4dd9-b20c-0612b127b880%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

likage

unread,
Aug 8, 2018, 6:55:41 PM8/8/18
to Python Programming for Autodesk Maya
Hi Justin,

It does not seems to work. The value returned is the number of attributes that are keyed.

sel = cmds.ls(sl=True)[0]
kf
= cmds.keyframe(sel, query=True, keyframeCount=True)
print kf


Eg. 
1. Create a sphere (no animation keyframe) > run the above code > returns '0' as the result
2. Create a sphere (do a single keyframe, or hit 'S' key) > run the above code > returns '10' as the result

likage

unread,
Aug 8, 2018, 7:00:31 PM8/8/18
to Python Programming for Autodesk Maya
I can use `len(set(list(kf)))` as a means to check. If the values is greater than 1, it will means that there are 2 frames (2 ticks).
Trying to see if there is another similar/ better command within Maya itself.

Justin Israel

unread,
Aug 8, 2018, 7:06:45 PM8/8/18
to python_in...@googlegroups.com
I am not seeing this behaviour that you are reporting. What I am seeing is that the returned value is the total number of keyframes for the objects you pass in as arguments. If you are passing multiple objects, then it is the total for all of them, so you will want to run that for each object individually. When I create a new object, it is zero. When I create a key on tx, it is one. If I created another key on tx at a different time it returns 2. If I hit 's' like you suggested then I am creating keys on all the transform channels which means the first one will be 10. So it is not an attribute count.

I assumed since your stated goal is to check if an object has more than 1 red tick mark. And so checking each object individually, the way I had provided, seems like it does what you want? Technically you could have 100 red tick marks but no value change between them, which means the object is static even though it has keyframes.
 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages