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)
| 55 | |
| 56 | |
| 57 | def 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 | |
| 92 | def find_node_input(node, name): |
no test coverage detected