Skip to content

Instantly share code, notes, and snippets.

@BigRoy
Created January 13, 2023 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BigRoy/ecf450f9f5a0ae0a59651bbb06eb2af5 to your computer and use it in GitHub Desktop.
Save BigRoy/ecf450f9f5a0ae0a59651bbb06eb2af5 to your computer and use it in GitHub Desktop.
Maya Python code example on how to shift animation keys for an export
from maya import cmds
import contextlib
@contextlib.contextmanager
def offsetted_keys(offset, nodes=None):
if nodes is None:
# Apply to all time-based animation curves (excluding driven keys)
nodes = cmds.ls(type=("animCurveTL","animCurveTU","animCurveTA","animCurveTT"))
try:
cmds.keyframe(nodes, edit=True, relative=True, selected=False, timeChange=offset)
yield
finally:
cmds.keyframe(nodes, edit=True, relative=True, selected=False, timeChange=-offset)
start = 30
with offsetted_keys(-start):
# Implement your export logic here
export()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment