Search code examples
pythonmayapymel

Maya/Python: How do I scale multiple selected animation curves each from their own specific pivot point?


I'm trying to do a scale operation of multiple animation curves, each using its lowest key as the pivot point. I am thinking it should be a nested for loop structure but have not been able to get it working properly.

The scaling is simple, just:

mykeys = pm.keyframe( query=True, valueChange=True, absolute=True )
low = min(mykeys)
pm.scaleKey( valuePivot=low, valueScale=1.5 )

I am thinking it should be something similar to?

selectedCurves = pm.listConnections( t="animCurve")
for curve in selectedCurves:
    mykeys = pm.keyframe( query=True, valueChange=True, absolute=True )
    low = min(mykeys)
    pm.scaleKey( valuePivot=low, valueScale=1.5 )

Thanks in advance.


Solution

  • You have it right, you're just not telling the command to work on only one curve at a time:

    selectedCurves = cmds.listConnections( t="animCurve")
    for curve in selectedCurves:
        mykeys = cmds.keyframe(curve, query=True, valueChange=True, absolute=True )
        low = min(mykeys)
        cmds.scaleKey(curve, valuePivot=low, valueScale=1.5 )