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 aSet Material node with:

bpy.ops.mesh.primitive_monkey_add()monkey = bpy.context.active_objectmodifier = 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.widthoutput_node.location.x = 200group.interface.new_socket('Geometry', in_out='INPUT', socket_type='NodeSocketGeometry')group.interface.new_socket('Geometry', in_out='OUTPUT', socket_type='NodeSocketGeometry')modifier.node_group = groupmaterial_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!

askedDec 5, 2023 at 21:20
Linus's user avatar
$\endgroup$

1 Answer1

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')
answeredDec 5, 2023 at 21:32
Linus's user avatar
$\endgroup$

You mustlog 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.