Skip to content

Instantly share code, notes, and snippets.

@julik
Created September 8, 2012 11:24
Show Gist options
  • Save julik/3673783 to your computer and use it in GitHub Desktop.
Save julik/3673783 to your computer and use it in GitHub Desktop.
slips.py
import nuke, re
def slip_animations_of_node(node, by_offset):
"""
This function will slip all the animations of the passed node by a passed
offset in frames
The animations are offset in the passed TCL curve command.
In this script every frame at which keys are placed is marked by x<FRAME_NUMBER>,
and these are only placed at the start of a non-continuous segment.
Instead of mucking about with AnimationKey objects (which we also
can inadvertently slip behind their following keys), we take the whole curve
and replace all these commands by their respective slipped values
"""
def offset_frames_in_curve(curve_str, offset):
def offset_replace(m):
# Try to preserve float/int distinction
if "." in m.group(1):
return "x%0.3f" % (float(m.group(1)) + offset)
else:
return "x%d" % (int(m.group(1)) + offset)
return re.sub(r"x([-+]?\d*\.\d+|\d+)", offset_replace, curve_str)
# Walk all the knobs of the object and check if they are animated.
for knob_name in node.knobs():
k = node[knob_name]
if k.isAnimated():
k.fromScript(offset_frames_in_curve(k.toScript(), int(by_offset)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment