autobuild beta max

main
pullusb 2023-01-06 16:05:09 +01:00
parent a736eec7c9
commit dd57f0651e
2 changed files with 19 additions and 33 deletions

View File

@ -63,7 +63,7 @@ class GPEXP_OT_render_auto_build(bpy.types.Operator):
def execute(self, context):
print('-- Auto-build Render scene --\n')
## TODO: add colors to layers (specified in ENV or hardcoded for now...)
## TODO: Add colors to layers (specified in ENV or hardcoded for now...)
## Option: Maybe find a way to create a color from prefix hash ? (always give unique color with same prefix on other project!)
render_scn = bpy.data.scenes.get('Render')
@ -103,8 +103,21 @@ class GPEXP_OT_render_auto_build(bpy.types.Operator):
if not render_scn:
self.report({'ERROR'}, 'No render scene found')
return {'CANCELLED'}
context.window.scene = render_scn
## Group all adjacent layer type
print('Group all adjacent layer type')
for ob in ob_list:
fn.group_adjacent_layer_prefix_rlayer(ob, excluded_prefix=['GP', 'PO', 'RG'], first_name=True)
bpy.ops.gp_export.render_scene_setup() # next render scene setup at once
## attempt to refresh scene
# render_scn.node_tree.nodes.update()
# context.view_layer.update()
# context.scene.update_tag()
## Change to GP workspace (if needed)
if context.window.workspace.name != 'GP Render':
print('Change to GP workspace')
@ -121,41 +134,12 @@ class GPEXP_OT_render_auto_build(bpy.types.Operator):
if ret != {'FINISHED'}:
print('No GP render workspace available')
## Group all adjacent layer type
print('Group all adjacent layer type')
for ob in ob_list:
fn.group_adjacent_layer_prefix_rlayer(ob, excluded_prefix=['GP', 'PO', 'RG'], first_name=True)
# bpy.ops.gp_export.render_scene_setup() # next render scene setup at once
## Renumber File outputs
print('Renumber File outputs')
for fo in render_scn.node_tree.nodes:
if fo.type == 'OUTPUT_FILE':
fn.renumber_keep_existing(fo)
## Swap to bg_cam (if any)
if render_scn.objects.get('bg_cam') and (not render_scn.camera or render_scn.camera.name != 'bg_cam'):
print('Swap to bg cam')
bpy.ops.gp.swap_render_cams()
## Go to camera view in visible viewports
if render_scn.camera:
print('Go to camera view in visible viewports')
for window in bpy.context.window_manager.windows:
screen = window.screen
for area in screen.areas:
if area.type == 'VIEW_3D':
area.spaces.active.region_3d.view_perspective = 'CAMERA'
## Clean compo Tree
print('Clean compo Tree')
# bpy.ops.gp.clean_compo_tree('INVOKE_DEFAULT', use_render_scene=True)
bpy.ops.gp.clean_compo_tree('EXEC_DEFAULT', use_render_scene=True)
bpy.app.timers.register(batch_setup_render_scene, first_interval=0.001)
## Trigger check file before finishing ?
# bpy.ops.gp.check_render_scene('INVOKE_DEFAULT')
## Note: After all these operation, a ctrl+Z might crash
print('\nDone.')
return {"FINISHED"}

View File

@ -111,7 +111,7 @@ class GPEXP_OT_clean_compo_tree(bpy.types.Operator):
# box.prop(self, 'fo_clear_disconnected')
def execute(self, context):
if self.use_render_scene:
if self.use_render_scene:
render = bpy.data.scenes.get('Render')
if not render:
print('SKIP clean_compo_tree, No "Render" scene !')
@ -120,6 +120,8 @@ class GPEXP_OT_clean_compo_tree(bpy.types.Operator):
render = context.scene
nodes = render.node_tree.nodes
for n in nodes:
n.update()
if self.clear_unused_view_layers:
used_rlayer_names = [n.layer for n in nodes if n.type == 'R_LAYERS']
for rl in reversed(render.view_layers):