Search code examples
pythongraphkeyframemaya

move the key between frames - Maya Graph Editor


I have many keys in Graph Editor, After scaling them, Maya has moved some of them between frames, (frame 5,37-4'54-...). I know how to move them one by one but I would like to create any script to put them one frame after o before.

img

Select All keys - click right - Snap option is not enough

img


Solution

  • Have a look to the selectKey and keyframe commands.

    You could do something like this:

    from maya import cmds
    
    # Select the keys to be moved based on a time interval.
    # For example the following commands will select keys between 5.01 and 5.99.
    # Customize the interval and object/attributes based on your need.
    cmds.selectKey(clear=True)
    cmds.selectKey('pSphere1.tx', add=True, keyframe=True, time=(5.01, 5.99))
    cmds.selectKey('pSphere1.ty', add=True, keyframe=True, time=(5.01, 5.99))
    cmds.selectKey('pSphere1.tz', add=True, keyframe=True, time=(5.01, 5.99))
    
    # Change the time of the selected keys to the correct value (for example 5.0)
    cmds.keyframe(animation='keys', option='over', absolute=True, timeChange=5.0)