I have been trying to get a custom render button to work. The purpose is to render all markers in a timeline. There are examples that use handlers but I could not make it work properly:
import bpy
import os
import time
from bpy.types import Operator, Panel
class Marker_OT_Render(bpy.types.Operator):
bl_idname = "render.markers"
bl_label = "Render markers"
def execute(self, context):
# Variable to continue or stop rendering
complete = False
rendering = True
#output path
output_path = bpy.context.scene.render.filepath
#for filenaming
itemmarkers = bpy.context.scene.timeline_markers.items()
rendername = []
rendername.clear
for m in itemmarkers:
rendername.append(m[0])
#render limit verification
maxframe = bpy.context.scene.frame_end + 1
#position frame for the modal script
bpy.context.scene.frame_set(bpy.context.scene.frame_start - 1)
return {"RUNNING_MODAL"}
def modal(self, context, event):
if complete == False:
if rendering == False:
sc = bpy.context.scene
sc.frame_set(sc.frame_current + 1)
if sc.frame_current != maxframe:
sc.render.filepath = os.path.join(output_path, rendername[sc.frame_current] + ".png")
bpy.ops.render.render("INVOKE_DEFAULT", write_still=True)
else:
complete = True
return {"PASS_THROUGH"}
else:
time.sleep(5)
return {"PASS_THROUGH"}
else:
return {"FINISHED"}
class Render_PT_Buttontest(Panel):
bl_label = "Render Button Test"
bl_idname = "SCENE_PT_RENDERBUTTON"
bl_category = "Tool"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
def draw(self, context):
layout = self.layout
col = layout.column(align=True)
row = layout.row()
row.operator('render.markers', text="Render Button")
layout.separator()
def register():
bpy.utils.register_class(Marker_OT_Render)
bpy.utils.register_class(Render_PT_Buttontest)
def unregister():
bpy.utils.unregister_class(Marker_OT_Render)
bpy.utils.unregister_class(Render_PT_Buttontest)
if __name__ == "__main__":
register()
Q: Is there any way to get the render window when rendering these frames in the timeline?