Add templates options for fileoutput
1.7.3
- added: Optional string templates for fileoutputs
- add `base_path, file_slot, layer_slot` arguments to operators
- possible keywords are as follow:
- '{object}' : Set object name
- '{gplayer}' : Set Gp layer name
- Default template when not passed:
base_path = `//render/{object}`
(for multilayer exr, default to `//render/{object}/{object}_`)
file_slot = `{gplayer}/{gplayer}_`
layer_slot = `{gplayer}`
This commit is contained in:
+16
-62
@@ -2,39 +2,6 @@ import bpy
|
||||
from . import gen_vlayer, fn
|
||||
|
||||
|
||||
def add_layer_to_render(ob, node_scene=None):
|
||||
'''Send GP object to render layer
|
||||
return a tuple with report message'''
|
||||
|
||||
# ob = ob or bpy.context.object
|
||||
layer = ob.data.layers.active
|
||||
if not layer:
|
||||
return ('ERROR', 'No active layer')
|
||||
|
||||
node_scene = fn.get_compo_scene(scene_name=node_scene, create=True)
|
||||
|
||||
ct = 0
|
||||
# send scene ?
|
||||
hidden = 0
|
||||
for l in ob.data.layers:
|
||||
if not l.select:
|
||||
if not l.viewlayer_render:
|
||||
# TODO : need to link, can raise error if object is not linked in Render scene yet
|
||||
l.viewlayer_render = fn.get_view_layer('exclude').name
|
||||
continue
|
||||
|
||||
gen_vlayer.get_set_viewlayer_from_gp(ob, l, node_scene=node_scene)
|
||||
|
||||
if l.hide:
|
||||
hidden += 1
|
||||
ct += 1
|
||||
|
||||
if hidden:
|
||||
return ('WARNING', f'{hidden}/{ct} layers are hidden!')
|
||||
|
||||
else:
|
||||
return ('INFO', f'{ct} layer(s) added')
|
||||
|
||||
class GPEXP_OT_add_layer_to_render(bpy.types.Operator):
|
||||
bl_idname = "gp.add_layer_to_render"
|
||||
bl_label = "Add Gp Layer as render nodes"
|
||||
@@ -49,39 +16,20 @@ class GPEXP_OT_add_layer_to_render(bpy.types.Operator):
|
||||
node_scene : bpy.props.StringProperty(default='',
|
||||
description='Scene where to add nodes, Abort if not found', options={'SKIP_SAVE'})
|
||||
|
||||
# File output templates
|
||||
base_path : bpy.props.StringProperty(name='Base Path', default='', options={'SKIP_SAVE'})
|
||||
file_slot : bpy.props.StringProperty(name='File Slot', default='', options={'SKIP_SAVE'})
|
||||
layer_slot : bpy.props.StringProperty(name='Layer Slot', default='', options={'SKIP_SAVE'})
|
||||
|
||||
def execute(self, context):
|
||||
ret = add_layer_to_render(context.object, node_scene=self.node_scene)
|
||||
ret = gen_vlayer.add_layer_to_render(context.object, node_scene=self.node_scene,
|
||||
base_path=self.base_path, file_slot=self.file_slot, layer_slot=self.layer_slot)
|
||||
if isinstance(ret, tuple):
|
||||
self.report({ret[0]}, ret[1])
|
||||
if ret[0] == 'ERROR':
|
||||
return {'CANCELLED'}
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
def add_object_to_render(mode='ALL', scene='', node_scene=''):
|
||||
context = bpy.context
|
||||
|
||||
if scene:
|
||||
scn = fn.get_render_scene(scene)
|
||||
else:
|
||||
scn = fn.get_render_scene()
|
||||
|
||||
if node_scene:
|
||||
node_scn = fn.get_compo_scene(scene_name=node_scene, create=True)
|
||||
if not node_scn:
|
||||
return ('ERROR', f'/!\ Node Scene "{node_scene}" not found ! Abort "Add object to Render" !')
|
||||
else:
|
||||
# if not passed add in render scene
|
||||
node_scn = scn
|
||||
|
||||
excludes = [] # ['MA', 'IN'] # Get list dynamically
|
||||
if mode == 'SELECTED':
|
||||
gen_vlayer.export_gp_objects([o for o in context.selected_objects if o.type == 'GPENCIL'], exclude_list=excludes, scene=scn, node_scene=node_scn)
|
||||
|
||||
elif mode == 'ALL':
|
||||
gen_vlayer.export_gp_objects([o for o in context.scene.objects if o.type == 'GPENCIL' and not o.hide_get() and fn.is_valid_name(o.name)], exclude_list=excludes, scene=scn, node_scene=node_scn)
|
||||
|
||||
|
||||
## send operator with mode ALL or SELECTED to batch build
|
||||
class GPEXP_OT_add_objects_to_render(bpy.types.Operator):
|
||||
bl_idname = "gp.add_object_to_render"
|
||||
@@ -96,8 +44,8 @@ class GPEXP_OT_add_objects_to_render(bpy.types.Operator):
|
||||
|
||||
mode : bpy.props.EnumProperty(
|
||||
items=(
|
||||
('ALL', 'All', 'All objects', 0),
|
||||
('SELECTED', 'Selected', 'Selected objects', 0),
|
||||
('ALL', 'All', 'All objects'),
|
||||
('SELECTED', 'Selected', 'Selected objects'),
|
||||
),
|
||||
default='ALL', options={'SKIP_SAVE'},
|
||||
description='Choice to send all or only selected objects')
|
||||
@@ -108,8 +56,14 @@ class GPEXP_OT_add_objects_to_render(bpy.types.Operator):
|
||||
node_scene : bpy.props.StringProperty(default='',
|
||||
description='Scene where to add nodes, Abort if not found', options={'SKIP_SAVE'})
|
||||
|
||||
# File output templates
|
||||
base_path : bpy.props.StringProperty(name='Base Path', default='', options={'SKIP_SAVE'})
|
||||
file_slot : bpy.props.StringProperty(name='File Slot', default='', options={'SKIP_SAVE'})
|
||||
layer_slot : bpy.props.StringProperty(name='Layer Slot', default='', options={'SKIP_SAVE'})
|
||||
|
||||
def execute(self, context):
|
||||
ret = add_object_to_render(mode=self.mode, scene=self.scene, node_scene=self.node_scene)
|
||||
ret = gen_vlayer.add_object_to_render(mode=self.mode, scene=self.scene, node_scene=self.node_scene,
|
||||
base_path=self.base_path, file_slot=self.file_slot, layer_slot=self.layer_slot)
|
||||
if isinstance(ret, tuple):
|
||||
self.report({ret[0]}, ret[1])
|
||||
if ret[0] == 'ERROR':
|
||||
|
||||
Reference in New Issue
Block a user