PDA

View Full Version : python/MEL query question


misterwolfy
09-12-2010, 03:53 AM
This code will query whether a node has keyframes at a certain time. Then I can do various things to those keys. How do I query whether a particular channel has keys, to refine the query?


hasKey = mc.keyframe( selection, query=True, time=(theTime, theTime))
if hasKey != None:
print 'found keys!'

NaughtyNathan
09-12-2010, 02:59 PM
er.. just query the particular channel..?

mc.keyframe( 'pCube.translateY', query=1)
additionally, animation keys are stored in animCurve nodes, so alternatively, depending on your scenario, if you want to check if a particular channel has keys, you could check if it is connected to an animCurve.

mc.listConnections('pCube1.translateY',type='animCurve')
incidentally, python has an innate understanding of everything being either true or false, so it is not very pythonic to compare things when boolean testing.

if hasKey != None:is much better asif hasKey:and far easier to understand the intention!
:nathaN

misterwolfy
09-16-2010, 04:24 PM
Thanks Nathan, great info!

CGTalk Moderation
09-16-2010, 04:24 PM
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.