PDA

View Full Version : Python syntax for time range in Keyframe cmd?


EightBit
06-12-2012, 02:31 AM
When specifying 'time' in the Python version of the keyframe command, the values are separated by a comma. In Mel they are separated by a colon.
In the manual, they instruct that a range of frames can also be specified, ie:
-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).

Python doesn't like that last version (up to and including) because it would start with (,


cmds.keyframe(time=(),r=1,timeChange=12) # All
cmds.keyframe(time=(,5),r=1,timeChange=12) # Error: invalid syntax #

Anyone know the fix?
Thanks.

Edit:
cmds.keyframe(time=(5,),r=1,timeChange=12) # This also fails, it only moves the keys at F5.

jewalker
02-05-2013, 10:30 PM
I realize that this is a little old, but I just ran across this problem and wanted to post the answer for others to reference.

The -time flag is allowed to be used multiple times in a single command. In MEL this would be: keyframe -time 1 -time 5 -time 10. Since Python allows an argument to be used only once any flag that can be used multiple times must be passed a tuple, so the previous example would be time=(1, 5, 10). In Python a tuple of a single element is created like this: ( <first entry> , ). So to pass the equivalent of -time "10:" in Python you would do this: ("10:" , ).

e.g. cmds.keyframe(time=("5:",), relative=True, timeChange=12)

EightBit
02-05-2013, 10:48 PM
Hey thanks!

CGTalk Moderation
02-05-2013, 10:48 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.