better check for connect selection to output node

main
pullusb 2024-01-17 18:37:00 +01:00
parent 1a97f75692
commit c176f7ab6a
1 changed files with 19 additions and 0 deletions

19
fn.py
View File

@ -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)