By default, the Group Output node from Blender Geometry Nodes node tree, has two inputs. The first one, with index 0, is the base input for the geometry. The second input, with index 1, is virtual, used to create new inputs – when we connect a link to it, a new input of a certain type is automatically created on its place.
When creating links between nodes using the Python API, in Blender before version 3.4, this virtual input worked exactly the same as in the visual mode – it was enough to create a connection by specifying the input of the Group Output node with index 1, and the required input was created automatically.
In Blender versions 3.5 and higher, when trying to create a link using the virtual input of the Group Output node, a new input is not automatically generated, and the link is created incorrectly.
To create a link with the Group Output node correctly, we must first create a new input with the following command:
1 |
bpy.context.object.modifiers['GeometryNodes'].node_group.outputs.new(type='NodeSocketGeometry', name='new input') |
In the parameters of the new() method, we need to pass the type of the input being created and its name.
The created input is placed in the Group Output node at index 1 and replaces the virtual input that was previously placed there.
Before creating a new input:
1 2 3 |
bpy.context.object.modifiers['GeometryNodes'].node_group.nodes['Group Output'].inputs[1] # <class 'bpy.types.NodeSocketVirtual'> |
After creating a new input:
1 2 3 |
bpy.context.object.modifiers['GeometryNodes'].node_group.nodes['Group Output'].inputs[1] # <class 'bpy.types.NodeSocketGeometry'> |
Now we can create a link to the created input in a common way. For example:
1 2 3 4 |
bpy.context.object.modifiers['GeometryNodes'].node_group.links.new( bpy.context.object.modifiers['GeometryNodes'].node_group.nodes['Group Input'].outputs[0], bpy.context.object.modifiers['GeometryNodes'].node_group.nodes['Group Output'].inputs[1] ) |