Having a node, I want to unlink it. My current approach is to clear all links from a desired NodeSocket:


I get a:

AttributeError: 'tuple' object has no attribute 'clear'

I would think that 'links' is a NodeLinks structure, which would have 'clear()' and 'remove()', but apparently no? I also can not simply del my_node.inputs[0].links[0].

One approach I got working is:

for l in my_node.inputs[0].links:

but is there a simpler way? Should one of my previous attempts work?

  • $\begingroup$ There is mistake in: ``` for l in output.links : if l.to_socket == input : node_tree.remove(l) ``` node_tree.remove(l) does'nt work. You need to use node_tree.links.remove(l) $\endgroup$ – Petr Hromják Feb 11 at 18:57

The my_node.inputs[0] is a node Socket type, and the my_node.inputs[0].links is a read only list of links from this socket, so your first attempt won't work, and you have found the correct way, which is deleting the link from node_tree.links as follows:

 # remove only the desired link
 l = my_node.outputs[0].links[0]

To find a link:

output = my_node1.outputs[0]
input  = my_node2.inputs[0]

for l in output.links :
    if l.to_socket == input :

Also you can check for the connected node: if l.to_node == my_node2:

See the DOC page for more details.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.