From c176f7ab6a876b60c455c51d43c9deff34897956 Mon Sep 17 00:00:00 2001 From: pullusb Date: Wed, 17 Jan 2024 18:37:00 +0100 Subject: [PATCH] better check for connect selection to output node --- fn.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/fn.py b/fn.py index d147846..8bb602f 100644 --- a/fn.py +++ b/fn.py @@ -1788,6 +1788,15 @@ def clean_mats_duplication(ob, skip_different_materials=True): print(f'{diff_ct} mat skipped >> same name but different color settings!') # return ('INFO', f'{diff_ct} mat skipped >> same name but different color settings!') +def recursive_node_connect_check(l, target_node): + if l.to_node == target_node: + return True + for o in l.to_node.outputs: + for sl in o.links: + if recursive_node_connect_check(sl, target_node): + return True + return False + def connect_to_file_output(node_list, file_out=None): scene = bpy.context.scene nodes = scene.node_tree.nodes @@ -1828,6 +1837,11 @@ def connect_to_file_output(node_list, file_out=None): for o in outs: # if o.name == 'Deprecated': # continue + + ## Skip if already connected to current FO + # 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) slot_name = f'{slot_name}/{slot_name}_' fo.file_slots.new(slot_name) @@ -1856,6 +1870,11 @@ def connect_to_file_output(node_list, file_out=None): fo.base_path = f'//render/{out_base}/cryptos/cryptos_' for o in cryptout: + ## Skip already connected + ## TODO Test recusively to find fo (some have interconnected sockets) + # 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 # slot_name = f'{slot_name}/{slot_name}_' fo.file_slots.new(slot_name)