expose autobuild options

1.1.2

- added: popup panel with options for autobuild
main
pullusb 2023-01-10 18:41:09 +01:00
parent 7f359dd910
commit fd91900328
3 changed files with 195 additions and 1 deletions

View File

@ -14,6 +14,10 @@ Activate / deactivate layer opacity according to prefix
Activate / deactivate all masks using MA layers Activate / deactivate all masks using MA layers
--> -->
1.1.2
- added: popup panel with options for autobuild
1.1.1 1.1.1
- changed: autobuild beta - changed: autobuild beta

View File

@ -45,6 +45,194 @@ def batch_setup_render_scene(context=None):
## Trigger check file before finishing ? ## Trigger check file before finishing ?
# bpy.ops.gp.check_render_scene('INVOKE_DEFAULT') # bpy.ops.gp.check_render_scene('INVOKE_DEFAULT')
class GPEXP_OT_render_auto_build(bpy.types.Operator):
bl_idname = "gp_export.render_auto_build"
bl_label = "Auto-Build"
bl_description = "Trigger all operation to make build render scene with default settings"
bl_options = {"REGISTER"}
@classmethod
def poll(cls, context):
return context.object and context.object.type == 'GPENCIL'
timer : bpy.props.FloatProperty(default=0.1, options={'SKIP_SAVE'})
excluded_prefix : bpy.props.StringProperty(
name='Excluded Layer By Prefix', default='GP, RG, PO',
description='Exclude layer to send to render by prefix (comma separated list)')
clean_name_and_visibility : bpy.props.BoolProperty(name='Clean Name And Visibility', default=True,
description='Add object name to layer name when there is only prefix (ex: "CO_")\
\nEnable visibility for layer with prefix included in Prefix Filter')
prefix_filter : bpy.props.StringProperty(name='Prefix Filter', default='CO, CU, FX, TO, MA',
description='Comma separated prefix to render. Set the other prefix and non-prefixed layer to exluded viewlayer')
set_layers_colors : bpy.props.BoolProperty(name='Set Layers Colors', default=True,
description='')
trigger_rename_lowercase : bpy.props.BoolProperty(name='Trigger Rename Lowercase', default=True,
description='')
trigger_renumber_by_distance : bpy.props.BoolProperty(name='Trigger Renumber By Distance', default=True,
description='')
export_layer_infos : bpy.props.BoolProperty(name='Export Layer Infos', default=True,
description='')
group_all_adjacent_layer_type : bpy.props.BoolProperty(name='Group All Adjacent Layer Type', default=True,
description='')
change_to_gp_workspace : bpy.props.BoolProperty(name='Change To Gp Workspace', default=True,
description='')
batch_setup_render_scene : bpy.props.BoolProperty(name='Batch Setup Render Scene', default=True,
description='')
def invoke(self, context, event):
# return self.execute(context)
return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
layout = self.layout
col = layout.column()
col.prop(self, 'clean_name_and_visibility')
row = col.row()
row.prop(self, 'prefix_filter')
row.active = self.clean_name_and_visibility
col.prop(self, 'set_layers_colors')
col.prop(self, 'trigger_rename_lowercase')
col.prop(self, 'trigger_renumber_by_distance')
col.prop(self, 'export_layer_infos')
col.label(text='Send prefixed layer to render scene (except excluded)')
col.prop(self, 'excluded_prefix', text='Excluded')
col.prop(self, 'group_all_adjacent_layer_type')
col.prop(self, 'change_to_gp_workspace')
col.prop(self, 'batch_setup_render_scene')
# layout.prop(self, 'clear_unused_view_layers')
def execute(self, context):
print('-- Auto-build Render scene --\n')
## Prefix Filter
# TODO : add to preferences / environment var
# prefix_to_render = ['CO', 'CU', 'FX', 'TO', 'MA']
prefix_to_render = [p.strip() for p in self.prefix_filter.split(',')]
render_scn = bpy.data.scenes.get('Render')
if render_scn:
self.report({'ERROR'}, 'A "Render" scene already exists')
return {'CANCELLED'}
## clean name and visibility
if self.clean_name_and_visibility:
for o in [o for o in context.scene.objects if o.type == 'GPENCIL']:
if o.hide_render:
print(f'skip: {o.name} hide render')
continue
for l in o.data.layers:
## Clean name when layer has no name after prefix
if re.match(r'^[A-Z]{2}_$', l.info):
l.info = l.info + o.name.lower()
## Make used prefix visible ?
if (res := re.search(r'^([A-Z]{2})_', l.info)):
if res.group(1) in prefix_to_render and l.hide == True:
print(f'{o.name} -> {l.info} : Switch visibility On')
l.hide = False
ob_list = [o for o in context.scene.objects if o.type == 'GPENCIL' and not o.hide_get() and fn.is_valid_name(o.name)]
if not ob_list:
self.report({'ERROR'}, 'No GP object to render found')
return {'CANCELLED'}
print('GP objects to send:')
for o in ob_list:
print(f' - {o.name}')
## Set layers colors (skip if colors were already set ?)
if self.set_layers_colors:
# Option: Maybe find a way to create a color from prefix hash ? (always give unique color with same prefix on other project!)
fn.set_layer_colors(skip_if_colored=True)
## Trigger rename lowercase
if self.trigger_rename_lowercase:
print('Trigger rename lowercase')
bpy.ops.gp.lower_layers_name('EXEC_DEFAULT')
# bpy.ops.gp.lower_layers_name('INVOKE_DEFAULT')
## Trigger renumber by distance
if self.trigger_renumber_by_distance:
print('Trigger renumber by distance')
bpy.ops.gp.auto_number_object('EXEC_DEFAULT')
# bpy.ops.gp.auto_number_object('INVOKE_DEFAULT')
## Export layer infos ? (skip if json already exists)
if self.export_layer_infos:
print('Export layer infos (skip if json already exists)')
bpy.ops.gp.export_infos_for_compo('INVOKE_DEFAULT', skip_check=True)
## Send all GP to render scene
print('Send all GP to render scene')
# bpy.ops.gp.add_object_to_render(mode="ALL") # Ops to send all
gen_vlayer.export_gp_objects(ob_list, exclude_list=self.excluded_prefix) # Create render scene OTF
## Switch to new Render Scene
print('Switch to new Render Scene')
render_scn = bpy.data.scenes.get('Render')
if not render_scn:
self.report({'ERROR'}, 'No render scene found')
return {'CANCELLED'}
context.window.scene = render_scn
## Group all adjacent layer type
if self.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=self.excluded_prefix, 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 self.change_to_gp_workspace:
if context.window.workspace.name != 'GP Render':
print('Change to GP workspace')
if (render_wkspace := bpy.data.workspaces.get('GP Render')):
context.window.workspace = render_wkspace
else:
render_wkspace_filepath = Path(bpy.utils.user_resource('SCRIPTS'), 'startup', 'bl_app_templates_user', 'GP', 'startup.blend')
ret = bpy.ops.workspace.append_activate(idname='GP Render', filepath=str(render_wkspace_filepath))
print('ret: ', ret)
if ret != {'FINISHED'}:
# Fallback to workspace template shipped with addon (TODO : add template blend file in addon)
render_wkspace_filepath = Path(__file__).parent / 'workspaces' / 'startup.blend'
ret = bpy.ops.workspace.append_activate(idname='GP Render', filepath=str(render_wkspace_filepath))
if ret != {'FINISHED'}:
print('No GP render workspace available')
## Batch setup render scene
if batch_setup_render_scene:
bpy.app.timers.register(batch_setup_render_scene, first_interval=self.timer)
## 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"}
'''
class GPEXP_OT_render_auto_build(bpy.types.Operator): class GPEXP_OT_render_auto_build(bpy.types.Operator):
bl_idname = "gp_export.render_auto_build" bl_idname = "gp_export.render_auto_build"
bl_label = "Auto-Build" bl_label = "Auto-Build"
@ -165,6 +353,8 @@ class GPEXP_OT_render_auto_build(bpy.types.Operator):
print('\nDone.') print('\nDone.')
return {"FINISHED"} return {"FINISHED"}
'''
class GPEXP_OT_render_scene_setup(bpy.types.Operator): class GPEXP_OT_render_scene_setup(bpy.types.Operator):
bl_idname = "gp_export.render_scene_setup" bl_idname = "gp_export.render_scene_setup"

View File

@ -2,7 +2,7 @@ bl_info = {
"name": "GP Render", "name": "GP Render",
"description": "Organise export of gp layers through compositor output", "description": "Organise export of gp layers through compositor output",
"author": "Samuel Bernou", "author": "Samuel Bernou",
"version": (1, 1, 1), "version": (1, 1, 2),
"blender": (2, 93, 0), "blender": (2, 93, 0),
"location": "View3D", "location": "View3D",
"warning": "", "warning": "",