2021-09-08 18:29:10 +02:00
|
|
|
import bpy
|
2021-09-22 12:06:40 +02:00
|
|
|
import re
|
|
|
|
from . import fn
|
2021-09-08 18:29:10 +02:00
|
|
|
|
|
|
|
class GPEXP_OT_mute_toggle_output_nodes(bpy.types.Operator):
|
|
|
|
bl_idname = "gp.mute_toggle_output_nodes"
|
|
|
|
bl_label = "Mute Toggle output nodes"
|
|
|
|
bl_description = "Mute / Unmute all output nodes"
|
|
|
|
bl_options = {"REGISTER"}
|
|
|
|
|
|
|
|
mute : bpy.props.BoolProperty(default=True, options={'SKIP_SAVE'})
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
# scene = bpy.data.scenes.get('Render')
|
|
|
|
ct = 0
|
|
|
|
for n in context.scene.node_tree.nodes:
|
|
|
|
if n.type != 'OUTPUT_FILE':
|
|
|
|
continue
|
|
|
|
n.mute = self.mute
|
|
|
|
ct += 1
|
|
|
|
|
|
|
|
state = 'muted' if self.mute else 'unmuted'
|
|
|
|
self.report({"INFO"}, f'{ct} nodes {state}')
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
2021-09-22 12:06:40 +02:00
|
|
|
class GPEXP_OT_number_outputs(bpy.types.Operator):
|
|
|
|
bl_idname = "gp.number_outputs"
|
|
|
|
bl_label = "Number Outputs"
|
|
|
|
bl_description = "(Re)Number the outputs to have ordered file by name in export directories\nCtrl+Clic : Delete numbering"
|
|
|
|
bl_options = {"REGISTER"}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
return True
|
|
|
|
|
|
|
|
mode : bpy.props.StringProperty(default='SELECTED', options={'SKIP_SAVE'})
|
|
|
|
# ctrl : bpy.props.StringProperty(default=False, options={'SKIP_SAVE'}) # no need
|
|
|
|
|
|
|
|
def invoke(self, context, event):
|
|
|
|
self.ctrl = event.ctrl
|
|
|
|
return self.execute(context)
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
render = bpy.data.scenes.get('Render')
|
|
|
|
if not render:
|
|
|
|
print('SKIP, no Render scene')
|
|
|
|
return {"CANCELLED"}
|
|
|
|
|
|
|
|
ct = 0
|
|
|
|
nodes = render.node_tree.nodes
|
|
|
|
for fo in nodes:
|
|
|
|
if fo.type != 'OUTPUT_FILE':
|
|
|
|
continue
|
|
|
|
if self.mode == 'SELECTED' and not fo.select:
|
|
|
|
continue
|
|
|
|
# print(f'numbering {fo.name}')
|
|
|
|
ct += 1
|
|
|
|
if self.ctrl:
|
|
|
|
fn.delete_numbering(fo)
|
|
|
|
else:
|
|
|
|
fn.renumber_keep_existing(fo)
|
|
|
|
# fn.renumber(fo)
|
|
|
|
|
|
|
|
txt = 'de-numbered' if self.ctrl else 're-numbered'
|
|
|
|
if ct:
|
|
|
|
self.report({'INFO'}, f'{ct} output nodes {txt}')
|
|
|
|
else:
|
|
|
|
self.report({'ERROR'}, f'No output nodes {txt}')
|
|
|
|
|
|
|
|
return {"FINISHED"}
|
2021-09-21 18:23:25 +02:00
|
|
|
|
|
|
|
class GPEXP_OT_set_output_node_format(bpy.types.Operator):
|
|
|
|
bl_idname = "gp.set_output_node_format"
|
|
|
|
bl_label = "Set output format from active"
|
|
|
|
bl_description = "Change all selected output node to match active output node format"
|
|
|
|
bl_options = {"REGISTER"}
|
|
|
|
|
|
|
|
mute : bpy.props.BoolProperty(default=True, options={'SKIP_SAVE'})
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
# scene = bpy.data.scenes.get('Render')
|
|
|
|
nodes = context.scene.node_tree.nodes
|
|
|
|
if not nodes.active or nodes.active.type != 'OUTPUT_FILE':
|
|
|
|
self.report({"ERROR"}, f'Active node should be an output file to use as reference for output format')
|
|
|
|
return {"CANCELLED"}
|
|
|
|
|
|
|
|
ref = nodes.active
|
2021-09-23 15:13:30 +02:00
|
|
|
|
|
|
|
# file_format = ref.format.file_format
|
|
|
|
# color_mode = ref.format.color_mode
|
|
|
|
# color_depth = ref.format.color_depth
|
|
|
|
# compression = ref.format.compression
|
2021-09-21 18:23:25 +02:00
|
|
|
|
|
|
|
ct = 0
|
2021-09-22 12:06:40 +02:00
|
|
|
for n in nodes:
|
|
|
|
if n.type != 'OUTPUT_FILE' or n == ref or not n.select:
|
2021-09-21 18:23:25 +02:00
|
|
|
continue
|
|
|
|
|
2021-09-23 15:13:30 +02:00
|
|
|
for attr in dir(ref.format):
|
2021-09-23 15:18:06 +02:00
|
|
|
if attr.startswith('__') or attr in {'rna_type','bl_rna', 'view_settings', 'display_settings','stereo_3d_format'}: # views_format
|
2021-09-23 15:13:30 +02:00
|
|
|
continue
|
|
|
|
try:
|
|
|
|
setattr(n.format, attr, getattr(ref.format, attr))
|
|
|
|
except Exception as e:
|
|
|
|
print(f"can't set attribute : {attr}")
|
|
|
|
|
|
|
|
# n.format.file_format = file_format
|
|
|
|
# n.format.color_mode = color_mode
|
|
|
|
# n.format.color_depth = color_depth
|
|
|
|
# n.format.compression = compression
|
2021-09-21 18:23:25 +02:00
|
|
|
|
|
|
|
ct += 1
|
|
|
|
|
|
|
|
# state = 'muted' if self.mute else 'unmuted'
|
|
|
|
self.report({"INFO"}, f'{ct} output format copied from {ref.name}')
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
2021-09-23 15:13:30 +02:00
|
|
|
|
2021-09-22 12:06:40 +02:00
|
|
|
def out_norm(x):
|
|
|
|
a = x.group(1) if x.group(1) else ''
|
|
|
|
b = x.group(2) if x.group(2) else ''
|
|
|
|
c = x.group(3) if x.group(3) else ''
|
|
|
|
d = x.group(4) if x.group(4) else ''
|
|
|
|
e = x.group(5) if x.group(5) else ''
|
|
|
|
return f'{a}{b}{fn.normalize(c)}{d}{e}'
|
|
|
|
|
2021-09-23 15:13:30 +02:00
|
|
|
|
2021-09-22 12:06:40 +02:00
|
|
|
## does not match the right thing yet
|
|
|
|
class GPEXP_OT_normalize_outnames(bpy.types.Operator):
|
|
|
|
bl_idname = "gp.normalize_outnames"
|
|
|
|
bl_label = "Normalize Output names"
|
|
|
|
bl_description = "Normalize output names with lowercase and replace dash to underscore"
|
|
|
|
bl_options = {"REGISTER"}
|
|
|
|
|
|
|
|
mute : bpy.props.BoolProperty(default=True, options={'SKIP_SAVE'})
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
# scene = bpy.data.scenes.get('Render')
|
|
|
|
nodes = context.scene.node_tree.nodes
|
|
|
|
# if not nodes.active or nodes.active.type != 'OUTPUT_FILE':
|
|
|
|
# self.report({"ERROR"}, f'')
|
|
|
|
# return {"CANCELLED"}
|
|
|
|
|
|
|
|
reslash = re.compile('\\/')
|
|
|
|
ct = 0
|
|
|
|
for n in nodes:
|
|
|
|
if n.type != 'OUTPUT_FILE' or not n.select:
|
|
|
|
continue
|
|
|
|
# Normalize last part of the file out names
|
|
|
|
base_path_l = reslash.split(n.base_path)
|
|
|
|
base_path_l[-1] = fn.normalize(base_path_l[-1])
|
|
|
|
n.base_path = '/'.join(base_path_l)
|
|
|
|
|
|
|
|
for fs in n.file_slots:
|
|
|
|
fp = fs.path
|
|
|
|
fp_l = reslash.split(fp)
|
|
|
|
for i, part in enumerate(fp_l):
|
|
|
|
fp_l[1] = re.sub(r'(^\d{3}_)?([A-Z]{2}_)?(.*?)(_[A-Z]{2})?(_)?', out_norm, part)
|
|
|
|
|
|
|
|
fs.path = '/'.join(fp_l)
|
|
|
|
|
|
|
|
ct += 1
|
|
|
|
|
|
|
|
# state = 'muted' if self.mute else 'unmuted'
|
|
|
|
self.report({"INFO"}, f'{ct} output nodes normalized')
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
2021-09-23 19:14:48 +02:00
|
|
|
class GPEXP_OT_enable_all_viewlayers(bpy.types.Operator):
|
|
|
|
bl_idname = "gp.enable_all_viewlayers"
|
|
|
|
bl_label = "Enable All Viewlayers"
|
|
|
|
bl_description = "Enable all View layers except those named 'exclude' 'View Layer'"
|
|
|
|
bl_options = {"REGISTER"}
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-10-08 15:29:56 +02:00
|
|
|
# scn = bpy.data.scenes.get('Render')
|
|
|
|
# if not scn:
|
|
|
|
# print('SKIP, no Render scene')
|
|
|
|
# return {"CANCELLED"}
|
|
|
|
scn = context.scene
|
2021-09-23 19:14:48 +02:00
|
|
|
|
2021-10-08 15:29:56 +02:00
|
|
|
vl_list = [vl for vl in scn.view_layers if not vl.use and vl.name not in {'View Layer', 'exclude'}]
|
2021-09-23 19:14:48 +02:00
|
|
|
for v in vl_list:
|
|
|
|
v.use = True
|
|
|
|
|
|
|
|
self.report({"INFO"}, f'{len(vl_list)} ViewLayers Reactivated')
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
class GPEXP_OT_activate_only_selected_layers(bpy.types.Operator):
|
|
|
|
bl_idname = "gp.activate_only_selected_layers"
|
|
|
|
bl_label = "Activate Only Selected Layers"
|
|
|
|
bl_description = "Activate only selected node view layer , excluding all others"
|
|
|
|
bl_options = {"REGISTER"}
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-10-08 15:29:56 +02:00
|
|
|
# scn = bpy.data.scenes.get('Render')
|
|
|
|
# if not scn:
|
|
|
|
# print('SKIP, no Render scene')
|
|
|
|
# return {"CANCELLED"}
|
|
|
|
scn = context.scene
|
|
|
|
|
|
|
|
nodes = scn.node_tree.nodes
|
2021-09-23 19:14:48 +02:00
|
|
|
|
|
|
|
rlayers_nodes = [n for n in nodes if n.select and n.type == 'R_LAYERS']
|
2021-10-08 15:29:56 +02:00
|
|
|
vls = [scn.view_layers.get(n.layer) for n in rlayers_nodes if scn.view_layers.get(n.layer)]
|
|
|
|
for v in scn.view_layers:
|
2021-09-23 19:14:48 +02:00
|
|
|
v.use = v in vls
|
|
|
|
|
2021-10-08 15:29:56 +02:00
|
|
|
self.report({"INFO"}, f'Now only {len(vls)} viewlayer active (/{len(scn.view_layers)})')
|
2021-09-23 19:14:48 +02:00
|
|
|
return {"FINISHED"}
|
|
|
|
|
2021-09-22 12:06:40 +02:00
|
|
|
|
2021-09-08 18:29:10 +02:00
|
|
|
classes=(
|
|
|
|
GPEXP_OT_mute_toggle_output_nodes,
|
2021-09-21 18:23:25 +02:00
|
|
|
GPEXP_OT_set_output_node_format,
|
2021-09-22 12:06:40 +02:00
|
|
|
GPEXP_OT_number_outputs,
|
2021-09-23 19:14:48 +02:00
|
|
|
GPEXP_OT_enable_all_viewlayers,
|
|
|
|
GPEXP_OT_activate_only_selected_layers,
|
2021-09-22 12:06:40 +02:00
|
|
|
# GPEXP_OT_normalize_outnames,
|
2021-09-08 18:29:10 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def register():
|
|
|
|
for cls in classes:
|
|
|
|
bpy.utils.register_class(cls)
|
|
|
|
|
|
|
|
def unregister():
|
|
|
|
for cls in reversed(classes):
|
|
|
|
bpy.utils.unregister_class(cls)
|