2
$\begingroup$

System Information Operating system: Windows 10

Blender Version 2.93.5

Hi, im fairly new to the python scripting in blender, how would i go about moving these 3 action strips from this:

Initial state

To this, joining them in the same channel, and in the end select them and add transition.

Final state

I can't seem to find translation of the NLA strips in the python documentation and when i run the code that appears in the info window it doesn't work.

$\endgroup$

1 Answer 1

2
$\begingroup$

You can't actually move strips between NLA Tracks. Instead, you have to do it in two steps:

  1. Delete the strip from the old track.
  2. Add the strip to the new track.

This can be done in either order.

Once you have the new strip, you can modify the NlaStrip itself to add transitions and modifiers. You can do this to any NlaStrip once you've looked it up.

There is one small detail about adding a strip: you have to tell Blender where in the NlaTrack the strips should go. In my example, I'm placing the strips one frame after the end of last strip already in the NLaTrack.

I start with a situation similar to yours: 3 tracks, each with a single strip.

NLA Editor showing 3 tracks each with a single strip

I then execute this code:

import bpy

# Assume we want to deal with actions associated with the active object
object = bpy.context.active_object
tracks = object.animation_data.nla_tracks

# For a different set up, replace "NlaTrack.002" with the name of the destination track
dst_track = tracks["NlaTrack.002"]

# For a different set up, replace "NlaTrack.001" with the name of the source track.
src_track = tracks["NlaTrack.001"]

# Assume that the strip to be moved is the first strip on the track.
# We could, instead, simply select an action from bpy.data.actions and not bother
# with an additional strip
src_strip = src_track.strips[0]

# We really need the action, not the strip
action = src_strip.action

# Since we are "moving" the strip, we delete it from the src track
src_track.strips.remove(src_strip)

# The 2nd argument is the frame number where the action goes. It has to be an integer.
# We assume that it goes adjacent to the last strip already on the track.
new_strip = dst_track.strips.new(action.name, int(dst_track.strips[-1].frame_end+1), action)

# Now you can use new_strip to set transition or add modifiers.  See the manual entry
# https://docs.blender.org/api/current/bpy.types.NlaStrips.htm for details on the fields
# for instance
# new_strip.blend_in = SOME_FRAME_NUMBER


# This is unnecessary for just "moving" a strip.  Here only for completeness.
tracks.remove(src_track)

# This is just a repeat of the above, but applied to a different track.
src_track = tracks["NlaTrack"]
src_strip = src_track.strips[0]
action = src_strip.action
src_track.strips.remove(src_strip)
new_strip = dst_track.strips.new(action.name, int(dst_track.strips[-1].frame_end+1), action)
tracks.remove(src_track)

You didn't ask to show how to remove tracks, but in my example I do remove them. That's simply to show how it is done. After the code runs, the NLA editor looks like this:

NLA Editor after execution

$\endgroup$
1
  • 1
    $\begingroup$ Thank you for the response it worked ! my final objective is to fully automate the process of appending animations and joining them together, now i understand how these strips work, i will now try to add the strips directly in the same track after appending them in the same file instead $\endgroup$ Mar 5, 2022 at 17:03

You must log in to answer this question.

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