Skip to main content
Formatting
Source Link
Rug
  • 833
  • 9
  • 26

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()

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..

Documentation for keyframe_delete()

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()

Source Link
Rug
  • 833
  • 9
  • 26

Why does keyframe_delete() seem to call keyframe_insert()?

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..

Documentation for keyframe_delete()