My question concerns the use of scripts to generate nodetrees. If I manage to use and link all the nodes offered by Blender on the same tree, I can't find a way of using a custom group.

an example below (the code itself is of no interest; it's just so I can understand how to code nodetrees)


as mentioned before, within a single tree, I have no problem creating nodes, but as soon as I want to create group with the following function (which works since I can add it manually after) :


def create_group():
group = bpy.data.node_groups.new(type="GeometryNodeTree", name="test-group")
new_socket_g = group.interface.new_socket(name='in Socket', in_out='INPUT',socket_type='NodeSocketVector',)
return group


I don't know how to use it with a python command on the main tree since the command g1=node_tree.nodes.new(type="test-group") returns the error message : "RuntimeError: Error: Node type test-group undefined"

So what is the script to load a custom group intside a tree ??

enter image description here

Thank you very much for any help


1 Answer 1


The solution can be found in the following post: how to create node group inside another node group using Python script

simply create an instance between the node you want to create and the tree in which you want to place the node

so you need to define the function (as well explained in the post):

def instanciate_group( nodes, group ) :
Instantiates a group in a tree of nodes

nodes: the nodes of the node tree in which the group is to be instantiated
group: the group to instantiate

Returns :
instance: the group instance created
instance = nodes.new( type = 'GeometryNodeGroup' )
instance.node_tree = group
Returns the instance    

and in the main program


where nametree is the name of the tree in which you want to place the new node


You must log in to answer this question.

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