I'm trying to write a script that push down all actions in NLA-Editor. No matter how many actions exist, it should work.

This is the code I currently have:

bpy.context.area.type = "NLA_EDITOR"
bpy.ops.nla.action_pushdown(channel_index = 1)

My problem is that I don't know what channel_index each action has. How can I get this index? Or is there a way to iterate through all actions in in the nla editor?

  • $\begingroup$ Agree with your answer, using API methods rather than bpy.ops. In answer to your question re channel index, could use nla_tracks.find(trackname) which returns either channel, or -1 if not found. $\endgroup$ – batFINGER Aug 22 '17 at 13:40
  • $\begingroup$ thank you for your answer! Now I'm not gonna try it, but I'll keep in mind. $\endgroup$ – matt Aug 22 '17 at 14:35

I have the answer:

I don't Need to go to nla-editor, I just add a new track and a new Strip with the Action, which I get from my object.

for obj in bpy.context.scene.object:
    if obj.animation_data is not None:
        action = obj.animation_data.action
        if action is not None:
            track = obj.animation_data.nla_tracks.new()
            track.strips.new(action.name, action.frame_range[0], action)
            obj.animation_data.action = None
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.