more robust reorder
parent
cc1646081b
commit
d2a19ae9e3
28
fn.py
28
fn.py
|
@ -739,9 +739,31 @@ def clear_disconnected(fo):
|
|||
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 a list of tuple, pairs of connected socket indices
|
||||
from nodegroup to fileout. ex: [(0, 3), (1, 0), (2, 1), (3, 2)]
|
||||
'''
|
||||
|
||||
## Following version works well only if ng and fo have same number of sockets and all are connected.
|
||||
# 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
|
||||
|
||||
## A bit more robust : Do not count the unlinked socket
|
||||
pairs = []
|
||||
str_ct = 0
|
||||
for si, o in enumerate(ng.outputs):
|
||||
if o.is_linked and o.links[0].to_node == fo:
|
||||
|
||||
dest_ct = 0
|
||||
for j, inp in enumerate(fo.inputs):
|
||||
if inp.is_linked and inp.links[0].from_node == ng:
|
||||
if inp == o.links[0].to_socket:
|
||||
pairs.append((str_ct, dest_ct))
|
||||
dest_ct += 1
|
||||
# not incremented on non linked socket
|
||||
|
||||
str_ct += 1
|
||||
## not incremented on non-linked socket
|
||||
return pairs
|
||||
|
||||
def reorder_fileout(fo, ng=None):
|
||||
|
|
Loading…
Reference in New Issue