Creating Repeat Zone Nodes using the Blender Python API

Starting with Blender 4.0, a special group of nodes appeared in Blender Geometry Nodes, designed to cyclically execute a section of a node tree a specified number of times. This group of nodes is called “Repeat Zone”.

For common user, the Repeat Zone group is added to the Geometry Nodes tree in the usual way: shift + a – Utilities – Repeat Zone. After performing this action, two nodes are added to the node tree at once, already forming the desired zone.

To add this group of nodes through the Blender Python API, we need to perform a little more steps than when adding regular nodes.

First, we need to get a pointer to the Geometry Nodes tree.

Having a pointer to the node tree, we can start adding nodes.

Firstly, we need to add a “Repeat Output” node. The order of adding is important – when processing subsequent nodes, we will refer to those already added, so they must already exist in the node tree.

We add the “Repeat Output” node in the usual way, like any other node, by its type.

Having the “Repeat Output” node, we can immediately add, if necessary, additional inputs and outputs. Additional inputs and outputs are created through the “repeat_items” properties collection, a pointer to which we will receive through the Repeat Output node.

For example, we can add a floating point number field – with type = “FLOAT” and the name = “float_field”.

Now we can add a second Repeat Zone node to the node tree – “Repeat Input”:

At present, both added nodes are not connected in a group, and therefore they do not form the single Repeat Zone that we need.

To connect both nodes into a single zone, we need to execute the pair_with_output() function for the Repeat Input node, passing a pointer to the Repeat Output node as a parameter.

We have already created the Repeat Output node, so we can call the function:

Now both nodes are connected into the single zone.

Please note that for the Repeat Input node, there is no need to create additional inputs and outputs again. After connecting nodes to the zone, they were created automatically.

The last thing left for us is to create a link for the “Geometry” inputs and outputs for both nodes:

Now our new Repeat Zone is ready for use.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments