5
$\begingroup$

If I want to create a new Geometry Node in my python script I use a line like

new_node = nodes.new('GeometryNodeMeshToPoints')

but if I look at the type field of new_node it tells me 'MESH_TO_POINTS' and the name ('Mesh to Points') is no more helpful.

I've looked in the manual and searched on line but I can't find if there's a simple rule for this, or even an exhaustive list of Geometry Node types in Python format. I speculate that the above example is a clue, and the nodes have names like "GeometryNodeNodeTypeConvertedToCamelCase" but I'd like to know for sure.

Can anyone point me at a definite list or rule?

Edit: Gorgious has pointed out in a comment the list of GeometryNode derived node names; and Code3R has provided a quick script to generate that list; but that made me realize that what I really want isn't the list of types derived from GeometryNode but rather the list of types that are legal in a GN tree.

$\endgroup$
2
  • 2
    $\begingroup$ One workaround is to CTRL-F on this page and feel lucky docs.blender.org/api/current/… They do seem to have a hierarchical logic in type naming but not one you can 100% derive from what you get with type and name. But there should be a way to get the type from inside the environment ? $\endgroup$
    – Gorgious
    Commented Jan 11, 2022 at 20:43
  • $\begingroup$ There should be, but I think GN shipped before it was polished to that point. Usually there's a list that's pointed to by the documentation for the function and often specified in the function documentation; but I've had no luck finding it. $\endgroup$ Commented Jan 11, 2022 at 20:45

3 Answers 3

6
$\begingroup$

A basic dir() call on bpy.types should do:

import bpy

filter = []
for t in dir(bpy.types):
    if t.startswith("GeometryNode"):
        if "MeshTo" in t:
            filter.append(t)
            
print(filter)
#['GeometryNodeLegacyMeshToCurve', 'GeometryNodeMeshToCurve', 'GeometryNodeMeshToPoints']
$\endgroup$
0
3
$\begingroup$

Edit: This method is not 100% accurate because some Geometry nodes have not yet had their classes evaluated when GeometryNode subclasses are enumerated. The workaround is to explicitly import those classes.

Thanks to a commenter this list is now closer to complete. But also, it turns out that there are many classes not yet instantiated. The solution seems to be creating a Geometry Node modifier by hand that has one instance of every group. So I guess the actual answer is "No, there's no way to get the list, but here's how to get part of it."

Rather than relying on name similarity here's how to derive the complete list of names for node types that are valid in a Geometry Node Tree, provided that all such node types derive from either GeometryNode or ShaderNode:

import bpy

# This script assumes that
# 1) All valid Geometry Nodes are derived from bpy.types.GeometryNode
# 2) All valid Shader Nodes are derived from bpy.types.ShaderNode
# 3) Some but not all Shader Nodes are valid in a Geometry Node tree.
# 4) Attempting to use an invalid Shader Node generates a RuntimeError exception.

# There is a bug.  These two types don't show up as subtypes of geometry nodes
# unless they've been explicitly imported.  (Thanks Chris)
from bpy.types import GeometryNodeSubdivideMesh
from bpy.types import GeometryNodeTransform

# Create an object (any will do) and add GeometryNodes modifier to it.
bpy.ops.mesh.primitive_cube_add()
bpy.ops.object.modifier_add(type='NODES')

# Find the geometry node tree
curve = bpy.context.active_object
node_group = curve.modifiers['GeometryNodes'].node_group
nodes = node_group.nodes

# Find out which shader node classes are supported
Crossover_subClasses = [cls.__name__ for cls in  bpy.types.GeometryNode.__subclasses__()]
Shader_Node_subClasses = [cls.__name__ for cls in  bpy.types.ShaderNode.__subclasses__()]
Crossover_subClasses = Geometry_Node_subClasses

for node_type in Shader_Node_subClasses:
    try:
        nodes.new(node_type)
        Crossover_subClasses.append(node_type)
    except RuntimeError:
        print(f"Shader Node RuntimeError: {node_type}")

# Print the list
Crossover_subClasses.sort()
for node_type in Crossover_subClasses:
    print(node_type)

The (now more accurate) list follows, in sorted order

