Blender 4 using Geometry Nodes in script

Hello, I have been using blender meta balls to generate continuous meshes but have my frustrations with them and have also hit the limit of there viability for my needs.
I am not very familiar with Geometry Node but can use them from the user interface.
However, I need generate a large number of meshes so am trying to write a script that can automate the process. Everything works except for the final link to Group Output node, as the way I call it does not give it any attributes (‘Geometry’ or ‘Mesh’) which it seems to do automatically when I do it manually.

Code to initiate Geometry Node:
import bpy

— clean scene —

bpy.ops.object.select_all(action=‘SELECT’)
bpy.ops.object.delete(use_global=True)

— create base object —

bpy.ops.mesh.primitive_plane_add(size=2)
base = bpy.context.active_object
base.name = “SDF_Base”

— add Geometry Nodes modifier —

mod = base.modifiers.new(“SDF_Union”, type=‘NODES’)
gn = bpy.data.node_groups.new(“SDF_UnionGroup”, ‘GeometryNodeTree’)
mod.node_group = gn
nodes = gn.nodes
links = gn.links
nodes.clear()

— group input/output —

group_out = nodes.new(‘NodeGroupOutput’)
group_out.location = (600,0)
group_out = nodes.new(‘NodeGroupOutput’)
group_out.location = (600,0)

Which result in:

Whereas, when I do it manually it automatically assigns attributes to Group Output node.

Any help would be greatly appreciated.

Thank you,
Charlie

Welcome :tada:

You may have to elaborate this:

…to get a more suited answer. Because if it shows some manipulation of your mesh via the viewer node then this should possible to be connected to the group output…

I’m not sure for what exactly you need a (python) script… one can re-use a made geometry nodes on several object…

Thank you for your reply, I have added more context to my initial question which may help explain my problem.

You only create nodes and place them in the graph, but you dont actually connect (“link”) them at all.
You can, check some examples here:

You might better use the “preformatted text” icon </> to insert python code like so:

# some python code

Also you are allocating two output nodes on the same variable… with no further options… so no info about the mesh output… and so some very “unusable” node will be generated…

Anyway:
You seems to be in the middle of coding something while not fully understanding the API and also not very clearly explaining why you need to generate the geometry nodes via code…

You say it works when doing it manually so why do you have to generate this “every time” ? I guess there is some context data which you want to pass to the final generator… so it is very hard to give any more advise in this situation… You know: first steps first.

  • What do you want to achieve ?
  • How do you do this “manually” ?
  • Why do you need to generate this via python code ?