I am writing a script to offset some animations of subsequent objects from an array.
The idea is that I will take the 'old' keyframe data, add some number to it, then insert the 'new' keyframe with the updated data.
import bpy
active_obj = bpy.context.active_object
tracks = active_obj.animation_data.nla_tracks
for track in tracks:
for strip in track.strips:
action = strip.action
for fcu in action.fcurves:
data_path = fcu.data_path # Name of parameter
for keyframe in fcu.keyframe_points:
old_keyframe = keyframe.co
new_keyframe = (old_keyframe.x + 2, old_keyframe.y + 2)
fcu.keyframe_delete(data_path, 0, old_keyframe.x)
When I run this code, I get the error: Traceback (most recent call last): File "X:\path\to\file\offset.py", line 17, in <module> TypeError: bpy_struct.keyframe_insert() property "location" not found
.
My scene is just a single cube that goes from Location Z=9 to Location Z=1 over 30 frames, but I can provide the blend file if you need that.
I'm unsure why it is trying to run keyframe_insert()
when I am not referencing it at all in my script..
Also, I am using Blender 2.93
Documentation for keyframe_delete()
keyframe_insert
andkeyframe_delete
are methods on blender object properties s that can be animated, . for example thelocation
property of the "Cube". An fcurve has neither alocation
property (the error message), nor can it be animated. Suggest if you wish to shift the z location keyframe, search for datapath and array index and set that fcurves value withkeyframe.co.y += 2
(The x part of a keyframe is the frame) $\endgroup$