I am trying to create a python script that creates NLA strips for a selected group, and sets the start frame for each of the generated strips.

So I have a scene where I've keyframed a few objects and grouped the objects that have the keyframes. I've put together what I've learned of Blender's Python so far and created a script that I thought would select my group, make some NLA strips for the selected objects, and set the start frame of all strips at frame 60.

It's not quite working as I had hoped. Several strips are created, and only some of them have their start frame controlled. Does anyone have any ideas as to what could be the issue?

#Anim controls

nla_strips = []
for obj in bpy.context.selected_objects:
    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[1], action)
            obj.animation_data.action = None

            if obj.animation_data and obj.animation_data.nla_tracks:

                for track in obj.animation_data.nla_tracks:

                    for strip in track.strips:
                        strip.frame_start = 60
  • 1
    $\begingroup$ Nothing seems obvious with the code. What is different about the ones that fail? Do they have actions? More than one keyframe in the action? Are you running this in a try block that hides error messages? $\endgroup$ – sambler Nov 23 '17 at 2:35
  • $\begingroup$ I had a definition conflict with a line in my script that was giving me an error with this code. Now that I've fixed the error by setting my definitions properly, I'm trying to figure out how to offset multiple NLA strips rather than just set a start or end frame. $\endgroup$ – Dassie Dec 3 '17 at 20:46

Your Answer

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

Browse other questions tagged or ask your own question.