Hey guys, I don’t even know how to start on this one since I can’t find anything in documentation that would link action tracks and their corresponding strips.
So the basic idea is that I’m a lazy bastard and I never name my damn NLA tracks properly. I do however keep naming convention for the actions. Now it would be awesome if I could use the name of the action to change the name of the track that contains it. Is scripting it even possible when I already have the tracks and strips set up?
Forgive me if this isn’t what you want, but is this possibly what you’re looking for?
import bpy
for o in bpy.data.objects:
if o.animation_data:
for n in o.animation_data.nla_tracks:
n.name = o.animation_data.action.name
Note: An action must be active on an object before the tracks of it can be accessed. I couldn’t find a global method of accessing nla_tracks through bpy.data.actions
, oddly. I’m probably overlooking some minor detail.
I just managed to figure something out but stumbled onto another problem.
To answer your question first, this is not exactly what I’m looking for. Current situation is that i have multiple armatures with actions assigned to them. Perfect scenario would be selecting one armature and pushing actions assigned to it into NLA tracks (with tracks named based on actions). Just the actions within selected armature, nothing more and nothing less.
Right now I have a code that does just that with all of the actions in the file and I’m kind of stuck again.
import bpy
ob = bpy.context.object
for action in bpy.data.actions:
track = ob.animation_data.nla_tracks.new()
track.name = action.name.replace('an_ch_', '')
track.strips.new(action.name, 0, action)
But i might be onto some solution here
import bpy
o = bpy.context.object
if o.animation_data:
a = o.animation_data.action
t = o.animation_data.nla_tracks.new()
t.name = a.name.replace("an_ch_", "")
t.strips.new(a.name, 0, a)