View Full Version : Time Ranges for KF cmds in Python?

11-10-2011, 04:40 PM
When using 'cutKey' and 'setKeyframe', the manual states that:
-time "10:" means all keys from time 10 (in the current time unit) onwards.
-time ":10" means all keys up to (and including) time 10 (in the current time unit)
-time ":" is a short form to specify all keys.
But they don't show how to do this in Python, so for example
time = (4, ) doesn't do anything.
How do I specify 'onwards' and 'up to (and including)', and 'all' in python?

11-10-2011, 09:50 PM
I just figured this out the other day, this is what you're looking for:

first = mc.findKeyframe(which='first')
next = mc.findKeyframe(which='next')
prev = mc.findKeyframe(which='previous')
last = mc.findKeyframe(which='last')
time = mc.currentTime(query=True)

mc.keyframe(e=True, an='objects', r=True, o='over', tc=1, t=(time,last))
mc.keyframe(e=True, an='objects', r=True, o='over', tc=1, t=(time,next))
mc.keyframe(e=True, an='objects', r=True, o='over', tc=1, t=(first,time)) switch the time, first next, prev, and last variables around to get different effects. And of course you can always hard code the values, but that's not recommended :)

11-11-2011, 12:45 AM
Thanks, but what if you are feeding the KF commands a list of objects?
I think you would have to setup a loop to execute your findKeyframe command on each object - hence the value of being able to specify the time slices.
IE: Add blank frames to all animCrvs on an animLayer:
now = cmds.currentTime(q=1)
end = 1000
numFrames = 50 # Can be negative
animCrvs =cmds.animLayer('Intro_aLyr', query=True, anc = 1)
cmds.keyframe(animCrvs, t = (now, end ), r = 1, tc = numFrames, o = 'over', an = 'keysOrObjects') # Works on objects or anim curves

CGTalk Moderation
11-11-2011, 12:45 AM
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.