Skip to main content
1 of 2
Linus
  • 308
  • 1
  • 6

adding modifier input with python API in 4.0

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")

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

Linus
  • 308
  • 1
  • 6