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):
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!
1 Answer1
You have to use the following line to create the new input instead:
modifier.node_group.interface.new_socket('Point Color', socket_type='NodeSocketMaterial')You mustlog in to answer this question.
Explore related questions
See similar questions with these tags.