Created
August 5, 2016 11:56
-
-
Save zeffii/bbaaae57115f67a0627e3554b04a1776 to your computer and use it in GitHub Desktop.
getting reduces links from current pre monad selection, exclude peripheral
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pprint | |
import bpy | |
from collections import defaultdict | |
def get_relinks(ng): | |
''' | |
ng = bpy.data.node_groups['NodeTree'] | |
print(get_relinks(ng)) | |
''' | |
nodes = [n for n in ng.nodes if n.select] | |
relinks = dict(inputs=[], outputs=[]) | |
if not nodes: | |
return relinks | |
def gobble_links(link, link_kind, idx, kind): | |
linked_node = getattr(link, link_kind) | |
if not linked_node in nodes: | |
relinks[kind].append(dict(socket_idx=idx, link=link)) | |
def get_links(node, kind='inputs', link_kind='from_node'): | |
for idx, s in enumerate(getattr(node, kind)): | |
if not s.is_linked: | |
continue | |
if kind == 'inputs': | |
link = s.links[0] | |
gobble_links(link, link_kind, idx, kind) | |
else: | |
for link in s.links: | |
gobble_links(link, link_kind, idx, kind) | |
for node in nodes: | |
get_links(node=node, kind='inputs', link_kind='from_node') | |
get_links(node=node, kind='outputs', link_kind='to_node') | |
print(relinks) | |
return relinks | |
ng = bpy.data.node_groups['NodeTree'] | |
links = get_relinks(ng) | |
reduced_links = dict(inputs=defaultdict(list), outputs=defaultdict(list)) | |
for k, v in links.items(): | |
print(k) | |
for item in v: | |
link = item['link'] | |
if k == 'inputs': | |
# print(link.from_socket, link.to_socket, item['socket_idx']) | |
print('({0})[{1}] -> monad in -> ({2})[{3}]'.format( | |
link.from_socket.node.name, link.from_socket.name, | |
link.to_node.name, item['socket_idx'])) | |
reduced_links['inputs'][link.from_socket].append([link.to_node.name, item['socket_idx']]) | |
else: | |
# print(link.from_socket, link.to_socket, item['socket_idx']) | |
print('({0})[{1}] -> monad out -> ({2})[{3}]'.format( | |
link.from_socket.node.name, item['socket_idx'], | |
link.to_node.name, link.to_socket.name)) | |
reduced_links['outputs'][(link.from_socket.name, item['socket_idx'])].append(link.to_socket) | |
pprint.pprint(reduced_links) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment