How to manage the Geometry Nodes attribute by the output of the geometry node tree

When we create a Geometry Nodes node tree by a script, after building the node tree itself, the Geometry Nodes attributes need to be set in order to access these attributes from other areas, for example, from the Shader Node tree.

If the “Python ToolTips” option is enabled in the Blender settings, we can see how the attribute is accessed in the pop-up tooltip on hovering over the attribute field.

As we can see from the hint, the attribute is addressed by the text identifier, as a dynamic property of the Geometry Nodes modifier.

So we can manage the attribute:

But, if we work with an attribute through a script, we do not know its text identifier.

In addition, each time an attribute is created, its identifier will be changed. This can be easily checked by removing the output from the Geometry Nodes tree and re-creating it to recreate an attribute too.

We can get a list of all Geometry Nodes attributes identifiers using the keys() method of the modifier:

To correctly associate the desired output of the Geometry Nodes node tree with each of the attributes, we can do this by indices.

The order of the outputs of the node tree corresponds to the order of identifiers obtained through the keys() method. This can be easily checked by swapping several outputs and comparing them with the list of swapped identifiers.

We can get the index of the desired output in the Geometry Nodes by its name  from the list of the node tree outputs:

With this index, we can get the desired attribute identifier:

To get the attribute identifier, we use a decremented index that we got from the output of the node tree because the first output “Geometry” does not generate an attribute in the modifier.

With the received identifier, we can now access the attribute:

Additionally, to check the correspondence of an attribute to the required output, we can check the occurrence of the output identifier in the attribute identifier:

Solution by: randum, Iyad Ahmed

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comment
Inline Feedbacks
View all comments