2
$\begingroup$

I'm working on a platform that requires me to introduce Frame start and end of my animation strips.

I've been looking for a scrip to get a list of the frame range of all the strips i have on my NLA.

I foun this in another thread but it only works for media sources. I hope somebody can help me modify this script to get NLA strip's frame range.

Here's the script i found:

import bpy

context = bpy.context
scene = context.scene
vse = scene.sequence_editor

for strip in vse.sequences_all:
    # Edit Strip Panel
    print("-" * 72)
    print(strip.name)
    print(strip.type)
    # extend for other strip types.
    if strip.type in ['MOVIE']:
        print(strip.filepath)
    elif strip.type in ['SOUND']:
        print(strip.sound.filepath)
    print(strip.channel)
    print(strip.frame_start)
    print(strip.frame_final_duration)
    # Trim Duration (soft)
    print(strip.frame_offset_start)
    print(strip.frame_offset_end)
$\endgroup$
1
  • 1
    $\begingroup$ NLA strips don't show up in the vse, but are data attached to the object. You need to iterate through objects to find their animation_data, and if they have any, then the nla_tracks associated with that and the strips associated with each track. I'm off to dinner, but I'll write up an example later if nobody else already has. $\endgroup$ Oct 2, 2021 at 0:32

1 Answer 1

4
$\begingroup$

Look up the docs, use the python console.

With developer extras on, if we right click on any field and select "Online Python Reference" on for example NLA strip frame start it opens docs for NLAStrip.frame_start

enter image description here

Small script, loop over all objects in scene, then any or all of their NLA data, print name of object, track and strip. Print frame start and frame end of each strip

import bpy

context = bpy.context

for ob in context.scene.objects:
    if not ob.animation_data:
        continue
    print(ob.name)
    for track in ob.animation_data.nla_tracks:
        print("  ", track.name)
        for strip in track.strips:
            print(" " * 4, strip.name, strip.frame_start, strip.frame_end)

Result for IMG above.

Cube
   NlaTrack.002
     CubeAction.003 3.0 67.0
   NlaTrack.001
     CubeAction.002 155.0 219.0
   NlaTrack
     CubeAction -0.29999998211860657 63.79999923706055
     CubeAction.001 110.39999389648438 145.0

Using the python console.

Now we know roundabouts where things are, can make tests in python console, for example the strips of bottom track

>>> strips = C.object.animation_data.nla_tracks[0].strips

Pressing TAB auto completes with available options

>>> strips['CubeAction.003'].
                             action
                             action_frame_end
                             action_frame_start
                             active

for example from above NLAStrip.action_frame_end

References.

Further to the docs, if you scroll down to the bottom to references

enter image description here

it will show ways to reference an instance of that object, in this case an NLA strip. In code above have iterated NLATrack.strips collection. (via track.strips)

If in context of NLA editor, to run over all selected strips, much like context selected objects, use

for strip in context.selected_nla_strips:
    blah

Notice too that a strip has a strips collection, which reminded me, if the strip is a META strip, could check for that, eg

        if strip.type == 'META':
            for s in strip.strips:
                print(s.name)
$\endgroup$
1
  • $\begingroup$ This does not find CubeAction in a simple animation of a cube moving on the Y axis. $\endgroup$ Oct 2, 2021 at 14:01

You must log in to answer this question.

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