Creating inputs and outputs for node groups in Blender 4.0 using the Python API

In Blender 3.6 and earlier, inputs and outputs for node groups could be created by calling the new() command for the list of inputs or outputs of the node tree. In Blender 4.0, the developers made changes, and the creation of input and output sockets for node trees was moved to the “interface” object.

Inputs and outputs are still created not for the node group but for its node tree, a pointer to which can be obtained through the node group object.

Pointer to the node tree for the currently selected node group:

A pointer to the node tree interface through which we can create inputs and outputs:

To create a new input or output socket, we need to call the new_socket() interface method with the following required parameters:

  • name – new input/output name
  • in_out – input or output socket we create. To create input socket, we need to specify the “INPUT” value, and to make the output socket – “OUTPUT”.
  • socket_type – type of the socket. Still:
    • NodeSocketShader – for shaders
    • NodeSocketVector – for vectors
    • NodeSocketFloat – for float numbers
    • NodeSocketColor – for color

We can also specify additional parameters: “description” – for description, and “parent” for specifying the parent panel of the socket.

Let’s create several input and output sockets.

Input sockets for shaders and vectors:

Output sockets for floating point numbers and colors:

The created input and output sockets appear in the node group:

0 0 votes
Article Rating
Notify of

2 Comment
Oldest Most Voted
Inline Feedbacks
View all comments
Rombout Versluijs
3 months ago

Guess all this breaking of the API is done for Geometry Nodes Tools i guess… Man so much work to do. Also, its very badly documented, how do we even create group inputs and outputs, nowhere in there API changes?!