pymel.core.animation.keyframe

keyframe(*args, **kwargs)

This command operates on a keyset. A keyset is defined as a group of keys within a specified time range on one or more animation curves. The animation curves comprising a keyset depend on the value of the “-animation” flag: keysOrObjects: Any active keys, when no target objects or -attribute flags appear on the command line, orAll animation curves connected to all keyframable attributes of objects specified as the command line’s targetList, when there are no active keys.keys: Only act on active keys or tangents. If there are no active keys or tangents, don’t do anything.objects: Only act on specified objects. If there are no objects specified, don’t do anything.Note that the “-animation” flag can be used to override the curves uniquely identified by the multi-use “-attribute” flag, which takes an argument of the form attributeName, such as “translateX”. Keys on animation curves are identified by either their time values or their indices. Times and indices can be given individually or as part of a list or range. -time 10palmeans the key at frame 10 (PAL format).-time 1.0sec -time 15ntsc -time 20means the keys at time 1.0 second, frame 15 (in NTSC format), and time 20 (in the currently defined global time unit).-time “10:20”means all keys in the range from 10 to 20, inclusive, in the current time unit.Omitting one end of a range means “go to infinity”, as in the following examples: -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.-index 0means the first key of each animation curve. (Indices are 0-based.)-index 2 -index 5 -index 7means the 3rd, 6th, and 8th keys.-index “1:5”means the 2nd, 3rd, 4th, 5th, and 6th keys of each animation curve.This command edits the time and/or value of keys of specified objects and/or parameter curves Unless otherwise specified by the -query flag, the command defaults to editing keyframes.

Modifications:
  • returns an empty list when the result is None
  • if both valueChange and timeChange are queried, the result will be a list of (time,value) pairs
Flags:
Long name (short name) Argument Types Properties
absolute (a) bool ../../../_images/create.gif
 
Move amounts are absolute.
adjustBreakdown (abd) bool ../../../_images/create.gif
 
When false, moving keys will not preserve breakdown timing, when true (the default) breakdowns will be adjusted to preserve their timing relationship.
animation (an) unicode ../../../_images/create.gif
 

Where this command should get the animation to act on. Valid values are “objects,” “keys,” and “keysOrObjects” Default: “keysOrObjects.” (See Description for details.)

attribute (at) unicode ../../../_images/create.gif
 
List of attributes to select
breakdown (bd) bool ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 

Sets the breakdown state for the key. Returns an integer. Default is false. The breakdown state of a key cannot be set in the same command as it is moved (i.e., via the -tc or -fc flags).

controlPoints (cp) bool ../../../_images/create.gif
 

This flag explicitly specifies whether or not to include the control points of a shape (see “-s” flag) in the list of attributes. Default: false. (Not valid for “pasteKey” cmd.)

eval (ev) bool ../../../_images/create.gif ../../../_images/query.gif
 

Returns the value(s) of the animCurves when evaluated (without regard to input connections) at the times given by the -t/time or -f/float flags. Cannot be used in combination with other query flags, and cannot be used with time ranges (-t “5:10”). When no -t or -f flags appear on the command line, the evals are queried at the current time. Query returns a float[].

float (f) floatrange ../../../_images/create.gif
 

value uniquely representing a non-time-based key (or key range) on a time-based animCurve. Valid floatRange include single values (-f 10) or a string with a lower and upper bound, separated by a colon (-f “10:20”)

floatChange (fc) float ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 
How much (with -relative) or where (with -absolute) to move keys (on non-time-input animation curves) along the x (float) axis. Returns float[] when queried.
hierarchy (hi) unicode ../../../_images/create.gif
 
Hierarchy expansion options. Valid values are “above,” “below,” “both,” and “none.” (Not valid for “pasteKey” cmd.)
includeUpperBound (iub) bool ../../../_images/create.gif
 

When the -t/time or -f/float flags represent a range of keys, this flag determines whether the keys at the upper bound of the range are included in the keyset. Default value: true. This flag is only valid when the argument to the -t/time flag is a time range with a lower and upper bound. (When used with the “pasteKey” command, this flag refers only to the time range of the target curve that is replaced, when using options such as “replace,” “fitReplace,” or “scaleReplace.” This flag has no effect on the curve pasted from the clipboard.)

index (index) timeRange ../../../_images/create.gif
 
index of a key on an animCurve
indexValue (iv) bool ../../../_images/create.gif ../../../_images/query.gif
 
Query-only flag that returns an int for the key’s index.
keyframeCount (kc) bool ../../../_images/create.gif ../../../_images/query.gif
 
Returns an int for the number of keys found for the targets.
lastSelected (lsl) bool ../../../_images/create.gif ../../../_images/query.gif
 

When used in queries, this flag returns requested values for the last selected key.Flag can appear in Create mode of commandFlag can have multiple arguments, passed either as a tuple or a list.

name (n) bool ../../../_images/create.gif ../../../_images/query.gif
 
Returns the names of animCurves of specified nodes, attributes or keys.
option (o) unicode ../../../_images/create.gif ../../../_images/edit.gif
 

Valid values are “move,” “insert,” “over,” and “segmentOver.” When you “move” a key, the key will not cross over (in time) any keys before or after it. When you “insert” a key, all keys before or after (depending upon the -timeChange value) will be moved an equivalent amount. When you “over” a key, the key is allowed to move to any time (as long as a key is not there already). When you “segmentOver” a set of keys (this option only has a noticeable effect when more than one key is being moved) the first key (in time) and last key define a segment (unless you specify a time range). That segment is then allowed to move over other keys, and keys will be moved to make room for the segment.

relative (r) bool ../../../_images/create.gif
 
Move amounts are relative to a key’s current position.
selected (sl) bool ../../../_images/create.gif ../../../_images/query.gif
 
When used in queries, this flag returns requested values for any active keys.
shape (s) bool ../../../_images/create.gif
 
Consider attributes of shapes below transforms as well, except “controlPoints”. Default: true. (Not valid for “pasteKey” cmd.)
tickDrawSpecial (tds) bool ../../../_images/create.gif ../../../_images/edit.gif
 
Sets the special drawing state for this key when it is drawn as a tick in the timeline.
time (t) timerange ../../../_images/create.gif
 

time uniquely representing a key (or key range) on a time-based animCurve. Valid timeRanges include single values (-t 10) or a string with a lower and upper bound, separated by a colon (-t “10:20”)

timeChange (tc) time ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 
How much (with -relative) or where (with -absolute) to move keys (on time-input animation curves) along the x (time) axis. Returns float[] when queried.
valueChange (vc) float ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 
How much (with -relative) or where (with -absolute) to move keys along the y (value) axis. Returns float[] when queried.

Derived from mel command maya.cmds.keyframe

Example:

import pymel.core as pm

# Two ways to find out how many keys there are on the
# paramCurve connected to surface1.translateX;
#
pm.keyframe( 'surface1', attribute='translateX', query=True, keyframeCount=True )
pm.keyframe( 'surface1.translateX', query=True, keyframeCount=True )

# Query all keyframes of object "surface1" within the time range 0 to 20.
#
pm.keyframe( 'surface1', time=(0,20), query=True, valueChange=True, timeChange=True);

# Query just the time of the first key in the
# "Translate X" parameter curve.  Note that the indices are 0-based.
#
pm.keyframe('surface1.translateX',index=(0,0),query=True);

# Shift all the active object's keys in the range 10-20
# by one (current) time unit (frame, second, etc.)
#
pm.keyframe(edit=True,relative=True,timeChange=1,time=(10,20))

# Two ways to move all keys at time 10 of
# the active object to time 12.  Note that "-absolute"
# is the default.
#
pm.keyframe(time=(10,10),timeChange=12)
pm.keyframe(time=(10,10),absolute=True,timeChange=12)

# Set the 2nd keyframe of cube1's Translate X parameter
# curve to be 10.25 at time 1.5 seconds.
#
pm.keyframe('surface1.translateX',edit=True,index=(1,1),timeChange='1.5sec',valueChange=10.25)

# Evaluate the animCurve feeding into nurbsCone1's translateX attribute at time 3
#
pm.keyframe('nurbsCone1',at='tx',t=(3,3),q=True,eval=True)

# Query the times of the active keys on attribute translateX of nurbsCone1
#
pm.keyframe( 'nurbsCone1', at='tx', sl=True, q=True, tc=True )

# How many keys are selected on nurbsCone1?
#
pm.keyframe( 'nurbsCone1', sl=True, q=True, kc=True )

# Here's a script to print out all a cone's animCurves that have
# keys selected.  Each animCurve is followed by a list of times
# for the selected keys.  The result of this script is:
#     nurbsCone1_translateX: 5
#     nurbsCone1_translateY: 12
#     nurbsCone1_translateZ: 4 14
#
myCone = pm.cone()
pm.setKeyframe( myCone[0], t=[0,5,10], at='tx', v=5 )
pm.setKeyframe( myCone[0], t=[2,7,12], at='ty', v=10 )
pm.setKeyframe( myCone[0], t=[4,9,14], at='tz', v=15 )
pm.selectKey( t=[(5,5),(12,12),(4,4)] )
pm.selectKey( animation='objects', add=True, t=(14,14) )

nodes = pm.keyframe(myCone,query=True,name=True)
for node in nodes:
   keyTimes = pm.keyframe(node,sl=True,query=True,tc=True)
   print "Node: %s" % node
   print keyTimes

# For the above sample script, the last selected key is
# nurbsCone1_translateZ: 14.  The following may be used to query
# the values for that key
#
pm.keyframe( query=True, lastSelected=True, name=True )
pm.keyframe( query=True, lastSelected=True, timeChange=True )
pm.keyframe( query=True, lastSelected=True, valueChange=True )

Previous topic

pymel.core.animation.keyTangent

Next topic

pymel.core.animation.keyframeOutliner

Core

Core Modules

Other Modules

This Page