I have dozens of curves and I want to add a Geometry Node called test
to all these selected objects.
The Geometry Node has already been created and I just want to add it to all curves that are selected.
How do I do this with Python script?
It will apply all the modifiers (and convert the curve to mesh)
import bpy
from bpy import context
node_group = bpy.data.node_groups['Geometry Nodes']
for object in context.selected_objects:
modifier = object.modifiers.new(name='Geometry Nodes', type='NODES')
modifier.node_group = node_group
context.view_layer.objects.active = object
if object.type == 'CURVE':
bpy.ops.object.convert(target='MESH')
elif object.type == 'MESH':
bpy.ops.object.modifier_apply(modifier=modifier.name)
bpy.ops.object.convert(target='MESH')
- but keep in mind it will apply all modifiers (and convert the curve to mesh)
$\endgroup$
Commented
Jul 19, 2023 at 14:48
Warning, Potential AI generated content⚠️
This post is suspected to have been generated with the help of an artificial intelligence, chat bot, or other language model tools without proper attribution.
There is reason to believe this post was not written by a human due to its structure, and grammatical construction, and has been marked by our community.
Current AI chat bots are a language models, that means they are like a parrot, they can mimic human language well, but they are built to write seemingly logical, seemingly factual grammatically valid text, rather than actually be correct, like a human would.
The veracity of the following content cannot be ascertained. See the Concerns regarding AI generated content.
I tried to create with the help of ChatGPT and came up with this script. In my case it works. The only way I managed to do it ON CURVES (not meshes) was by creating the modifier and specifying the node name for a single active object. Then, simply copy the created modifier to the selected inactive objects.
import bpy
# Select the active object
obj = bpy.context.object
# Add a new Geometry Nodes modifier
modifier = obj.modifiers.new(name="Geometry Nodes", type='NODES')
# Get a reference to the Geometry Nodes modification node
node_group = bpy.data.node_groups["test"]
# Set the modification node as the "test" Geometry Nodes node
modifier.node_group = node_group
# Copy the modifier to other objects
bpy.ops.object.make_links_data(type='MODIFIERS')