Skip to content

Instantly share code, notes, and snippets.

@tin2tin
Created January 17, 2021 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tin2tin/b8c3d8ad9bb39b5c1cfd2cee587cac6a to your computer and use it in GitHub Desktop.
Save tin2tin/b8c3d8ad9bb39b5c1cfd2cee587cac6a to your computer and use it in GitHub Desktop.
Render selected strips
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
import bpy
from bpy.props import StringProperty
class SEQUENCER_OT_export_strip(bpy.types.Operator):
"""Export (render) selected strips in sequencer"""
bl_idname = "sequencer.export_strips"
bl_label = "Export Selected Strips"
filepath: StringProperty(subtype='FILE_PATH')
def execute(self, context):
sce = bpy.context.scene
back_filepath = sce.render.filepath
back_seq = sce.render.use_sequencer
back_start = sce.frame_start
back_end = sce.frame_end
hidden_seq = []
sce.render.use_sequencer = True
sce.render.filepath = self.filepath
seq = sce.sequence_editor
start = end = None
for strip in seq.sequences_all:
if not strip.select:
if not strip.mute:
strip.mute = True
hidden_seq.append(strip)
continue
if start is None or strip.frame_final_start < start:
start = strip.frame_final_start
if end is None or strip.frame_final_end > end:
end = strip.frame_final_end
if start is None or end is None:
return {'CANCELLED'}
sce.frame_start = start
sce.frame_end = end
# Non-blocking render!
bpy.ops.render.render("INVOKE_DEFAULT", animation=True)
for strip in hidden_seq:
strip.mute = False
sce.render.use_sequencer = back_seq
sce.render.filepath = back_filepath
sce.frame_start = back_start
sce.frame_end = back_end
return {'FINISHED'}
def invoke(self, context, event):
if not self.filepath:
self.filepath = bpy.context.scene.render.filepath
winman = context.window_manager
winman.fileselect_add(self)
return {'RUNNING_MODAL'}
def menu_export_strips(self, context):
self.layout.operator("sequencer.export_strips")
classes = (
SEQUENCER_OT_export_strip,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.SEQUENCER_MT_view.append(menu_export_strips)
def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
bpy.types.SEQUENCER_MT_view.remove(menu_export_strips)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment