Skip to content

Instantly share code, notes, and snippets.

@gabrielmontagne
Created November 16, 2024 16:58
Show Gist options
  • Save gabrielmontagne/0009135e29caea256972f848a1a19573 to your computer and use it in GitHub Desktop.
Save gabrielmontagne/0009135e29caea256972f848a1a19573 to your computer and use it in GitHub Desktop.
Blender Operator to unpack nested scene sounds, to do a final edit from a top-level scene of scenes composed independently
class SCENE_OT_scene_unpack_sound_strips(Operator):
"""
Unpack sound strips from a scene
"""
bl_idname = "rojored.unpack_sound_strips"
bl_label = "Unpack sound strips from a scene"
bl_options = {"UNDO"}
@classmethod
def poll(cls, context):
return context.selected_sequences
def execute(self, context):
print("unpacking sounds", context.selected_sequences)
current_scene = context.scene
current_sequences = current_scene.sequence_editor.sequences
for seq in context.selected_sequences:
if seq.type != "SCENE":
continue
start, end = seq.frame_final_start, seq.frame_final_end
offset_start = seq.frame_offset_start
nested_scene = seq.scene
nested_sequences = nested_scene.sequence_editor.sequences
if not nested_sequences:
continue
for nested in nested_sequences:
if nested.type != "SOUND":
continue
sound = nested.sound
parent_scene_start = start - offset_start
new_sound = current_sequences.new_sound(
name=nested.name,
filepath=sound.filepath,
channel=nested.channel,
frame_start=round(parent_scene_start + nested.frame_start),
)
new_sound.frame_offset_start = nested.frame_offset_start
new_sound.frame_offset_end = nested.frame_offset_end
return {"FINISHED"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment