Creating Inputs and Outputs for Node Groups in Blender 3.6 using the Python API

The easiest way to create new inputs and outputs for node groups is to press the plus button in the node group editing mode (tab) on the N-panel on the “Group” section. However, when creating node groups using the Blender Python API, this method is not available.

To create an input or output for a node group, we must remember that inputs and outputs are not created for a current node, but for the entire node tree, which is enclosed in a node group.

We can get a pointer to a node group node tree through its “node_tree” property

For this node tree we need to create inputs and outputs.

To create an input, we can use the “new()” method of the “inputs” node tree property:

In the method parameters, we pass the type of input we are creating (NodeSocketShader) and the name we want to assign to it.

In total, the API provides 4 possible types of inputs and outputs:

  • NodeSocketShader – for shaders
  • NodeSocketVector – for vectors
  • NodeSocketFloat – for floating point numbers
  • NodeSocketColor – for colors

and another one, not available for common selection:

  • NodeSocketInt – for integers

A new output is created in the same way as an input, through the “new()” method, but for the “outputs” property:

The inputs and outputs created in this way are immediately displayed on the Node Group node, and also appear on the Group Input and Group Output nodes.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments