Skip to content

Instantly share code, notes, and snippets.

@RedForty
Created October 15, 2017 05:40
Show Gist options
  • Save RedForty/258afa25661f9ea28b5b3465d319da90 to your computer and use it in GitHub Desktop.
Save RedForty/258afa25661f9ea28b5b3465d319da90 to your computer and use it in GitHub Desktop.
Turbo charged swapKeys
import maya.cmds as cmds
import selectedAttributes
sel = cmds.ls(selection=True)
if cmds.scaleKey(attribute=True): # Is a key/curve selected?
keys = cmds.keyframe(sel, query=True, selected=True) or []
attributes = cmds.keyframe(sel, query=True, selected=True, name=True) or []
first_key = min(keys)
last_key = max(keys)
mid_pivot = (first_key + last_key) / 2
for attribute in attributes:
cmds.scaleKey(attribute, time=(first_key, last_key), timeScale=-1, timePivot=mid_pivot )
else:
channel_attributes = selectedAttributes.get()
list_of_keys = []
for attribute in channel_attributes:
list_of_keys.extend(cmds.keyframe(attribute, query=True) or [])
first_key = min(list_of_keys)
last_key = max(list_of_keys)
mid_pivot = (first_key + last_key) / 2
for attribute in channel_attributes:
cmds.scaleKey(attribute, time=(first_key, last_key), timeScale=-1, timePivot=mid_pivot )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment