BlenderObject

BlenderObject(self, obj=None)

A convenience class for working with Blender objects

Attributes

Name Description
attributes Get the attributes of the Blender object.
edges Get the edges of the Blender object.
name Get the name of the Blender object.
object Get the Blender object.
position Get the position of the vertices of the Blender object.
selected Get the selected vertices of the Blender object.
vertices Get the vertices of the Blender object.

Methods

Name Description
centroid Return the centroid, potentially weighted by an attribute.
evaluate Return a version of the object with all modifiers applied.
list_attributes Returns a list of attribute names for the object.
named_attribute Retrieve a named attribute from the object.
new_from_pydata Create a new Blender object from vertex, edge and face data.
remove_named_attribute Remove a named attribute from the object.
selected_positions Get the positions of the selected vertices, optionally filtered by a mask.
set_boolean Store a boolean attribute on the Blender object.
store_named_attribute Store a named attribute on the Blender object.
transform_origin Transform the origin of the Blender object.
transform_points Transform the points of the Blender object.

centroid

BlenderObject.centroid(weight=None)

Return the centroid, potentially weighted by an attribute.

If the weight is a string, an attribute of that name is attempted to be accessed on the mesh. If an array is given that array is used as weights. A value of None returns just the centroid calculation.

Parameters

Name Type Description Default
weight str | np.ndarray | None The weights to apply to the positions when calculating the centroid. Defaults to None. None

Returns

Name Type Description
np.ndarray A 3-component vector with the calculated centroid.

evaluate

BlenderObject.evaluate()

Return a version of the object with all modifiers applied.

Returns

Name Type Description
Object A new Object that isn’t yet registered with the database

list_attributes

BlenderObject.list_attributes(evaluate=False, drop_hidden=False)

Returns a list of attribute names for the object.

Parameters

Name Type Description Default
evaluate bool Whether to first evaluate the modifiers on the object before listing the available attributes. False
drop_hidden bool Whether to drop hidden attributes (those starting with a dot). Defaults to False. False

Returns

Name Type Description
list[str] | None A list of attribute names if the molecule object exists, None otherwise.

named_attribute

BlenderObject.named_attribute(name, evaluate=False)

Retrieve a named attribute from the object.

Optionally, evaluate the object before reading the named attribute

Parameters

Name Type Description Default
name str Name of the attribute to get. required
evaluate bool Whether to evaluate the object before reading the attribute (default is False). False

Returns

Name Type Description
np.ndarray The attribute read from the mesh as a numpy array.

new_from_pydata

BlenderObject.new_from_pydata(vertices=None, edges=None, faces=None)

Create a new Blender object from vertex, edge and face data.

Parameters

Name Type Description Default
vertices np.ndarray The vertices of the object. None
edges np.ndarray The edges of the object. None
faces np.ndarray The faces of the object. None

Returns

Name Type Description
Object The new Blender object.

remove_named_attribute

BlenderObject.remove_named_attribute(name)

Remove a named attribute from the object.

Parameters

Name Type Description Default
name str The name of the attribute to remove. required

selected_positions

BlenderObject.selected_positions(mask=None)

Get the positions of the selected vertices, optionally filtered by a mask.

Parameters

Name Type Description Default
mask np.ndarray | None The mask to filter the selected vertices. Defaults to None. None

Returns

Name Type Description
np.ndarray The positions of the selected vertices.

set_boolean

BlenderObject.set_boolean(array, name)

Store a boolean attribute on the Blender object.

Parameters

Name Type Description Default
array np.ndarray The boolean data to be stored as an attribute. required
name str The name for the attribute. required

store_named_attribute

BlenderObject.store_named_attribute(
    data,
    name,
    atype=None,
    domain=Domains.POINT,
)

Store a named attribute on the Blender object.

Parameters

Name Type Description Default
data np.ndarray The data to be stored as an attribute. required
name str The name for the attribute. Will overwrite an already existing attribute. required
atype str or AttributeType or None The attribute type to store the data as. Either string or selection from the AttributeTypes enum. None will attempt to infer the attribute type from the input array. None
domain str or DomainType The domain to store the attribute on. Defaults to Domains.POINT. Domains.POINT

Returns

Name Type Description
self

transform_origin

BlenderObject.transform_origin(matrix)

Transform the origin of the Blender object.

Parameters

Name Type Description Default
matrix Matrix The transformation matrix to apply to the origin. required

transform_points

BlenderObject.transform_points(matrix)

Transform the points of the Blender object.

Parameters

Name Type Description Default
matrix Matrix The transformation matrix to apply to the points. required