My way could be a bit slow, so would like to hear a faster way. But you have to find the instances where there is only one property (Focal Length or something), or if it’s split out into several animation nodes (X,Y,Z or RGB).
And I think if you’re moving back in time, you need to remember to do the first keys first (or the last keys first when moving forwards).
# The new start time desired.
start_time = 0
for lComponent in FBSystem().Scene.Components:
for lProp in lComponent.PropertyList:
if lProp and lProp.IsAnimatable() and lProp.IsAnimated():
animation_node = lProp.GetAnimationNode()
# For the node, check to see if it has and FCurve or keys.
if animation_node:
# Use "if animation_node.Nodes:" here to detect any nodes with more than one fcurve within.
# Here I'm just using the simplest example with one.
current_curve = animation_node.FCurve
if len(current_curve.Keys) > 0:
if current_curve.Keys:
# Move all the keys to 0 first.
first_key = current_curve.Keys[0].Time.GetFrame()
# Change the direction of the movement depending on the key offset.
if start_time > first_key:
# Backwards
for x in range(len(current_curve.Keys) - 1, -1, -1):
current_frame = current_curve.Keys[x].Time.GetFrame()
new_frame = FBTime(0, 0, 0, (current_frame - first_key) + start_time)
current_curve.Keys[x].Time = new_frame