Accessing custom attributes created in Geometry Nodes

With Geometry Nodes in Blender is easy to create additional custom attributes for objects and transfer the necessary data to them.  However, there is no direct access to such created attributes.

If we try to read the object’s attribute created in Geometry Nodes by name:

Blender will throw an error:

KeyError: ‘bpy_prop_collection [key]: key “_attribute_name_” not found’

This occurs because Geometry Nodes works like a modifier appended to an object. Modifiers do not affect the object’s source, overlaying changes above.

Like other modifiers, all the results of the Geometry Nodes, including the attributes created in them, can be obtained from the evaluated object.

Let’s add a cube to the scene and assign the Geometry Nodes modifier to it.

Add an Attribute Convert node (shift+a – Attributes – Attribute Convert) to the Geometry Nodes node tree. In the “Attribute” field set the “position” attribute. In the “Result” field type any name for the new attribute, for example, “my_pos”. As a result, Geometry Nodes will create a new attribute with this name and will translate the current position of the object to it.

If we try to access this attribute right now:

Blender will throw the same error informing that the specified attribute is missing for this object.

We can check that the object has no attributes by printing the list of its attributes.

To access the Geometry Nodes attributes, we first need to evaluate the object – get its final evaluated copy.

The “obj” object now contains a fully evaluated copy of the active object with all changes made by modifiers and Geometry Nodes.

The required attribute already exists in the evaluated object:

Now we can get all the data we need from the attribute by its name.

For example, the position of the first vertex of the mesh:

or a list of positions of all mesh vertices:

*.blend file with the code example for my Patreon subscribers

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