GeometryNodeAttributeRemove
GeometryNodeAttributeStatistic
GeometryNodeAttributeTransfer
GeometryNodeCaptureAttribute
GeometryNodeCurvePrimitiveBezierSegment
GeometryNodeCurvePrimitiveCircle
GeometryNodeCurvePrimitiveLine
GeometryNodeCurvePrimitiveQuadrilateral
GeometryNodeCurveQuadraticBezier
GeometryNodeCurveSpiral
GeometryNodeCurveStar
GeometryNodeImageTexture
GeometryNodeInstanceOnPoints
GeometryNodeInstancesToPoints
GeometryNodeLegacyAttributeClamp
GeometryNodeLegacyAttributeColorRamp
GeometryNodeLegacyAttributeCombineXYZ
GeometryNodeLegacyAttributeCompare
GeometryNodeLegacyAttributeConvert
GeometryNodeLegacyAttributeCurveMap
GeometryNodeLegacyAttributeFill
GeometryNodeLegacyAttributeMapRange
GeometryNodeLegacyAttributeMath
GeometryNodeLegacyAttributeMix
GeometryNodeLegacyAttributeProximity
GeometryNodeLegacyAttributeRandomize
GeometryNodeLegacyAttributeSampleTexture
GeometryNodeLegacyAttributeSeparateXYZ
GeometryNodeLegacyAttributeTransfer
GeometryNodeLegacyAttributeVectorMath
GeometryNodeLegacyAttributeVectorRotate
GeometryNodeLegacyPointsToVolume
GeometryNodeLegacyVolumeToMesh
GeometryNodeMeshCircle
GeometryNodeMeshCone
GeometryNodeMeshCube
GeometryNodeMeshCylinder
GeometryNodeMeshGrid
GeometryNodeMeshIcoSphere
GeometryNodeMeshLine
GeometryNodeMeshUVSphere
GeometryNodeRealizeInstances
GeometryNodeRotateInstances
GeometryNodeScaleInstances
GeometryNodeStringJoin
GeometryNodeStringToCurves
GeometryNodeSubdivideMesh
GeometryNodeSwitch
GeometryNodeTransform
GeometryNodeTranslateInstances
GeometryNodeViewer
GeometryNodeVolumeToMesh
ShaderNodeClamp
ShaderNodeCombineRGB
ShaderNodeCombineXYZ
ShaderNodeFloatCurve
ShaderNodeMapRange
ShaderNodeMath
ShaderNodeMixRGB
ShaderNodeRGBCurve
ShaderNodeSeparateRGB
ShaderNodeSeparateXYZ
ShaderNodeTexBrick
ShaderNodeTexChecker
ShaderNodeTexGradient
ShaderNodeTexMagic
ShaderNodeTexMusgrave
ShaderNodeTexNoise
ShaderNodeTexVoronoi
ShaderNodeTexWave
ShaderNodeTexWhiteNoise
ShaderNodeValToRGB
ShaderNodeValue
ShaderNodeVectorCurve
ShaderNodeVectorMath
ShaderNodeVectorRotate

There are many Shader nodes that will trip the RuntimeError, even in 3.0.0. If you run this version of the code it will print their names.

$\endgroup$
7
  • 1
    $\begingroup$ and where are the math nodes? shouldn't they be there too? and i am sure more are missing ... $\endgroup$
    – Chris
    Commented Jan 12, 2022 at 5:20
  • $\begingroup$ Didn’t know that the geometry math nodes are shader nodes. Isn’t that obvious to me….so maybe they should be renamed by Blender developers… $\endgroup$
    – Chris
    Commented Jan 12, 2022 at 14:48
  • $\begingroup$ Ok, but just as example…where is the mesh subdivide node? $\endgroup$
    – Chris
    Commented Jan 12, 2022 at 14:57
  • $\begingroup$ Or transform node? $\endgroup$
    – Chris
    Commented Jan 12, 2022 at 14:59
  • $\begingroup$ curve set spline type, set spline resolution... $\endgroup$
    – Chris
    Commented Jan 12, 2022 at 18:40
0
$\begingroup$

Slightly related, I recommend also looking into Carson Katri script at Github that helps dealing with Geometry Nodes scripting: https://github.com/carson-katri/geometry-script

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .