Discussion:
[Maya-Python] How to check if objects have more than 1 keyframe in the time slider
likage
2018-08-07 23:39:33 UTC
Permalink
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.
--
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_maya+***@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.
Justin Israel
2018-08-08 01:20:25 UTC
Permalink
Post by likage
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()
Post by likage
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/1d2f95a1-ed87-4dd9-b20c-0612b127b880%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/1d2f95a1-ed87-4dd9-b20c-0612b127b880%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0wdTYza7VRfT6m6329Qo4z7SsmVcpcz8CtST0kOWQQog%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
likage
2018-08-08 22:55:24 UTC
Permalink
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
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/65a4c866-3bb5-4e02-9bce-1bee55bef381%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
likage
2018-08-08 23:00:31 UTC
Permalink
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.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/3fca60a1-f577-43ea-8f56-997eec42c323%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Justin Israel
2018-08-08 23:06:29 UTC
Permalink
Post by likage
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
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.
Post by likage
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/65a4c866-3bb5-4e02-9bce-1bee55bef381%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/65a4c866-3bb5-4e02-9bce-1bee55bef381%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA16ekOsZjEhz2%3D2yqgLjZrH6HYdo%3D92UZ2HZ-Ga6iEsuQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...