Nodes: expose ordering of links in multi input socket in Python
This fixes #116096 and is based on #115249 with some changes. This patch contains three changes: * `NodeSocket.links` in the Python API gives the links in the correct order. * `NodeLink.multi_input_sort_id` gives read-only access to an id that's used for sorting. Note that for historical reasons the highest id is the first link. * `NodeLink.swap_multi_input_sort_id(other_link)` provides a safe way to change the order of links connected to a multi-input socket. Co-authored-by: Adrian Bibby Walther <adrianbibbywalther@gmail.com> Pull Request: https://projects.blender.org/blender/blender/pulls/118987
This commit is contained in:
@@ -1258,10 +1258,15 @@ class NodeSocket(StructRNA, metaclass=RNAMetaPropGroup):
|
||||
List of node links from or to this socket.
|
||||
|
||||
.. note:: Takes ``O(len(nodetree.links))`` time."""
|
||||
return tuple(
|
||||
link for link in self.id_data.links
|
||||
if (link.from_socket == self or
|
||||
link.to_socket == self))
|
||||
links = (link for link in self.id_data.links
|
||||
if self in (link.from_socket, link.to_socket))
|
||||
|
||||
if not self.is_output:
|
||||
links = sorted(links,
|
||||
key=lambda link: link.multi_input_sort_id,
|
||||
reverse=True)
|
||||
|
||||
return tuple(links)
|
||||
|
||||
|
||||
class NodeTreeInterfaceItem(StructRNA):
|
||||
|
||||
Reference in New Issue
Block a user