1
$\begingroup$

I'd like to create a geometry nodes modifier and add an input parameter (in this case a material) using the python API. I am able to create the node group and add a Set Material node with:

bpy.ops.mesh.primitive_monkey_add()
monkey = bpy.context.active_object
modifier = monkey.modifiers.new(type="NODES", name="base_object")

group = bpy.data.node_groups.new("Geometry Nodes", 'GeometryNodeTree')

input_node = group.nodes.new('NodeGroupInput')
output_node = group.nodes.new('NodeGroupOutput')
input_node.location.x = -200 - input_node.width
output_node.location.x = 200

group.interface.new_socket('Geometry', in_out='INPUT', socket_type='NodeSocketGeometry')
group.interface.new_socket('Geometry', in_out='OUTPUT', socket_type='NodeSocketGeometry')

modifier.node_group = group
material_node = modifier.node_group.nodes.new('GeometryNodeSetMaterial')

I would now like to add the connection circled in this image (which I for now have to add via the UI):enter image description here

In 3.x.x I would do this with

modifier.node_group.inputs.new("NodeSocketMaterial", "Point Color")
modifier.node_group.links.new(modifier.node_group.nodes['Group Input'].outputs['Point Color'], material_node.inputs['Material'])

But that does not work in 4.0. Any pointer to how to accomplish this in the current version would be appreciated!

$\endgroup$

1 Answer 1

1
$\begingroup$

You have to use the following line to create the new input instead:

modifier.node_group.interface.new_socket('Point Color', socket_type='NodeSocketMaterial')
$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.