First of all, I want to mention that I'm quite new to programming with Python and Blender.

Now, I wanted to know how I can create (or remove) a new socket in a custom nodetree considering the new "Items Tree" structure in Blender 4.0.

As far as I know, in Blender 4.0 the structure of the nodetree changed (due to the UI enhancement, which is great by the way). Now it appears to have a new "Items Tree" section, and each socket can be either input or output.

I'm trying to do this through bpy.data

In the past, I could create a new input or output with a function (New, or Remove, if I remember correctly) but now I don't know how to do it.

This is something I tried but the console says "AttributeError: bpy_prop_collection: attribute "new_socket" not found"

new_socket = bpy.data.node_groups['My nodegroup'].interface.items_tree.new_socket('NodeSocketFloat', 'My new Float Socket')

The part of the documentation that I'm referring to is this. But really, I never understood very well the Python API documentation.

Any hints on this will be appreciated!


1 Answer 1


I got a solution aided by the help of the Serpens add-on and their community.

In Python the code would look like this:

#### To add a new socket 
new_socket = bpy.data.node_groups['My nodegroup'].interface.new_socket(name='My new Float Socket', in_out='INPUT', socket_type='NodeSocketFloat',)

# in_out is the new attribute to determine if it is either an INPUT or an OUTPUT

#### To remove a socket
bpy.data.node_groups['My nodegroup'].interface.remove(item=bpy.data.node_groups['My nodegroup'].interface.items_tree['My new Float Socket'])

You must log in to answer this question.

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