I want my script to add the selected object to the NLA editor, add an empty track, and then add an action strip to that track.

When I call the tracks_add function, I get the error "Select an existing NLA Track or an empty action line first." Here's my code:

import bpy

# find nla editor area for proper context
area = None
for a in bpy.context.screen.areas:
    if a.type == 'NLA_EDITOR':
        area = a
override = {'area': area}

# check for animation data

# check for existing animation tracks

In the UI it's easy to just click the empty action line. But how can I do this using the Python API so I can add the empty track?

Thanks in advance!


1 Answer 1


Use the API methods.

This can be done via low level calls. Test script below, adds a new track "Foo", adds the action strip, starting at frame 1, using and named after object action.

When adding the track can specify the previous track to insert or append in different orders.

Only requirement is to have reference to an object with an action. Note adds empty animation data if none exists. Test against None to bypass

import bpy

context = bpy.context
ob = context.object

ad = ob.animation_data_create()

action =  ob.animation_data.action

if action:
    track = ad.nla_tracks.new()
    track.name = "Foo"
    strip = track.strips.new(action.name, 1, action)
  • $\begingroup$ This worked great, thank you! $\endgroup$
    – Joel L
    Apr 28, 2020 at 12:45

You must log in to answer this question.

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