1
$\begingroup$

I'm writing an addon script which can create a new NodeGroup from a set of texture nodes, or add features to an already created NodeGroup. When adding features which require new Input or Output sockets for the node, the new sockets will be created at the end of the socket list, so at the bottom of the node, but I need them to be at the top.

bpy.ops.node.tree_socket_move(direction='DOWN')

This function could work out but it requires that the Editor be correctly arranged with the right nodegroup selected and open for editing.

One solution could be to remove all sockets and rebuild them in the correct order, but this would require a lot of loops and testing to make sure I have a map of how to reconnect all the disconnected nodes.

Is there a way to rearrange existing NodeGroup Input sockets through script?

$\endgroup$

1 Answer 1

1
$\begingroup$

Yes, we can. The node tree inputs collection has a Move function which takes the current index of the socket to be moved, and the index to which it should be moved.

node_tree.inputs.move(4, 0)

So simple!

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .