Is there a way in python to check if an NLA track has open space in a range of frames? I couldn’t find anything in the API nor by using the dir() function in a python console. I would expect it to be either in the NlaTrack class or the NlaStrips class. The only way I can think of so far is to run NlaStrips.new and catch the error, such as:
try: track.strips.new("NewStrip", 35, bpy.data.actions["SomeAction"]) except Exception as e: err = e if 'Error: Unable to add strip (the track does not have any space to accommodate this new strip)\n' in err.args: # code for what to do if there is no room for the strip
One problem with this is that it will initially attempt to create a strip that is the length of the action, which could be past open space in the track. However, I might want to run the action quicker or only use part of the action. For example, suppose a track is free from frames 30-80, and I use NlaStrips.new to create a strip with an action that lasts 100 frames, but I only want to use the first 25 frames. Do do this I would have to initially create the strip as 100 frames long then set NlaStrip.action_frame_end to 25. This would make the strip last from frames 35-60, which would fit since the track is open from frames 30-80. However, since it initially makes the strip 100 frames long, it would last from frames 30-130, and would overlap the strip that starts at frame 81. This would cause the error and the strip would not be created.
The only way I can think of around this is to create a dummy action that lasts only 1 frame, then change NlaStrip.action to the action I want the strip to use. However, this all does not seem like good practice. Is there a way to check if a track is open at a frame, or for a range of frames? Is there a way to set the length of a strip when using NlaStrips.new so that it wouldn’t overlap other strips in the same track?