I'd like to add similar Geometry Node Groups to some curves. I try to use a function. A simplified version of the code is this:
import bpy
def purge_orphans():
if bpy.app.version >= (3, 0, 0):
# run this only for Blender versions 3.0 and higher
bpy.ops.outliner.orphans_purge(do_local_ids=True, do_linked_ids=True, do_recursive=True)
else:
# run this only for Blender versions lower than 3.0
# call purge_orphans() recursively until there are no more orphan data blocks to purge
result = bpy.ops.outliner.orphans_purge()
if result.pop() != "CANCELLED":
purge_orphans()
def crea_nodes(ProfileRadius):
bpy.ops.node.new_geometry_nodes_modifier()
node_tree = bpy.data.node_groups["Geometry Nodes"]
out_node = node_tree.nodes["Group Output"]
in_node = node_tree.nodes["Group Input"]
circle_node = node_tree.nodes.new(type="GeometryNodeCurvePrimitiveCircle")
circle_node.inputs["Radius"].default_value =ProfileRadius
to_Mesh_node = node_tree.nodes.new(type="GeometryNodeCurveToMesh")
node_tree.links.new(in_node.outputs['Geometry'], to_Mesh_node.inputs['Curve'])
node_tree.links.new(to_Mesh_node.outputs['Mesh'], out_node.inputs['Geometry'])
node_tree.links.new(circle_node.outputs['Curve'], to_Mesh_node.inputs['Profile Curve'])
if __name__ == "__main__":
purge_orphans()
bpy.ops.curve.primitive_bezier_circle_add(radius=1, location=(0, 0, 0), scale=(1, 1, 1))
crea_nodes(0.2)
bpy.ops.curve.primitive_bezier_circle_add(radius=1, location=(0, 2, 0), scale=(1, 1, 1))
crea_nodes(0.1)
The problem
The two function calls appear to affect the first curve:

While on the second curve I get this:

Please, what is the correct code?

node_tree = bpy.data.node_groups["Geometry Nodes"]each call ofcrea_nodes()modifies the same geometry node. $\endgroup$