From fe3f0ae86983ce03a8e8eb8164cfa8361bf942a3 Mon Sep 17 00:00:00 2001 From: pullusb Date: Mon, 24 Jun 2024 16:10:44 +0200 Subject: [PATCH] rename fields in selection to fileoutput 1.8.0 - added: Allow to rename output on the fly using `connect selection to output` --- CHANGELOG.md | 4 ++++ OP_manage_outputs.py | 19 +++++++++++++------ __init__.py | 2 +- fn.py | 16 ++++++++++++---- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5b1fc8..def6b62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ Activate / deactivate layer opacity according to prefix Activate / deactivate all masks using MA layers --> +1.8.0 + +- added: Allow to rename output on the fly using `connect selection to output` + 1.7.4 - removed: Restriction to use default scene "Scene" diff --git a/OP_manage_outputs.py b/OP_manage_outputs.py index 8d30da6..0d797b5 100644 --- a/OP_manage_outputs.py +++ b/OP_manage_outputs.py @@ -241,6 +241,7 @@ class GPEXP_OT_reset_render_settings(bpy.types.Operator): class GPEXP_PG_selectable_prop(bpy.types.PropertyGroup): node_name: bpy.props.StringProperty(name="Object Name") name: bpy.props.StringProperty(name="Name or Path") + socket_name: bpy.props.StringProperty(name="Source socket Name") # Source socket name as reference select: bpy.props.BoolProperty(name="Selected", default=True) is_linked: bpy.props.BoolProperty(name="Linked", default=False) # is_valid: bpy.props.BoolProperty(name="Valid", default=True) @@ -321,7 +322,8 @@ class GPEXP_OT_connect_selected_to_file_out(bpy.types.Operator): continue item = self.socket_collection.add() item.node_name = n.name - item.name = o.name + item.socket_name = item.name = o.name + ## TODO: rename item.name according to tamplate pairs in preferences (to add later) if o.is_linked: item.is_linked = True item.select = False @@ -350,7 +352,7 @@ class GPEXP_OT_connect_selected_to_file_out(bpy.types.Operator): current_node_name = item.node_name col.separator() col.label(text=item.node_name, icon='NODE_SEL') - + row = col.row() if item.is_linked: row.label(text='', icon='LINKED') # NODETREE @@ -358,27 +360,32 @@ class GPEXP_OT_connect_selected_to_file_out(bpy.types.Operator): row.label(text='', icon='BLANK1') row.prop(item, 'select', text='') - display_name = item.name + display_name = item.socket_name if 'crypto' in display_name.lower(): display_name = f'{display_name} (-> separate 32bit output node)' row.label(text=display_name) + row.label(text='', icon='RIGHTARROW') + row.prop(item, 'name', text='') def execute(self, context): # Build exclude dict from selection excludes = {} + remap_names = {} if len(self.socket_collection): for item in self.socket_collection: if not item.select: # All deselected goes to exclude with {node_name: [socket1, ...]} excludes.setdefault(item.node_name, []).append(item.name) - + elif item.socket_name != item.name: + remap_names[item.socket_name] = item.name + ## Handle default file format file_ext = self.file_format if self.file_format == 'NONE': env_file_format = os.environ.get('FILE_FORMAT') file_ext = env_file_format if env_file_format else 'OPEN_EXR_MULTILAYER' - + file_format = { 'file_format' : file_ext, 'exr_codec' : self.exr_codec, @@ -394,7 +401,7 @@ class GPEXP_OT_connect_selected_to_file_out(bpy.types.Operator): # fn.connect_to_file_output(selected, outfile) for n in selected: - fn.connect_to_file_output(n, outfile, base_path=self.base_path, excludes=excludes, file_format=file_format) + fn.connect_to_file_output(n, outfile, base_path=self.base_path, excludes=excludes, remap_names=remap_names, file_format=file_format) return {"FINISHED"} classes=( diff --git a/__init__.py b/__init__.py index e8d07ff..783cc63 100644 --- a/__init__.py +++ b/__init__.py @@ -2,7 +2,7 @@ bl_info = { "name": "GP Render", "description": "Organise export of gp layers through compositor output", "author": "Samuel Bernou", - "version": (1, 7, 4), + "version": (1, 8, 0), "blender": (3, 0, 0), "location": "View3D", "warning": "", diff --git a/fn.py b/fn.py index 7c39644..59d43ef 100644 --- a/fn.py +++ b/fn.py @@ -1871,7 +1871,7 @@ def recursive_node_connect_check(l, target_node): return True return False -def connect_to_file_output(node_list, file_out=None, base_path='', excludes=None, file_format=None): +def connect_to_file_output(node_list, file_out=None, base_path='', excludes=None, remap_names=None, file_format=None): """Connect selected nodes output to file output(s) if a file output is selected, add intputs on it @@ -1952,7 +1952,12 @@ def connect_to_file_output(node_list, file_out=None, base_path='', excludes=None for o in outs: if next((l for l in o.links if recursive_node_connect_check(l, fo)), None): continue - slot_name = bpy.path.clean_name(o.name) + + if remap_names and (custom_name := remap_names.get(o.name)): + slot_name = bpy.path.clean_name(custom_name) # clean name ? + else: + slot_name = bpy.path.clean_name(o.name) + # if fo.format.file_format == 'OPEN_EXR_MULTILAYER': # slot_name = slot_name # else: @@ -2010,8 +2015,11 @@ def connect_to_file_output(node_list, file_out=None, base_path='', excludes=None # if next((l for l in o.links if l.to_node == fo), None): if next((l for l in o.links if recursive_node_connect_check(l, fo)), None): continue - - slot_name = bpy.path.clean_name(o.name) # directly use name in multi layer exr + + if remap_names and (custom_name := remap_names.get(o.name)): + slot_name = bpy.path.clean_name(custom_name) # clean name ? + else: + slot_name = bpy.path.clean_name(o.name) # directly use name in multi layer exr # if fo.format.file_format == 'OPEN_EXR_MULTILAYER': # slot_name = slot_name