GeometrySet

Accessing Evaluated Geometry

import bpy

# The GeometrySet can only be retrieved from an evaluated object. So one always
# needs a depsgraph that has evaluated the object.
depsgraph = bpy.context.view_layer.depsgraph
ob = bpy.context.active_object
ob_eval = depsgraph.id_eval_get(ob)

# Get the final evaluated geometry of an object.
geometry = ob_eval.evaluated_geometry()

# Print basic information like the number of elements.
print(geometry)

# A geometry set may have a name. It can be set with the Set Geometry Name node.
print(geometry.name)

# Access "realized" geometry components.
print(geometry.mesh)
print(geometry.pointcloud)
print(geometry.curves)
print(geometry.volume)
print(geometry.grease_pencil)

# Access the mesh without final subdivision applied.
print(geometry.mesh_base)

# Accessing instances is a bit more tricky, because there is no specific
# mechanism to expose instances. Instead, two accessors are provided which
# are easy to keep working in the future even if we get a proper Instances type.

# This is a pointcloud that provides access to all the instance attributes.
# There is a point per instances. May return None if there is no instances data.
instances_pointcloud = geometry.instances_pointcloud()

if instances_pointcloud is not None:
    # This is a list containing the data that is instanced. The list may contain
    # None, objects, collections or other GeometrySets. If the geometry does not
    # have instances, the list is empty.
    references = geometry.instance_references()

    # Besides normal generic attributes, there are also two important
    # instance-specific attributes. "instance_transform" is a 4x4 matrix attribute
    # containing the transforms of each instance.
    instance_transforms = instances_pointcloud.attributes["instance_transform"]

    # ".reference_index" contains indices into the `references` list above and
    # determines what geometry each instance uses.
    reference_indices = instances_pointcloud.attributes[".reference_index"]
class bpy.types.GeometrySet

Stores potentially multiple geometry components of different types. For example, it might contain a mesh, curves and nested instances.

instance_references()

This returns a list of geometries that is indexed by the .reference_index attribute of the pointcloud returned by bpy.types.GeometrySet.instances_pointcloud(). It may contain other geometry sets, objects, collections and None values.

Return type:

list[None | bpy.types.Object | bpy.types.Collection | bpy.types.GeometrySet]

instances_pointcloud()

Get a pointcloud that encodes information about the instances of the geometry. The returned pointcloud should not be modified. There is a point per instance and per-instance data is stored in point attributes. The local transforms are stored in the instance_transform attribute. The data instanced by each point is referenced by the .reference_index attribute, indexing into the list returned by bpy.types.GeometrySet.instance_references().

Return type:

bpy.types.PointCloud

curves

The curves data-block in the geometry set.

Type:

bpy.types.Curves

grease_pencil

The Grease Pencil data-block in the geometry set.

Type:

bpy.types.GreasePencilv3

mesh

The mesh data-block in the geometry set.

Type:

bpy.types.Mesh

mesh_base

The mesh data-block in the geometry set without final subdivision.

Type:

bpy.types.Mesh

name

The name of the geometry set.

Type:

str

pointcloud

The point cloud data-block in the geometry set.

Type:

bpy.types.PointCloud

volume

The volume data-block in the geometry set.

Type:

bpy.types.Volume

static from_evaluated_object(evaluated_object)

Create a geometry set from the evaluated geometry of an evaluated object. Typically, it’s more convenient to use bpy.types.Object.evaluated_geometry().

Parameters:

evaluated_object (bpy.types.Object) – The evaluated object to create a geometry set from.