MCPcopy Create free account
hub / github.com/blender/blender / connect_sockets

Function connect_sockets

scripts/modules/bpy_extras/node_utils.py:57–89  ·  view source on GitHub ↗

Connect sockets in a node tree. This is useful because the links created through the normal Python API are invalid when one of the sockets is a virtual socket (grayed out sockets in Group Input and Group Output nodes). It replaces node_tree.links.new(input, output) :param

(input, output)

Source from the content-addressed store, hash-verified

55
56
57def connect_sockets(input, output):
58 """
59 Connect sockets in a node tree.
60
61 This is useful because the links created through the normal Python API are
62 invalid when one of the sockets is a virtual socket (grayed out sockets in
63 Group Input and Group Output nodes).
64
65 It replaces node_tree.links.new(input, output)
66
67 :param input: The input socket.
68 :type input: :class:`bpy.types.NodeSocket`
69 :param output: The output socket.
70 :type output: :class:`bpy.types.NodeSocket`
71 """
72 import bpy
73
74 # Swap sockets if they are not passed in the proper order
75 if input.is_output and not output.is_output:
76 input, output = output, input
77
78 input_node = output.node
79 output_node = input.node
80
81 if input_node.id_data is not output_node.id_data:
82 print("Sockets do not belong to the same node tree")
83 return
84
85 if type(input) == type(output) == bpy.types.NodeSocketVirtual:
86 print("Cannot connect two virtual sockets together")
87 return
88
89 return input_node.id_data.links.new(input, output, handle_dynamic_sockets=True)
90
91
92def find_node_input(node, name):

Callers 15

create_linksMethod · 0.90
invokeMethod · 0.90
autolinkFunction · 0.90
executeMethod · 0.90
executeMethod · 0.90
executeMethod · 0.90
executeMethod · 0.90
executeMethod · 0.90
executeMethod · 0.90
executeMethod · 0.90
executeMethod · 0.90

Calls 3

newMethod · 0.80
printFunction · 0.50
typeFunction · 0.50

Tested by

no test coverage detected