change clean method based on connection order
parent
af2d8e1ad4
commit
26bcb56815
22
fn.py
22
fn.py
|
@ -738,6 +738,12 @@ def clear_disconnected(fo):
|
|||
print(f'Deleting unlinked fileout slot: {inp.name}')
|
||||
fo.inputs.remove(inp)
|
||||
|
||||
def get_pairs(ng, fo):
|
||||
## pairs of connected socket indices (from nodegroup to fileout), ex: [(0, 3), (1, 0), (2, 1), (3, 2)]
|
||||
pairs = [(si, next((i for i, inp in enumerate(fo.inputs) if inp == o.links[0].to_socket), None))
|
||||
for si, o in enumerate(ng.outputs) if o.is_linked and o.links[0].to_node == fo]
|
||||
return pairs
|
||||
|
||||
def reorder_fileout(fo, ng=None):
|
||||
if not ng: # get connected nodegroup
|
||||
for s in fo.inputs:
|
||||
|
@ -747,10 +753,18 @@ def reorder_fileout(fo, ng=None):
|
|||
if not ng:
|
||||
print(f'No nodegroup to refer to filter {fo.name}')
|
||||
return
|
||||
ordered = [o.links[0].to_socket.name for o in ng.outputs if o.is_linked and o.is_linked and o.links[0].to_node == fo]
|
||||
for s_name in ordered:
|
||||
all_outnames = [s.name for s in fo.inputs] # same as [fs.path for fs in fo.file_slots]
|
||||
fo.inputs.move(all_outnames.index(s_name), ordered.index(s_name))
|
||||
|
||||
## Order based on sockets indices
|
||||
# for _ in range(len(ng.outputs)):
|
||||
for _ in range(len(fo.inputs)):
|
||||
# print(f'reorder iteration {_}')
|
||||
pairs = get_pairs(ng, fo) # build index pairs
|
||||
pair = next((p for p in pairs if p[0] is not None and p[1] is not None and p[0] != p[1]), None)
|
||||
if pair is None:
|
||||
## if pair is None, we have iterated over all pairs without index difference (ordered)
|
||||
break
|
||||
print(pair)
|
||||
fo.inputs.move(pair[1], pair[0])
|
||||
|
||||
def reorganise_NG_nodegroup(ng):
|
||||
'''refit node content to avoid overlap'''
|
||||
|
|
Loading…
Reference in New Issue