I am trying to create a python script that creates NLA strips for a selected group, and sets the start frame for each of the generated strips.

So I have a scene where I've keyframed a few objects and grouped the objects that have the keyframes. I've put together what I've learned of Blender's Python so far and created a script that I thought would select my group, make some NLA strips for the selected objects, and set the start frame of all strips at frame 60.

It's not quite working as I had hoped. Several strips are created, and only some of them have their start frame controlled. Does anyone have any ideas as to what could be the issue?

#Anim controls

nla_strips = []
for obj in bpy.context.selected_objects:
    if obj.animation_data is not None:
        action = obj.animation_data.action
        if action is not None:
            track = obj.animation_data.nla_tracks.new()
            track.strips.new(action.name, action.frame_range[1], action)
            obj.animation_data.action = None

            if obj.animation_data and obj.animation_data.nla_tracks:

                for track in obj.animation_data.nla_tracks:

                    for strip in track.strips:
                        strip.frame_start = 60
  • 1
    $\begingroup$ Nothing seems obvious with the code. What is different about the ones that fail? Do they have actions? More than one keyframe in the action? Are you running this in a try block that hides error messages? $\endgroup$
    – sambler
    Nov 23, 2017 at 2:35
  • $\begingroup$ I had a definition conflict with a line in my script that was giving me an error with this code. Now that I've fixed the error by setting my definitions properly, I'm trying to figure out how to offset multiple NLA strips rather than just set a start or end frame. $\endgroup$
    – Dassie
    Dec 3, 2017 at 20:46

1 Answer 1


This script here will go through all the actions and push them down to NLA strips. The context has to be changed during selection of the actions. Im not sure why but it works.Using Blender 2.9

 for action in bpy.data.actions:
        bpy.context.area.type = 'DOPESHEET_EDITOR'
        bpy.context.space_data.ui_mode = 'ACTION'
        bpy.context.selected_objects[0].animation_data.action = action
        bpy.context.area.type = 'DOPESHEET_EDITOR'
        bpy.context.space_data.ui_mode = 'ACTION'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .