Last active
October 31, 2023 08:22
-
-
Save tin2tin/f6fa1e78ccae72acca78c924c118e8d3 to your computer and use it in GitHub Desktop.
Join strips operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
def join(vse, current_strip, next_strip): | |
# Calculate the duration of the next strip | |
duration = next_strip.frame_final_end - next_strip.frame_final_start | |
# Remove the next strip from the VSE | |
vse.sequences.remove(next_strip) | |
# Extend the current strip with the duration of the next strip | |
current_strip.frame_final_end += duration | |
class SEQUENCER_OT_join_strips(bpy.types.Operator): | |
"""Join adjoined strips""" | |
bl_idname = "sequencer.join_strips" | |
bl_label = " Join Through Splits" | |
@classmethod | |
def poll(cls, context): | |
return context.scene.sequence_editor and context.selected_sequences | |
def execute(self, context): | |
vse = context.scene.sequence_editor | |
# Define a set of strip types that can be joined | |
join_strip_types = {"MOVIE", "SOUND", "SCENE", "IMAGE"} | |
# Iterate through the selected sequences | |
for current_strip in context.selected_sequences: | |
# Iterate through all sequences in the VSE | |
for next_strip in context.selected_sequences: | |
# Check if the strips are on the same channel and if they're the same type. | |
if ( | |
current_strip.channel == next_strip.channel | |
and current_strip.type == next_strip.type | |
): | |
# Check if the end frame of the current strip matches the start frame of the next strip. | |
if current_strip.frame_final_end == next_strip.frame_final_start: | |
# Check if both the current and next strip types are in the set of joinable strip types | |
if ( | |
current_strip.type in join_strip_types | |
and next_strip.type in join_strip_types | |
): | |
# If the start frame of the current strip matches the start frame of the next strip, join them | |
if current_strip.frame_start == next_strip.frame_start: | |
join(vse, current_strip, next_strip) | |
# If not the the joinable strip types, just join them. | |
else: | |
join(vse, current_strip, next_strip) | |
return {"FINISHED"} | |
def draw_func(self, context): | |
layout = self.layout | |
layout.operator("sequencer.join_strips") | |
def register(): | |
bpy.utils.register_class(SEQUENCER_OT_join_strips) | |
bpy.types.SEQUENCER_MT_strip.append(draw_func) | |
def unregister(): | |
bpy.utils.unregister_class(SEQUENCER_OT_join_strips) | |
bpy.types.SEQUENCER_MT_strip.remove(draw_func) | |
if __name__ == "__main__": | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment