gp_render/OP_render_scenes.py

119 lines
3.7 KiB
Python

import bpy
from . import fn
from time import time
from bpy.types import Panel, UIList, Operator, PropertyGroup, Menu
from bpy.props import PointerProperty, IntProperty, BoolProperty, StringProperty, EnumProperty, FloatProperty
class GPEXP_OT_render_all_scenes(bpy.types.Operator):
bl_idname = "gp.render_all_scenes"
bl_label = "Render all scenes"
bl_description = "Render all scene except Render"
bl_options = {"REGISTER"}
@classmethod
def poll(cls, context):
return True
def execute(self, context):
start = time()
ct = 0
for scn in bpy.data.scenes:
if scn.name == 'Scene':
continue
if not scn.use_nodes:
continue
outfiles = [n for n in scn.node_tree.nodes if n.type == 'OUTPUT_FILE']
if not outfiles:
print(f'\n -!-> Skip {scn.name}, No output files')
continue
if all(x.mute for x in outfiles):
print(f'\n -!-> Skip {scn.name}, All output file are muted')
continue
print(f'\n --> Rendering {scn.name}')
# bpy.context.window.scene = scn
bpy.ops.render.render(animation=True, scene=scn.name)
ct += 1
print(f'\nDone. {ct} scenes rendered in {time()-start:.2f}s')
return {"FINISHED"}
class GPEXP_scene_select_prop(PropertyGroup):
name : StringProperty()
select: BoolProperty()
class GPEXP_OT_render_selected_scene(bpy.types.Operator):
bl_idname = "gp.render_selected_scenes"
bl_label = "Render Selected Scenes"
bl_description = "Launch render of selected scenes with a selection popup"
bl_options = {"REGISTER"}
@classmethod
def poll(cls, context):
return True
def invoke(self, context, event):
context.scene.scenes_list.clear()
for s in bpy.data.scenes:
scn_item = context.scene.scenes_list.add()
scn_item.name = s.name
scn_item.select = s.name != 'Scene'
return context.window_manager.invoke_props_dialog(self, width=250)
def draw(self, context):
layout = self.layout
col = layout.column()
for si in context.scene.scenes_list:
row = col.row()
row.label(text=si.name)
row.prop(si, 'select',text='')
def execute(self, context):
scn_to_render = [si.name for si in context.scene.scenes_list if si.select]
start = time()
ct = 0
for scn_name in scn_to_render:
scn = bpy.data.scenes.get(scn_name)
if not scn.use_nodes:
print(f'{scn.name} has use node deactivated')
continue
outfiles = [n for n in scn.node_tree.nodes if n.type == 'OUTPUT_FILE']
if not outfiles:
print(f'\n -!-> Skip {scn.name}, No output files')
continue
if all(x.mute for x in outfiles):
print(f'\n -!-> Skip {scn.name}, All output file are muted')
continue
print(f'\n --> Rendering {scn.name}')
# bpy.context.window.scene = scn
bpy.ops.render.render(animation=True, scene=scn.name)
ct += 1
print(f'\nDone. {ct} scenes rendered in {time()-start:.2f}s')
return {"FINISHED"}
classes=(
GPEXP_scene_select_prop,
GPEXP_OT_render_selected_scene,
GPEXP_OT_render_all_scenes,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.scenes_list = bpy.props.CollectionProperty(type=GPEXP_scene_select_prop)
def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
del bpy.types.Scene.scenes_list