Created
September 8, 2012 11:24
-
-
Save julik/3673783 to your computer and use it in GitHub Desktop.
slips.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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