# Python select empty action line in NLA Editor for Blender 2.8 API

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:
print(a.type)
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?

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