Animation¶
Animconstants¶
- getSceneFPS()¶
Returns maya’s current frame rate as a float
- Return framesPerSecond:
The current frame rate as a float
- Rtype framesPerSecond:
float
Animlayers¶
- getAttrPlugForLayer(nodeName, attr, animLayer)¶
Find the animBlendNode plug corresponding to the given node, attribute, and animation layer.
Credit from rflannery https://forums.autodesk.com/t5/maya-programming/how-to-get-attribute-value-from-animation-layer/td-p/6537895
- getAnimCurveForLayer(nodeName, attr, animLayer)¶
Returns an animation curve name given the node, attribute and the animation layer
- animCurvesInLayers(objs, animLayers)¶
Select all animation curves in all layers for all objects, can also pass in a single object too
- animCurvesInSelLayers(objs)¶
Returns animation curves for objs found only in the selected layers
- Parameters:
objs (list(str)) – A list of maya node names, can also be a single str
- Return animCurves:
A list of animation curve node names
- Rtype animCurves:
list(str)
- animCurvesAllLayers(objs)¶
Returns animation curves for objs in all animation layers
- Parameters:
objs (list(str)) – A list of maya node names, can also be a single str
- Return animCurves:
A list of animation curve node names
- Rtype animCurves:
list(str)
- deselectAnimLayer(animLayer)¶
Deselects an animation layer in the layer editor
- Parameters:
animLayer (str) – A maya animation layer name
- selectAnimLayer(animLayer)¶
Selects an animation set, only adds does not deselect
- Parameters:
animLayer (str) – A maya animation layer name
- replaceSelectAnimLayer(animLayer)¶
Selects an animation set while deselecting all other layers
- Parameters:
animLayer (str) – A maya animation layer name
- replaceSelectAnimLayers(animLayers)¶
Replace selects multiple animation layers, unselecting all others.
- Parameters:
animLayers (list(str)) – A list of Maya animation layer names
- isObjectInAnimLayer(obj, animLayer)¶
Returns whether an object is in an animation layer or not.
- allObjectsInAnimLayer(objs, animLayer)¶
Checks if all objects are all members of an animation layer, returns False if any objects are not members.
- noObjectsInAnimLayer(objs, animLayer)¶
Checks if none of the objects are members of an animation layer, returns False if any objects are members.
- selectedAnimationLayers()¶
Returns all the selected animation layers
- Return animLayer:
The name of an animation layer
- Rtype animLayer:
str
- firstSelectedAnimLayer(ignoreBaseLayer=True)¶
Returns the first selected animation layer or empty string if None are selected
- Parameters:
ignoreBaseLayer (bool) – Ignore the baseLayer if it’s the first selected and don’t return it.
- Return animLayer:
The name of an animation layer
- Rtype animLayer:
str
- getAllAnimationLayers()¶
Returns all animation layers in the scene
- Return allAnimLayers:
A list of all animation layer names in the scene
- Rtype allAnimLayers:
list(str)
Animobjects¶
Example use:
from zoo.libs.maya.cmds.animation import animobjects
animobjects.animSelection()
- filterAnimatedNodes(nodeList)¶
Filters a list returning a new list of nodes that have keyframes
- Parameters:
nodeList – Incoming list of nodes
- Return animNodeList:
The filtered list
- getAnimatedNodes(selectFlag='all', select=True, message=True)¶
Selects nodes animated with keyframes. Flag allows for three select options:
“all” : All in scene
“selected” : only selected
“hierarchy” : search selected hierarchy
- animSelection()¶
Returns the animation selection with the following information.
(animCurves, objAttrs, selObjs)
animCurves: The names of the curve nodes [“pCube1_translateX”] objAttrs: The names of the matching object.attributes of the channelbox selection [“pCube1.translateX”] selObjs: The names of the selected objects/nodes as per usual [“pCube1”]
Note: If animation curves are selected ignores the channelbox selection.
- Return animationSelection:
returns the tuple with (animCurves, channelBoxAttrs, selObjs)
- Rtype animationSelection:
tuple(list(str), list(str), list(str))
Bakeanim¶
from zoo.libs.maya.cmds.animation import bakeanim bakeanim.bakeLimitKeysToTimerangeSel(0.0, 10.0, message=True)
- bakeDifferentLayers(objList, attrList, animLayer, timeRange, bakeFrequency, shapes=False)¶
Bake objects when some objects are not in the first selected animation layer.
- keyProxiesNoKeys(objList, time)¶
Keys proxies if there are no keys on the proxy attributes. Fix for versions earlier than 2024.
- bakeAnimationLayers(objList, attrList, timeRange, bakeFrequency, animLayer, shapes=True, message=True)¶
Automatically bakes animation to the given anim layer, or on the base layer if objects aren’t members
Will intelligently bake by batching objects into one bake as much as possibly to keep efficiency.
- bakeAnimCurves(bakeFrequency=1)¶
Bakes animation curves with frequency
- Parameters:
bakeFrequency (float) – Bakes every nth frame
- bakeSelectedChannelBox(timeRange=[0, 0], timeSlider=1, bakeFrequency=1, shapes=False, message=True)¶
Intelligently bakes keyframes with a frequency option, channel selection and supports selected animation layers
Bakes selected objects
Uses channel box selection to restrict attributes, otherwise will bake all
Handles user selected animation layers
Batches objects where possible for speed
- Parameters:
timeRange (list(float)) – The start and end frame, only used if the timeSlider is set to 3 (use custom timerange)
timeSlider (int) – 0 is playback range, 1 is animation range, 2 is use timeRange kwargs
bakeFrequency (float) – Will bake every nth frame if bake is True
message (bool) – Return messages to the user?
- bakeSelected(timeRange=[0, 0], timeSlider=1, bakeFrequency=1, shapes=False, message=True)¶
Bakes animation keyframes using bake curves or bake simulation depending on the selection and settings.
Bake Animation based on selection:
Graph keyframe selection. (Time Range is ignored)
Channel Box selection.
If nothing is selected will bake all attributes.
- Parameters:
timeRange (list(float)) – The start and end frame, only used if the timeSlider is set to 3 (use custom timerange)
timeSlider (int) – 0 is playback range, 1 is animation range, 2 is use timeRange kwargs
bakeFrequency (float) – Will bake every nth frame if bake is True
message (bool) – Return messages to the user?
- bakeLimitKeysToTimerange(start, end, objAttrList)¶
Limits keys to timerange (deletes keys outside) cmds.bakeResults gives incorrect results on the in/out tangents.
objAttrList: can be [“object.attribute”] or the animation curves themselves [“object_attribute”]
- bakeLimitKeysToTimerangeSel(start, end, message=True)¶
- Parameters:
start –
end –
message –
- Returns:
- Return type:
Disableviewport¶
- suspendViewportUpdate(suspend)¶
Suspends all of Maya’s viewports, run code inbetween suspending and unsuspending. Handy for animation tools.
disableviewport.suspendViewportUpdate(True) someCodeHere() disableviewport.suspendViewportUpdate(False)
- resetViewport()¶
Fully refreshes maya’s viewport, gives it a kick!
- disableViewportBlankDec(func)¶
Decorator - Blanks out the main Maya display while func is running. if func fails, the error will be raised after.
Credit: https://blog.asimation.com/disable-maya-viewport-while-running-code/
uses:
mel.eval(“paneLayout -e -manage false $gMainPane”)
- disableViewportRefreshDec(func)¶
Decorator - suspends the Maya display while func is running. if func fails, the error will be raised after.
uses:
cmds.refresh(suspend=True)
Generalanimation¶
- changeRotOrder(nodes=None, newRotOrder=0, bakeEveryFrame=False, timeline=True)¶
Sets the rotation order of the specified nodes or the selected nodes.
- Parameters:
nodes (list[
zapi.DagNode
] or None) – If None then the current selection will be used.newRotOrder (int) – The rotation order number between 0-5.
bakeEveryFrame (bool) – Whether all frames either on the timeline or between the start and end frame keys for the nodes should be baked.
timeline (bool) – Whether the current active timeline should be used as a key filter.
- allGimbalTolerancesForKeys(node=None, currentFrameRange=False, message=False)¶
Returns the tolerances for each rotation order for the given nodes keyframes.
- gimbalTolerancesToLabels(tolerances)¶
Given a list of tolerance values return the appropriate labels. Useful for UIs.
- selectAnimNodes(mode=0)¶
0 Select all animated nodes under the selected hierarchy. 1 Select all animated nodes in the scene. 2 Select all animated nodes in the selection.
- Parameters:
mode (int) – Hierarchy 0, scene 1, from selected, 2
- setKeyChannel()¶
Set Key on all attributes, but if any Channel Box attributes are selected then key only those channels.
- setKeyAll()¶
Sets a key on all attributes ignoring any Channel Box selection.
- animHold()¶
Make an animation hold. Place the timeline between two keys and run. The first key will be copied to the second with flat tangents. Zoo Hotkey: alt a
- deleteCurrentFrame()¶
Deletes keys at the current time, or the selected timeline range.
- keyToggleVis()¶
Keys and inverts the visibility of the selected objects. Visibility of True will become False
- resetAttrsBtn()¶
Resets the selected object/s attributes to default values.
- toggleControlCurveVis()¶
Toggles Curve visibility in the current viewport
- bakeKeys()¶
Bakes animation keyframes using bake curves or bake simulation depending on the selection
Hardcoded hotkey settings. Bakes every frame of the selected range or if none selected the playback range.
Bake Animation based on selection:
Graph keyframe selection. (Time Range is ignored)
Channel Box selection.
If nothing is selected will bake all attributes.
- eulerFilter()¶
Perform Maya’s Euler Filter on selected objects rotation values
- createMotionTrail()¶
Creates a motion trail on the selected object/s
Displays settings from the ZooMotionTrailTrackerSingleton() data as shared across UIs and marking menus.
- openGhostEditor()¶
Opens Maya’s Ghost Editor Window
- snapKeysWholeFrames()¶
Snaps the selected keys to whole frames.
- snapKeysCurrent()¶
Snaps the selected graph keys to the current time.
- cycleAnimation(cycleMode=0, pre=True, post=True, displayInfinity=True)¶
Cycles the selected objects, options for the scale mode and pre and post.
Cycle modes are ints:
Cycle: 0 Cycle With Offset: 1 Oscillate: 2 Linear: 3 Constant: 4
- removeCycleAnimation()¶
Removes any cycling animation on the selected objects for both pre and post.
- showInfinity(show)¶
Show Infinity in the graph editor.
- Parameters:
show (bool) – True will show, False will hide.
- toggleInfinity()¶
Toggles infinity on and off in the Graph Editor
- selObjGraph()¶
Select an object from a graph curve selection.
- timeToKey()¶
Moves the time slider to the closest selected keyframe.
- insertKey()¶
Maya’s Insert Key Tool. Select a fCurve and middle click drag to insert a key.
- copyKeys()¶
Copy Keyframes in the Graph Editor.
- pasteKeys()¶
Paste Keyframes in the Graph Editor.
- playPause()¶
Play/Pause animation toggle.
- reverse()¶
Reverse/Pause animation toggle.
- stepNextFrame()¶
Step to the next frame in the timeline.
- stepLastFrame()¶
Step to the last frame in the timeline.
- stepNextKey()¶
Step to the next Key Frame in the timeline.
- stepLastKey()¶
Step to the last Key Frame in the timeline.
- step5framesForwards()¶
Step forward five frames in time.
- step5framesBackwards()¶
Step backwards five frames in time.
- playRangeStart()¶
Sets the playback start to the current time.
- playRangeEnd()¶
Sets the playback end to the current time.
- timeRangeStart()¶
Sets the time-range start to the current time.
- timeRangeEnd()¶
Sets the time-range end to the current time.
Grapheditorfcurve¶
from zoo.libs.maya.cmds.animation import grapheditorfcurve grapheditorfcurve.autoTangentCycleSel(0.0, 24.0, includeProxyAttrs=True, tangentType=”auto”)
- convertKeyIndexList(keyIndexList)¶
Converts a list(long, long) of keys to a format that cmds python can use list(set(int), set(int))
Example:
Converts [2L, 3L] to [(2,2), (3,3)]
- Parameters:
keyIndexList (list) – A list of keyframe indices, usually [2L, 3L] as per querying Maya
- Return newKeyIndex:
A new list now in a format that the python command recognises [(2,2), (3,3)]
- Rtype objList:
list(set)
- objFromFCurve()¶
Returns a list of objects connected to a graph curve
- Return objList:
list of maya object/node names
- Rtype objList:
list(str)
- selectObjFromFCurve(message=True)¶
Selects objects related to any selected curves in Maya’s graph editor.
- Parameters:
message (bool) – report the message back to the user?
- Return objList:
list of maya object/node names
- Rtype objList:
list(str)
- jumpToSelectedKey(closestKey=10000000.0, closestGap=10000000.0, message=True)¶
Changes the current time in the graph editor (Maya timeline) to match to the closest selected keyframe
- Parameters:
- Return closestKey:
the closest keyframe found, will be None if null
- Rtype closestKey:
float
- moveKeysSelectedTime(message=True)¶
Moves the selected keys to the current time. The first keyframe matching, maintains the spacing of selection
- Parameters:
message (bool) – report the message back to the user?
- animHold(message=True)¶
Creates a held pose with two identical keys and flat tangents intelligently from the current keyframes
Functionality:
For each curve, finds the previous key and copies it to the next keyframe while flattening both tangents.
Will work on selected curves only as a priority if curves have been selected
If no curve/s are selected then use all default curves, does not need the Graph Editor open
Will check if the current attribute values differ from the current curve values (ie object has moved)
If finds a mismatch between current curve value and current actual value, then uses the current actual value
Authors: Original .mel script by David Peers converted to python by Andrew Silke (also co-creator)
- Parameters:
message (bool) – report the message back to the user?
- autoTangentCycleAttr(animCurve, firstFrame, lastFrame, tangentType='auto')¶
Match the start and end frame tangents on a single curve for loop cycles.
Uses “auto” tangents by default as if keys were present before and after the cycle.
- Can be other:
“spline”, “autoease”, “automix”, “autocustom”
- Parameters:
animCurve (str) – An animation curve node “pCube1_rotateX” or obj.attribute “pCube1.rotateX”
firstFrame (float) – The first frame of the cycle eg. 0.0
lastFrame (float) – The first frame of the cycle eg. 24.0
tangentType (str) – The default tangent type setting can be other “spline”, “autoease”, “automix”, “autocustom” etc.
- Return success:
Returns True is single curve’s tangents was modified correctly.
- Rtype success:
bool
- autoTangentCycleObj(node, firstFrame, lastFrame, includeProxyAttrs=True, tangentType='auto')¶
Match the start and end frame tangents on a single object for loop cycles.
Uses “auto” tangents by default as if keys were present before and after the cycle.
- Can be other:
“spline”, “autoease”, “automix”, “autocustom”
- Parameters:
node (str) – A maya object transform name
firstFrame (float) – The first frame of the cycle eg. 0.0
lastFrame (float) – The first frame of the cycle eg. 24.0
includeProxyAttrs (bool) – Include animated proxy attributes?
tangentType (str) – The default tangent type setting can be other “spline”, “autoease”, “automix”, “autocustom” etc.
- Return success:
Returns True is single curve’s tangents was modified correctly.
- Rtype success:
bool
- autoTangentCycleCurveList(firstFrame, lastFrame, animCurveList, tangentType='auto')¶
See documentation for autoTangentCycleAttr() this function iterates over a list.
- Parameters:
firstFrame (float) – The first frame of the cycle eg. 0.0
lastFrame (float) – The first frame of the cycle eg. 24.0
animCurveList (list(str)) – An list of animation curve nodes [“pCube1_rotateX”] or obj.attributes [“pCube1.rotateX]
tangentType (str) – The default tangent type setting can be other “spline”, “autoease”, “automix”, “autocustom” etc.
- Return success:
success if one or more tangents were adjusted.
- Rtype success:
bool
- autoTangentCycleSel(firstFrame, lastFrame, tangentType='auto', message=True)¶
Match the start and end frame tangents on the selection for loop cycles.
Selection priority is curves then channelbox attrs then object selection (all curves)
Uses “auto” tangents by default as if keys were present before and after the cycle.
- Can be other:
“spline”, “autoease”, “automix”, “autocustom”
- Parameters:
- Return success:
Returns True is single curve’s tangents was modified correctly.
- Rtype success:
bool
- graphExpandConnections(expandConnections=False, message=True)¶
Expands or removes connections in the graph editor.
Deselects, so the user forces the refresh as refresh is difficult.
- Parameters:
expandConnections –
closeGraphs –
- Returns:
- Return type:
Keyframes¶
Keyframe related scripts.
Author: Andrew Silke
from zoo.libs.maya.cmds.animation import keyframes keyframes.transferAnimationSelected()
- createTurntable(rotateGrp, start=0, end=200, spinValue=360, startValue=0, attr='rotateY', tangent='spline', prePost='linear', setTimerange=True, reverse=False, angleOffset=0)¶
Creates a spinning object 360 degrees, useful for turntables
- Parameters:
rotateGrp (str) – the group name to animate
start (float) – the start frame
end (float) – the end frame
spinValue (float) – the value to spin, usually 360
startValue (float) – the start value usually 0
attr (str) – the attribute to animate, usually “rotateY”
tangent (str) – the tangent type “spline”, “linear”, “fast”, “slow”, “flat”, “stepped”, “step next” etc
prePost (str) – the infinity option, linear forever? “constant”, “linear”, “cycle”, “cycleRelative” etc
setTimerange (bool) – do you want to set Maya’s timerange to the in (+1) and out at the same time?
angleOffset (float) – the angle offset of the keyframes in degrees, will change the start rotation of the asset
reverse (bool) – reverses the spin direction
- Return rotateGrp:
the grp/object now with keyframes
- Rtype rotateGrp:
str
- turntableSelectedObj(start=0, end=200, spinValue=360, startValue=0, attr='rotateY', tangent='spline', prePost='linear', setTimerange=True, angleOffset=0, reverse=False, message=True)¶
Creates a turntable by spinning the selected object/s by 360 degrees
- Parameters:
rotateGrp (str) – the group name to animate
start (float) – the start frame
end (float) – the end frame
spinValue (float) – the value to spin, usually 360
startValue (float) – the start value usually 0
attr (str) – the attribute to animate, usually “rotateY”
tangent (str) – the tangent type “spline”, “linear”, “fast”, “slow”, “flat”, “stepped”, “step next” etc
prePost (str) – the infinity option, linear forever? “constant”, “linear”, “cycle”, “cycleRelative” etc
setTimerange (bool) – do you want to set Maya’s timerange to the in (+1) and out at the same time?
angleOffset (float) – the angle offset of the keyframes in degrees, will change the start rotation of the asset
reverse (bool) – reverses the spin direction
message (bool) – report the message to the user in Maya
- Return rotateObjs:
the grp/objects now with keyframes
- Rtype rotateGrp:
list
- deleteTurntableSelected(attr='rotateY', returnToZeroRot=True, message=True)¶
Deletes a turntable animation of the selected obj/s. Ie. Simply deletes the animation on the rot y attribute
- toggleAndKeyVisibility(message=True)¶
Inverts the visibility of an object in Maya and keys it’s visibility attribute Works on selected objects. Example:
“cube1.visibility True” becomes “cube1.visibility False” and the visibility attribute is also keyed
- transferAnimationLists(oldObjList, newObjList, message=True)¶
Transfers animation from one object list to another.
- transferAnimationSelected(message=True)¶
Transfers the animation of the first half of selected objects to the second half.
Objects must be selected in order.
- Parameters:
message (bool) – Report a message to the user?
- copyPasteKeys(source, target, attr, targetAttr=None, start=0, end=1000, mode='replace', maintainStartEnd=True, includeStaticValues=True)¶
Copy Paste keyframes with error checking if fails.
- paste modes are:
“insert”, “replace”, “replaceCompletely”, “merge”, “scaleInsert,” “scaleReplace”, “scaleMerge”, “fitInsert”, “fitReplace”, and “fitMerge”
- Parameters:
source (str) – The source obj/node to have copied keys
target (str) – The target obj/node to have pasted keys
attr (str) – the attribute to copy and paste
targetAttr (str) – Optional target attribute if different from the attr
start (float) – The start frame, ignored if maintainStartEnd
end (float) – The end frame, ignored if maintainStartEnd
mode (str) – The copy paste mode. “insert”, “replace”, “merge” etc see description.
maintainStartEnd (bool) – Copies only the time-range from the copied attr, otherwise use start end
includeStaticValues (bool) – Will copy values that do not have keyframes
- Return keyPasted:
True if keys were successfully pasted, False if not.
- Rtype keyPasted:
bool
Motiontrail¶
Code for animation motion trails
Example:
from zoo.libs.maya.cmds.animation import motiontrail
motiontrail.createMotionTrailsSel(nameAsObject=True, trailDrawMode=1, showFrames=False, showFrameMarkers=True,
frameMarkerSize=2, frameMarkerColor=(0.0, 1.0, 1.0), keyframeSize=0.1,
selectOriginal=True, replaceOld=True)
- moTrailShapes(scene=True, selected=True)¶
If both flags are true then, return the selected motion trail shape nodes. If no nodes are found in the selection, then return all nodes in the scene.
- toggleDisplaySetting(attr, valueOne=1, valueTwo=0, transform=False, scene=True, selected=True, message=True)¶
Toggles the display of motion trails from selection or if nothing selected then the whole scene.
attrs can be:
“visibility”: bool (transform=True) “trailDrawMode”: int (1-2) “showFrames”: bool (numbers) “showFrameMarkers”: bool (crosses) “frameMarkerSize”: float (0.01 - 2.0) (crosses size) “keyframeSize”: float (0.01 - 2.0) (white dots)
- Parameters:
attr (str) – A supported attribute name on the motion trail
valueOne (float, int, bool) – The first (largest) value to set in the toggle
valueTwo (float, int, bool) – The second (smallest) value to set in the toggle
scene (bool) – Affect all motion paths in the scene if none selected?
selected (bool) – Affect selected motion paths as a priority?
message (bool) – Report messages to the user?
- deleteMotionTrails(scene=True, selected=False, message=True)¶
Deletes selected or all motion trails in the scene.
- selectMotionTrails(message=True)¶
Selects all motion trails in the scene.
- objectFromMoTrailShp(motionTrailShp)¶
Returns the object that the motionTrailShape is connected to.
- Parameters:
motionTrailShp (str) – A motionTrailShp node
- Return object:
An object that the trail is connected to
- Rtype object:
str
- moTrailFromMoTrailShp(motionTrailShp)¶
Returns the motionTrail node (not shape) from the motion trail shape node.
- rebuildMotionTrail(motionTrailShapes, nameAsObject=True, selectOriginal=True, replaceOld=True, suffixNameFrames=False, message=True)¶
Rebuilds motion trails from motion trail shape node list.
- Parameters:
motionTrailShapes (list(str)) – A list of motion trail handle shape nodes
nameAsObject (bool) – Auto names the new trails based off the selection names eg “pCube1_mTrailHdl”
selectOriginal (bool) – Select the original objects after building? If False selects motion transforms instead.
replaceOld (Bool) – Will delete any old motionTrails related to the current selection, so will rebuild and won’t add.
suffixNameFrames (Bool) – adds a suffix with keyframes in out. eg _1_to_120
message (bool) – Report a message to the user?
- Returns:
matching lists… moTrailTransforms, moTrailHandleShapes, moTrailList, moTrailObjList
- Return type:
- createMotionTrails(objs, nameAsObject=True, trailDrawMode=2, showFrames=False, showFrameMarkers=True, frameMarkerSize=1.0, frameMarkerColor=(0.0, 1.0, 1.0), keyframeSize=1.0, selectOriginal=True, replaceOld=True, suffixNameFrames=False, limitFrames=0.0)¶
Creates a motion trails from and object list and changes the display modes to suit.
Default will create a moton trail with a new name matching the object.
pCube1_mTrailHdl
- Parameters:
objs (list(str)) – A list of Maya objects
nameAsObject (bool) – Auto names the new trails based off the selection names eg “pCube1_mTrailHdl”
trailDrawMode (int) – 0, constant, 1 alternating frames, 2 past future
showFrames (bool) – Show frame numbers?
showFrameMarkers (bool) – Show Frame Markers (crosses like handles)
frameMarkerSize (float) – Size of the Markers (crosses)
frameMarkerColor (list(float)) – Color of the Markers (crosses)
keyframeSize (float) – Size of the white dots, less than 0.5 will be invisible.
selectOriginal (bool) – Select the original objects after building? If False selects motion transforms instead.
replaceOld (Bool) – Will delete any old motionTrails related to the current selection, so will rebuild and won’t add.
suffixNameFrames (Bool) – adds a suffix with keyframes in out. eg _1_to_120
limitFrames (int) – The amount of frames to limit either side, if 0.0 then there is no limit.
- Returns:
matching lists… moTrailTransforms, moTrailHandleShapes, moTrailList, moTrailObjList
- Return type:
- createMotionTrailsSel(nameAsObject=True, trailDrawMode=2, showFrames=False, showFrameMarkers=True, frameMarkerSize=0.1, frameMarkerColor=(0.0, 1.0, 1.0), keyframeSize=1.0, selectOriginal=True, replaceOld=True, suffixNameFrames=False, noSelRebuild=True, limitFrames=0.0, message=True)¶
Creates a motion trail on the selected object and changes the display modes to suit.
default will create a motion trail with a new name matching the object.
pCube1_mTrailHdl
- Parameters:
nameAsObject (bool) – Auto names the new trails based off the selection names eg “pCube1_mTrailHdl_1_to_250”
trailDrawMode (int) – 0, constant, 1 alternating frames, 2 past future
showFrames (bool) – Show frame numbers?
showFrameMarkers (bool) – Show Frame Markers (crosses like handles)
frameMarkerSize (float) – Size of the Markers (crosses)
frameMarkerColor (list(float)) – Color of the Markers (crosses)
keyframeSize (float) – Size of the white dots, less than 0.5 will be invisible.
selectOriginal (bool) – Select the original objects after building? If False selects motion transforms instead.
replaceOld (Bool) – Will delete any old motionTrails related to the current selection, so will rebuild and won’t add.
suffixNameFrames (Bool) – adds a suffix with keyframes in out. eg _1_to_120
noSelRebuild (Bool) – If True and nothing is selected then try to rebuild all motion trails in the scene
limitFrames (int) – The amount of frames to limit either side, if 0.0 then there is no limit.
- Returns:
matching lists… moTrailTransforms, moTrailHandleShapes, moTrailList, moTrailObjList
- Return type:
- createMotionTrailSelBools(keyDots_bool, crosses_bool, frameSize_bool, pastFuture_bool, frameNumbers_bool, limitBeforeAfter_bool, limitFrames=8.0)¶
Main function for creating and rebuilding motion trails from UI or marking menu.
Takes boolean (checkbox) values as its keyword arguments.
- Parameters:
keyDots_bool (bool) – Keyframe dots visibility
crosses_bool (bool) – Every frame cross visibility
frameSize_bool (bool) – Small or Large size of the key and keyframe markers?
pastFuture_bool (bool) – Set alternating display style or past/future
frameNumbers_bool (bool) – Visibility of the frame numbers display
limitBeforeAfter_bool (bool) – limit the frame length before and after.
limitFrames (float) – The amount of frames that will be limited.
- Returns:
matching lists… moTrailTransforms, moTrailHandleShapes, moTrailList, moTrailObjList
- Return type:
- resetMoTrialDefaultDisplay(scene=True, selected=True, message=True)¶
Resets the display settings of the selected or scene moTrail shape nodes in the scene
- createKeyframeTrackAttrs(mTShape)¶
On a single motion trail create the zoo tracker attributes for keyframe dot scale and visibility
- keyframeTrackAttrs(mTShape)¶
On a single motion trail return the zoo tracker attributes for keyframe dot scale and visibility.
- keyDotsVisibility(moTShapes)¶
Returns the first found motion trail shape’s keyframe dots visibility
- keyDotsSize(moTShapes)¶
Returns the first found motion trail shape’s keyframe dots size, ignores visibility
- setKeyDotsVis(moTShapes, visible)¶
Sets the visibility of the key frame dots, annoying function that also takes into consideration the zoo scale toggle small/large.
The keyframeSize attribute doubles as visiblity (0.1) and scale larger sizes. So its difficult for UI toggles. Zoo creates trackable attributes for monitoring keyframe dot scale and size independently.
- setKeyDotsSize(moTShapes, sizeBool)¶
Sets the scale of the keyframe dots, annoying function that also takes into consideration the zoo visibility toggle on/off.
The keyframeSize attribute doubles as visiblity (0.1) and scale larger sizes. So its difficult for UI toggles. Zoo creates trackable attributes for monitoring keyframe dot scale and size independently.
- setVisibilityBool(moTShapes, visibility)¶
Sets the motion trail shapes
- setFrameCrossesBool(moTShapes, visibility)¶
Sets the motion trail shapes frame cross visibility.
- setFrameSizeBool(moTShapes, sizeBool)¶
Sets the motion trail shapes frame cross and keyframe dot size.
- setPastFutureBool(moTShapes, altPastBool)¶
Sets the motion trail shapes display type to be either alternating (False) or past future (True).
- setFrameNumbersBool(moTShapes, frameNumberVis)¶
Sets the motion trail shapes
- Parameters:
moTShapes (list(str)) – A list of motion trail shape nodes.
frameNumberVis –
- setLimitBeforeAfterBool(moTShapes, limitBool, framesIn=8.0, framesOut=8.0)¶
Sets the motion trail shapes frame limit to be on or off.
- visibilityToggleValue(moTShapes)¶
Returns from the first found node, is the motion trail transform visible or not?
- frameCrossesToggleValue(moTShapes)¶
Returns from the first found node, whether the frame crosses are visible or not.
- frameSizeToggleValue(moTShapes)¶
Returns from the first found node, the size of the keyframe and key display size, big or small.
- pastFutureToggleValue(moTShapes)¶
Returns from the first found node,
- frameNumbersToggleValue(moTShapes)¶
Returns from the first found node, whether the frame numbers are visible or not.
- limitBeforeAfterToggleValue(moTShapes)¶
Returns from the first found node, whether the trail is limited in time.
- keyFrameDotValue(moTShapes)¶
Returns from the first found node, whether the keyframe dots are visible or not.
- class ZooMotionTrailTrackerSingleton(*args, **kwargs)¶
Bases:
object
Used by the motion trail marking menu & UI, tracks data for motion trails between UIs and marking menus.
Tracks the current motion trail shapes in the scene or selected. Tracks visibility settings of the motion trails.
- resetDisplayDefaults()¶
Resets all the display defaults.
- cloneObjFromAnimation(obj, startTime, endTime, objToFrame=1.0)¶
Creates objects from animation with snapshot, clones new objects.
- Parameters:
obj (str) – A single object name, should be keys on translation
startTime (float) – The time start point to start creeating the curve
endTime (float) – The time end point to end creating the curve
objToFrame (float) – The amount of objects to frames, 1.0 is one obj per frame, 2.0 is one obj every 2 frames
- cloneObjsFromAnimation(objs, startTime, endTime, objToFrame=1)¶
Creates objects from animation with snapshot, clones new objects.
- Parameters:
objs (list(str)) – A list of objects (transforms) to create the CV curve.
startTime (float) – The time start point to start creeating the curve
endTime (float) – The time end point to end creating the curve
objToFrame (float) – The amount of objects to frames, 1.0 is one obj per frame, 2.0 is one obj every 2 frames
- cloneObjsFromAnimationSelected(objToFrame=1)¶
Creates objects from animation with snapshot, clones new objects.
- Parameters:
objToFrame (float) – The amount of objects to frames, 1.0 is one obj per frame, 2.0 is one obj every 2 frames
- cvCurveFromObjAnimation(obj, startTime, endTime, cvEveryFrame=1.0)¶
Creates a CV curve based on an animated object with keys per frame.
- Credit DELANO ATHIAS, cleaned up/faster code from:
https://www.delanimation.com/tutorials-1/2020/1/2/generating-curves-from-motion-trails-in-maya
- Parameters:
obj (str) – A single object name, should be keys on translation
startTime (float) – The time start point to start creeating the curve
endTime (float) – The time end point to end creating the curve
cvEveryFrame (float) – The amount of cvs per frame, 1.0 is one cv per frame, 2.0 is one CV every 2 frames
- cvCurveFromObjsAnimation(objs, startTime, endTime, cvEveryFrame=1)¶
Creates a CV curve based on an animated object with keys per frame.
Credit DELANO ATHIAS, cleaned up code from https://www.delanimation.com/tutorials-1/2020/1/2/generating-curves-from-motion-trails-in-maya
- Parameters:
objs (list(str)) – A list of objects (transforms) to create the CV curve.
startTime (float) – The time start point to start creeating the curve
endTime (float) – The time end point to end creating the curve
cvEveryFrame (float) – The amount of cvs per frame, 1.0 is one cv per frame, 2.0 is one CV every 2 frames
- cvCurveFromObjAnimationSelected(cvEveryFrame=1)¶
Creates a CV curve based on an animated selected objects uses the time range and sets a CV per frame.
Credit DELANO ATHIAS, cleaned up code from https://www.delanimation.com/tutorials-1/2020/1/2/generating-curves-from-motion-trails-in-maya
- Parameters:
cvEveryFrame (float) – The amount of cvs per frame, 1.0 is one cv per frame, 2.0 is one CV every 2 frames
Randomizeanim¶
- mergeTwoDicts(x, y)¶
Merges two dictionaries together
- randomizeKeyAttr(obj, attr, time, randomRange=[-1.0, 1.0])¶
Randomizes a single key given the object and attribute
- randomizeKeyCurve(animCurve, time, randomRange=[-1.0, 1.0])¶
Randomizes a single key given the animation curve eg ‘pCube1_translateX1’
:param animCurve:The name of an animation curve node :type animCurve: str :param time: The time/frame to affect :type time: float :param randomRange: the lower and upper values to randomize. The randomize value range. :type randomRange: list(float)
- Return oldValue:
The old value of the keyframe
- Rtype oldValue:
float
- Return newValue:
The updated new value of the keyframe
- Rtype newValue:
float
- randomizeKeysAttrRange(obj, attr, timeRange=[0, 100], randomRange=[-1.0, 1.0])¶
Randomizes keyframe attributes on an object with various options
- Parameters:
- Return animCurve:
An animation curve name, will be “” if None.
- Rtype animCurve:
str
- Return keyTimeList:
A list of keyframe times
- Rtype keyTimeList:
list(float)
- Return oldKeyValues:
A list of keyframe values, these are the old values for the UI cache
- Rtype oldKeyValues:
list(float)
- randomizeKeysAttrRangeCurve(animCurve, timeRange=[0, 100], randomRange=[-1.0, 1.0], message=False)¶
Randomizes keyframe attributes on an object with various options
- Parameters:
- Return keyTimesList:
A list of all keyframes in time
- Rtype keyTimesList:
list(float)
- Return oldKeyValuesList:
A list of the original not changed values, for caching UI purposes
- Rtype oldKeyValuesList:
list(float)
- randomizeKeysObj(obj, attrList, timeRange=[0, 100], randomRange=[-1.0, 1.0], animLayer='')¶
Randomizes a node given the node name (obj) and the attribute list.
returns objCurveDict, all the curves of this object and their time and value lists within the range:
Curve (key), TimeList, ValueList {‘pCube1_translateX’: [[119.0, 120.0], [8.237586020630143, 4.889088181859329]]}
- Parameters:
obj (str) – A Maya object/node name
attrList (list(str)) – A list of node/object attribute names
timeRange (list(float)) – The time range to affect start frame/end frame
randomRange (list(float)) – the lower and upper values to randomize. The randomize value range.
animLayer (str) – A name of a single animation layer
- Return objCurveDict:
Dict of the original animation curves with two lists time and value
- Rtype objCurveDict:
dict(str)
- randomizeKeysObjList(objList, attrList, timeRange=[0, 100], randomRange=[-1.0, 1.0], bake=False, bakeFrequency=1, animLayer='')¶
Randomizes keyframes on an object list given and attribute list. Will skip missing, connected or locked attrs.
Returns objCurveDict, all the curves of this object and their time and value lists within the range:
Curve (key), TimeList, ValueList {‘pCube1_translateX’: [[119.0, 120.0], [8.237586020630143, 4.889088181859329]]}
- Parameters:
objList (list(str)) – A list of Maya object/node names
attrList (list(str)) – A list of node/object attribute names
timeRange (list(float)) – The time range to affect start frame/end frame
randomRange (list(float)) – the lower and upper values to randomize. The randomize value range.
bake (bool) – Bake the time range before randomizing?
bakeFrequency (bool) – Every nth frame to bake if bake is True
animLayer (str) – A name of a single animation layer
- Return graphCurveDict:
Dict of the original animation curves with two lists time and value
- Rtype graphCurveDict:
dict(str)
- getKeyValueList(animCurve, keyTimeList)¶
Given a list of times representing keyframes on an animation curve return their values as a matching list
- randomizeKeysGraphCurves(animCurves, randomRange=[-1.0, 1.0])¶
Randomizes selected animation curve nodes with the given value range (random range)
- getCurveDictsKeyTimesSelection(animCurves)¶
Given a list of animation curves will return a startEndCurveDict with curves as keys and key times listed.
- curveKeyTimeDict:
Curve (key): [TimeList]
- selectKeysBetweenMinMaxTimes(curveKeyTimeDict)¶
Selects all keys between the min and max times, handy for after baking curves and returning new values.
- curveKeyTimeDict:
Curve (key): [TimeList]
- Parameters:
startEndCurveDict (dict(str: list)) – A dictionary of curves as keys and key times as the value
- Return animCurves:
The newly selected animation curves in case of changes
- Rtype animCurves:
list(str)
- randomizeBakeAnimCurves(animCurves, randomRange=[-1.0, 1.0], bake=False, bakeFrequency=1)¶
Randomize with bake option for animation curves only.
Returns a graphCurveDict of the original key values that the UI can use to recalculate and update the noise:
Curve (key): [TimeList, ValueList, RandomFloatList] {‘pCube1_translateX’: [[119.0, 120.0], [8.237586020630143, 4.889088181859329], [0.234, 0.932]]}
- Parameters:
- Return graphCurveDict:
Dict of the original animation curves with two lists time and value
- Rtype graphCurveDict:
dict(str)
- randomizeKeyframesSelection(timeRange=[0, 100], randomRange=[-1.0, 1.0], timeSlider=1, bake=False, bakeFrequency=1, message=True)¶
Randomizes keys frames based on selected Channel Box attributes or selected animation curves with bake options.
Will skip missing, connected or locked attributes.
Returns a graphCurveDict of the original key values that the UI can use to recalculate and update the noise:
Curve (key): [TimeList, ValueList, RandomFloatList] {‘pCube1_translateX’: [[119.0, 120.0], [8.237586020630143, 4.889088181859329], [0.234, 0.932]]}
- Parameters:
timeRange (list(float)) – The start and end frame, only used if the timeSlider is set to 3 (use custom timerange)
randomRange (list(float)) – The min and max range of the randomize value
timeSlider (int) – 0 is playback range, 1 is animation range, 2 is use timeRange kwargs
bake (bool) – Will bake the animation if set to True
bakeFrequency (float) – Will bake every nth frame if bake is True
message (bool) – Return messages to the user?
- Return graphCurveDict:
Dict of the original animation curves with two lists time and value
- Rtype graphCurveDict:
dict(str)
- randomizeKeysGraphSel(randomRange=[-1.0, 1.0], message=True)¶
Randomize selected keys in the graph editor between the randomRange of values.
Returns a graphCurveDict of the original key values that the UI can use to recalculate and update the noise:
Curve (key): [TimeList, ValueList, RandomFloatList] {‘pCube1_translateX’: [[119.0, 120.0], [8.237586020630143, 4.889088181859329], [0.234, 0.932]]}
- class RandomizeKeyframes¶
Bases:
object
Class for dealing with scaling keys from the center pivot of each graph curve. Used by UIs
- setRandomizeScale(randomizeScale)¶
Sets the range of the value scale as one float value
- Parameters:
randomizeScale (float) – The scale value of the randomize 2.0 gets converted to [-1.0, 1.0]
- setRandomizeRange(randomizeRange)¶
The min and max range of the value scale
- Parameters:
randomizeRange (list(float)) – Min and max range of the value scale [min, max]
- setBakeFrequency(bakeFrequency)¶
Set the bake frequency in frames as a float. Can only be used with self.bakeState = True
- Parameters:
bakeFrequency (float) – Bake every nth frame
- setTimeRange(timeRange)¶
Set the time range as two floats. [frameIn, frameOut] Note: Only used if self.setTimeSliderMode = 3 # custom frame range
- Parameters:
timeRange (list(float)) – Set the frame in and out [frameIn, frameOut]
- setBakeState(bakeState)¶
Set the bake state as a boolean. True or False
- Parameters:
bakeState (bool) – True if to bake in channel box, False is no bake.
- setTimeSliderMode(timeSliderMode)¶
Set the time slider mode options.
- Parameters:
timeSliderMode (int) – 0 is playback range, 1 is animation range, 2 is use timeRange kwargs
- clearCache()¶
Clears the self.cacheDict and self.animCurves
- cacheExists()¶
Returns True if the self.cacheDict contains values, False if not
- buildCacheCurvesSel(message=True)¶
Creates the self.cacheDict from the selected animation curves
- Parameters:
message (bool) – Report a message to the user?
- randomizeAnimCurvesSelection()¶
Randomizes the animation curves based on selected animation curves
- randomizeKeysSelection()¶
Main function that randomizes animation based on the selected objects/attr or curves
- resetKeys()¶
Resets all keys to original positions in the cache
- randomizeKeysFromCache()¶
Randomizes the current cache based on the current settings
- reSeedKeys()¶
Performs the randomize again with a new random seed
Resetattrs¶
- resetNodes(nodes, skipVisibility=True, proxies=True, message=False)¶
Resets all keyable unlocked attributes on given objects to their default values.
Will filter to the channelBox selection if there is one.
If from selection will only work on transform nodes. See resetSelection()
Great for running on a large selection such as all character controls.
- resetAttrs(node, attrs, proxies)¶
Resets all keyable unlocked attributes provided
Scaleretime¶
- class ScaleKeysCenter(scaleAmount=1.0, animCurves=[], scaleCacheDict={}, mode='average')¶
Bases:
object
Class for dealing with scaling keys from the center pivot of each graph curve.
- setScaleAmount(scaleValueAmount)¶
Updates the scale value amount for the class. scaleValueAmount is a float 2.0 scales double.
- Parameters:
scaleValueAmount (float) – The value to scale by
- setMode(mode)¶
Sets the mode of the scale, modes are in the global list AVERAGE_MODES:
“average”: Finds the average of all keys for the center pivot, “minMaxCenter”: Finds the middle value of the highest and lowest point
- Parameters:
mode (str) – “average” finds the average of all keys for the center pivot, “minMaxCenter” finds middle of hi/low
- clearCache()¶
Clears the cache values
- resetScale()¶
Resets all values to the original cached values in the scaleCacheDict.
- buildCache(message=True)¶
Creates the cache ready for scaling, cache values are
self.scaleCacheDict, is a dict of curves keys with time and value lists:
Curve (key), TimeList, ValueList {‘pCube1_translateX’: [[119.0, 120.0], [8.237586020630143, 4.889088181859329]]}
- Parameters:
message (bool) – Report messages to the user
- cacheDictFromSelected(message=True)¶
Creates the cache ready for scaling, uses the current selection. See self.buildCache() for more info
- Parameters:
message (bool) – Report messages to the user
- scaleKeysCenter()¶
Main function that center scales from the cache values and self.scaleValueAmount Note this method uses calculates the new scale values in python and sets via cmds.keyframe() Can be used to update the cache curves at any time.
self.scaleCacheDict, is a dict of curves keys with time and value lists:
Curve (key), TimeList, ValueList {‘pCube1_translateX’: [[119.0, 120.0], [8.237586020630143, 4.889088181859329]]}
Set the scale value with:
instance.setScaleAmount(scaleValueAmount)
Create the self.scaleCacheDict with:
instance.cacheDictFromSelected()
- MayaFloatToPercentage(timeScale)¶
Convert time scale: Maya Float to Percentage
- Parameters:
timeScale (float) – new time scale in the new time mode
- MayaFloatToFPS(timeScale)¶
Convert time scale: Maya Float to Frames Per Second
- Parameters:
timeScale (float) – new time scale in the new time mode
- percentageToMayaFloat(timeScale)¶
Convert time scale: Percentage to Maya Float
- Parameters:
timeScale (float) – new time scale in the new time mode
- percentageToFPS(timeScale)¶
Convert time scale: Percentage to Frames Per Second
- Parameters:
timeScale (float) – new time scale in the new time mode
- FPStoMayaFloat(timeScale)¶
Convert time scale: Frames Per Second to Maya Float
- Parameters:
timeScale (float) – new time scale in the new time mode
- FPStoPercentage(timeScale)¶
Convert time scale: Frames Per Second to Percentage
- Parameters:
timeScale (float) – new time scale in the new time mode
- convertTimeScale(timeScale, oldType=0, newType=1, message=True)¶
Converts a scale in one time type to another
Types:
Maya Float, Maya float style twice as fast is 0.5.
Percentage, Scales time as a percentage similar to an edit program. Twice as fast is 200%.
Frames Per Second, Scales time as frames per second similar to an edit program. Twice as fast is 48 if 24fps.
- animRetimer(startRange=0, endRange=100, timeScale=1.0, snapKeys=True, selectType=0, timeScaleOptions=0, ripple=True, allAnimLayers=True, message=True)¶
Numeric time scale of keyframes within a time range, will ripple offset the keys after the endRange
The timeScale will be scale as per the timeScaleOptions
0 - Maya float style twice as fast is 0.5 1 - Scales time as a percentage similar to an edit program. Twice as fast is 200% 2 - Scales time as frames per second similar to an edit program. Twice as fast is 48 if 24fps.
The selectType can affect various objects:
0 - selection: use the current selection 1 - hierarchy: use the current selection and all animated objects in the hierarchy under the selection 2 - all: use all animated objects in the scene
- Parameters:
startRange (float) – The start frame of the section to re-time
endRange (float) – The end frame of the section to re-time
timeScale (bool) – The scale value to affect time, see timeScaleOptions for how time will be scaled
snapKeys (bool) – True if the user wants to snap keyframes to whole frames after scaling
selectType (int) – 0 is Affect selected objs. 1 is selected and anim hierarchy. 2 is select all anim in scene
timeScaleOptions (int) – 0 is maya float, 1 is percentage, 2 is fps. See description for more info.
ripple (bool) – move the keys outside of the range being scaled?
message (bool) – report the message back to the user?
Timerange¶
- playbackRangeStartToCurrentFrame(animationStartTime=True)¶
Sets the range slider start to be the current frame in time
- Parameters:
animationStartTime (bool) – if True sets the range to be the entire range, False is playback range only
- playbackRangeEndToCurrentFrame(animationEndTime=True)¶
Sets the range slider end to be the current frame in time
- Parameters:
animationEndTime (bool) – if True sets the range to be the entire range, False is playback range only
- animMoveTimeForwardsBack(frames)¶
Moves the time slider back or forwards by these amount of frames. Can be a negative number for backwards.
- Parameters:
frames (float) – The amount of frames to offset from current time
- getRangePlayback()¶
Returns the playback range, so the start and end frame of the grey bar in the timeline
- Return timeRange:
The start and end time in a list
- Rtype timeRange:
list(float)
- getRangeAnimation()¶
Returns the animation range, so the start and end frame of whole timeline. Not the grey bar but the min and max range.
- Returns:
The start and end time in a list
- Return type:
list(float)
- getSelectedFrameRange(timeControl=None)¶
Returns the current selected frame range in specified timeControl widget. If not widget specified it will use mayas global timeline.
- getSelectedOrCurrentFrameRange(timeControl=None)¶
Returns the current selected frame range in specified timeControl widget if theres more than 1 frameSelected otherwise the current range in the visible timeControl is returned.
If not widget specified it will use mayas global timeline.
- getTimeRangeAnimCurveSelection(animCurve)¶
- getTimeRangeAnimCurveList(animCurveList)¶
- keysInRange(obj, attr, timeRange=[-100])¶
Returns all keyframes of an attribute within a range
- Parameters:
obj –
attr –
timeRange –
- Returns:
- Return type:
- keysInRangeCurve(animCurve, timeRange=[-100])¶
Returns all keyframes of an attribute within a range
- Parameters:
animCurve –
timeRange –
- Returns:
- Return type: