Make sure the Geometry Nodes editor area is visible then select the default cube and execute the following script to add a Geometry Nodes modifier to it with id name GeometryNodes
import bpy
ctx_override = bpy.context.copy()
for area in bpy.context.screen.areas:
if area.type == "NODE_EDITOR":
ctx_override['area'] = area
break;
bpy.context.active_object.modifiers.new('GeometryNodes', 'NODES')
It creates a new modifier in the modifiers list as shown below. So far all is fine.
Then execute the following script below to add another Geometry Nodes modifier. This script will also set the newly created modifier named GeometryNodes.001 as the selected or active modifier. But notice that the Input is added to the previously selected modifier. How do I fix that?
import bpy
ctx_override = bpy.context.copy()
for area in bpy.context.screen.areas:
if area.type == "NODE_EDITOR":
ctx_override['area'] = area
break;
bpy.context.active_object.modifiers.new('GeometryNodes.001', 'NODES')
bpy.ops.object.modifier_set_active(modifier='GeometryNodes.001')
bpy.ops.node.tree_socket_add(ctx_override, in_out='IN')
How do I fix that?


node_group.inputs.new("NodeSocketColor", "Color")after the last statement in the first part. $\endgroup$