databpy
  • Home
  • Attributes
  • API
  1. Objects
  2. BlenderObject
  • Function reference
  • Attribute
    • named_attribute
    • store_named_attribute
    • remove_named_attribute
    • AttributeDomains
    • AttributeTypes
    • AttributeArray
  • Collections
    • create_collection
  • Objects
    • create_object
    • create_mesh_object
    • create_curves_object
    • create_pointcloud_object
    • create_bob
    • evaluate_object
    • BlenderObject
    • BlenderObjectAttribute
    • BlenderObjectBase
    • LinkedObjectError

On this page

  • BlenderObject
    • Attributes
    • Methods
  1. Objects
  2. BlenderObject

BlenderObject

BlenderObject(obj=None)

A convenience class for working with Blender objects.

Extends BlenderObjectBase with creation methods and additional utility functions.

Attributes

Name Description
attributes Get the attributes of the Blender object.
data Get the data block of the Blender object.
edges Get the edges of the Blender mesh 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.
uuid Get the unique identifier for this object.
vertices Get the vertices of the Blender mesh object.

Methods

Name Description
centroid Calculate the weighted or unweighted centroid of the object’s positions.
evaluate Return a version of the object with all modifiers applied.
from_curves Create a BlenderObject from curves data.
from_mesh Create a BlenderObject from mesh data.
from_pointcloud Create a BlenderObject from point cloud data.
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.
store_named_attribute Store a named attribute on the Blender object.

centroid

BlenderObject.centroid(weight=None)

Calculate the weighted or unweighted centroid of the object’s positions.

Parameters

Name Type Description Default
weight str | np.ndarray | None The weights or indices for calculating the centroid: - If str: Name of attribute to use as weights - If np.ndarray with float dtype: Weights for each position - If np.ndarray with int dtype: Indices of positions to include - If None: Use all positions equally weighted Defaults to None. None

Returns

Name Type Description
np.ndarray A 3D vector representing the centroid position.

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

from_curves

BlenderObject.from_curves(
    positions=None,
    curve_sizes=None,
    name='Curves',
    collection=None,
)

Create a BlenderObject from curves data.

Parameters

Name Type Description Default
positions ndarray or None Control point positions with shape (N, 3). Default is None. None
curve_sizes list[int] | np.ndarray or None Number of points in each curve. Default is None. None
name str Name of the created object. Default is “Curves”. 'Curves'
collection bpy.types.Collection or None Blender collection to link the object to. Default is None. None

Returns

Name Type Description
BlenderObject A wrapped Blender curves object.

Examples

import numpy as np
import databpy as db

# Create 2 curves with 3 and 4 points
positions = np.random.random((7, 3))
bob = db.BlenderObject.from_curves(positions, [3, 4], name="MyCurves")
print(len(bob))  # 7

from_mesh

BlenderObject.from_mesh(
    vertices=None,
    edges=None,
    faces=None,
    name='Mesh',
    collection=None,
)

Create a BlenderObject from mesh data.

Parameters

Name Type Description Default
vertices ndarray or None Array of vertex coordinates with shape (N, 3). Default is None. None
edges ndarray or None Array of edge indices. Default is None. None
faces ndarray or None Array of face indices. Default is None. None
name str Name of the created object. Default is “Mesh”. 'Mesh'
collection bpy.types.Collection or None Blender collection to link the object to. Default is None. None

Returns

Name Type Description
BlenderObject A wrapped Blender mesh object.

Examples

import numpy as np
import databpy as db

vertices = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]])
bob = db.BlenderObject.from_mesh(vertices=vertices, name="MyMesh")
print(len(bob))  # 4

from_pointcloud

BlenderObject.from_pointcloud(
    positions=None,
    name='PointCloud',
    collection=None,
)

Create a BlenderObject from point cloud data.

Parameters

Name Type Description Default
positions ndarray or None Point positions with shape (N, 3). Default is None. None
name str Name of the created object. Default is “PointCloud”. 'PointCloud'
collection bpy.types.Collection or None Blender collection to link the object to. Default is None. None

Returns

Name Type Description
BlenderObject A wrapped Blender point cloud object.

Examples

import numpy as np
import databpy as db

# Create point cloud with 100 random points
positions = np.random.random((100, 3))
bob = db.BlenderObject.from_pointcloud(positions, name="MyPointCloud")
print(len(bob))  # 100

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

store_named_attribute

BlenderObject.store_named_attribute(
    data,
    name,
    atype=None,
    domain=AttributeDomains.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 AttributeDomain The domain to store the attribute on. Defaults to Domains.POINT. AttributeDomains.POINT

Returns

Name Type Description
self