0
$\begingroup$

I have file with 55 objects and 86 NLA actions using four distinct names - many NLA tracks with the same name are used to control many objects with a single animation when exporting to glTF. I want to preview just one of the action names. How can I iterate through all the NLA stacks and tracks (I think those names are right) and mute all the tracks that don't match the name, and unmute all the tracks that do match the name?

For example, given the string "Length" I want the NLA editor to look like below, muting tracks named "Selected", "Width", or "ShowSymbol", and unmuting all tracks (and their parent stack, if needed) with the name "Length".

Screenshot of NLA editor showing many NLA stacks and strips, with checkboxes only for those actions named "Length"

$\endgroup$

1 Answer 1

0
$\begingroup$

Enabling/disabling the parent stack is done via object.animation_data.use_nla = True/False, while enabling/disabling a specific track is done via nla_track.mute = False/True.

import bpy

desired_action_name = "Length"

for obj in bpy.context.scene.objects:
    if obj.animation_data and obj.animation_data.nla_tracks:
        has_matching_track = False
        for track in obj.animation_data.nla_tracks:
            name_matches = track.name == desired_action_name
            has_matching_track = name_matches or has_matching_track

            # Toggle the checkbox for the track row
            track.mute = not name_matches

            # Ensure no track is solo'd (which overrides muting)
            track.is_solo = False

        # Toggle the checkbox for the object
        obj.animation_data.use_nla = has_matching_track

The script assumes that all NLA strips for other tracks are already unmuted. (Muting a track implicitly mutes the strips in it, so there's no need to mute/unmute the individual strips.)

If you want to ensure all your strips are unmuted:

import bpy
for obj in bpy.context.scene.objects:
    if obj.animation_data and obj.animation_data.nla_tracks:
        for track in obj.animation_data.nla_tracks:
            for strip in track.strips:
                strip.mute = False
$\endgroup$

You must log in to answer this question.

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