Skip to content

Instantly share code, notes, and snippets.

@pmolodo
Created December 21, 2018 01:00
Show Gist options
  • Save pmolodo/9ca6750b1c7f5b748d7f19cf62405b2e to your computer and use it in GitHub Desktop.
Save pmolodo/9ca6750b1c7f5b748d7f19cf62405b2e to your computer and use it in GitHub Desktop.
Maya bug report: MAnimCurveChange for an MFnAnimCurve.setTime does not work after undoing/redoing an addKeys
# test AnimCurve.setTime undo/redo - api only
import maya.OpenMaya as om
import maya.OpenMayaAnim as oma
import maya.cmds as cmds
cmds.file(new=1, f=1)
curve = cmds.createNode('animCurveTL')
sel = om.MSelectionList()
sel.add(curve)
curveObj = om.MObject()
sel.getDependNode(0, curveObj)
mfnCurve = oma.MFnAnimCurve(curveObj)
origTimes = [0, 10, 20, 30, 40]
origVals = [0, 1, 2, 3, 4]
timeUnit = om.MTime.uiUnit()
mTimes = om.MTimeArray()
for t in origTimes:
mTimes.append(om.MTime(t, timeUnit))
mVals = om.MDoubleArray()
for v in origVals:
mVals.append(v)
linear = oma.MFnAnimCurve.kTangentLinear
# add keys
addKeysChange = oma.MAnimCurveChange()
mfnCurve.addKeys(mTimes, mVals, linear, linear, False, addKeysChange)
assert mfnCurve.numKeys() == 5
assert mfnCurve.time(1) == om.MTime(10, timeUnit)
assert mfnCurve.value(1) == 1
# check that addKeysChange undo/redo works by itself
addKeysChange.undoIt()
assert mfnCurve.numKeys() == 0
addKeysChange.redoIt()
assert mfnCurve.numKeys() == 5
assert mfnCurve.time(1) == om.MTime(10, timeUnit)
# retime key index=1
retimeChange = oma.MAnimCurveChange()
mfnCurve.setTime(1, om.MTime(8, timeUnit), retimeChange)
assert mfnCurve.numKeys() == 5
assert mfnCurve.time(1) == om.MTime(8, timeUnit)
# check that retimeChange undo/redo works by itself
retimeChange.undoIt()
assert mfnCurve.numKeys() == 5
assert mfnCurve.time(1) == om.MTime(10, timeUnit)
retimeChange.redoIt()
assert mfnCurve.numKeys() == 5
assert mfnCurve.time(1) == om.MTime(8, timeUnit)
# check that we can undo + redo both changes
retimeChange.undoIt()
assert mfnCurve.numKeys() == 5
assert mfnCurve.time(1) == om.MTime(10, timeUnit)
addKeysChange.undoIt()
assert mfnCurve.numKeys() == 0
addKeysChange.redoIt()
assert mfnCurve.numKeys() == 5
assert mfnCurve.time(1) == om.MTime(10, timeUnit)
retimeChange.redoIt()
assert mfnCurve.numKeys() == 5
# redoing, after undoing/redoing the addKeys, doesn't work!
assert mfnCurve.time(1) == om.MTime(8, timeUnit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment