To add a new strip to the Sequence Editor programmatically, we need to know the channel number to place it. We can get the number of an empty channel in the Sequence Editor throug the Blender Python API by walking through the list of sequences already added to the Sequence Editor.
The list of sequences already added to the Sequence Editor can be obtained as follows:
1 2 3 4 |
bpy.context.scene.sequence_editor.sequences_all[:] # [bpy.data.scenes['Scene'].sequence_editor.sequences_all["image.png"], # bpy.data.scenes['Scene'].sequence_editor.sequences_all["video.mp4"] ... |
Each sequence has a link to the channel on which it is placed:
1 2 3 |
bpy.context.scene.sequence_editor.sequences_all[0].channel # 3 |
So, to get the number of a next empty channel, we need to take the maximum number of already occupied channels and add 1 to it:
1 2 3 |
max((seq.channel for seq in bpy.context.scene.sequence_editor.sequences_all)) + 1 # 6 |
A channel with this number is guaranteed to be empty and we can upload a new strip to it.