I needed a way to know whenever a keyframe was set in Maya: There didn't seem to be a way to do this via a scriptJob, but the API to the rescue.
The below callback will print the names of the animCurve nodes modified whenever a keyframe is set.
However, even though the incoming argument to the
If you instead want a callback that iterates over all the channels keyed at once, you can use
The below callback will print the names of the animCurve nodes modified whenever a keyframe is set.
However, even though the incoming argument to the
editedCurves
parameter is an MObjectArray
, it only has a single item (based on testing), meaning if you have 10 nodes selected, this code will be executed 10 separate times using addAnimCurveEditedCallback
:import maya.OpenMaya as om import maya.OpenMayaAnim as oma def animFunc(editedCurves, *args): """ editedCurves : MObjectArray """ for i in range(editedCurves.length()): mFnDependNode = om.MFnDependencyNode(editedCurves[i]) nodeName = mFnDependNode.name() print i,nodeName cid = oma.MAnimMessage.addAnimCurveEditedCallback(animFunc)
# Delete the callback later: om.MMessage.removeCallback(cid)
If you instead want a callback that iterates over all the channels keyed at once, you can use
addAnimKeyframeEditedCallback
:import maya.OpenMaya as om import maya.OpenMayaAnim as oma def animFunc(editedKeys, *args): """ editedKeys : MObjectArray """ for i in range(editedKeys.length()): mFnKeyframeDelta = oma.MFnKeyframeDelta(editedKeys[i]) paramCurve = mFnKeyframeDelta.paramCurve() mFnDependNode = om.MFnDependencyNode(paramCurve) nodeName = mFnDependNode.name() print i,nodeName cid = oma.MAnimMessage.addAnimKeyframeEditedCallback(animFunc)Delete the callback later
om.MMessage.removeCallback(cid)