databpy
  • Home
  • Attributes
  • API
  1. Attribute
  2. AttributeArray
  • 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

  • Performance Characteristics
  • Supported Types
  • Attributes
  • Examples
  • See Also
  1. Attribute
  2. AttributeArray

AttributeArray

AttributeArray()

A numpy array subclass that automatically syncs changes back to the Blender object.

AttributeArray provides an ergonomic interface for working with Blender attributes using familiar numpy operations. It automatically handles bidirectional syncing: values are retrieved from Blender as a numpy array, operations are applied, and results are immediately stored back to Blender.

This is the high-level interface for attribute manipulation. For low-level control, see the Attribute class which provides manual get/set operations without auto-sync.

Performance Characteristics

  • Every modification syncs the ENTIRE attribute array to Blender, not just changed values
  • This is due to Blender’s foreach_set API requiring the complete array
  • For large meshes (10K+ elements), consider batching multiple operations
  • Example: pos[:, 2] += 1.0 writes all position data, not just Z coordinates

Supported Types

Works with all Blender attribute types: - Float types: FLOAT, FLOAT2, FLOAT_VECTOR, FLOAT_COLOR, FLOAT4X4, QUATERNION - Integer types: INT (int32), INT8, INT32_2D - Boolean: BOOLEAN - Color: BYTE_COLOR (uint8)

Attributes

Name Type Description
_blender_object bpy.types.Object Reference to the Blender object for syncing changes.
_attribute Attribute The underlying Attribute instance with type information.
_attr_name str Name of the attribute being wrapped.
_root AttributeArray Reference to the root array for handling views/slices correctly.

Examples

Basic usage:

import databpy as db
import numpy as np

obj = db.create_object(np.random.rand(10, 3), name="test_bob")
pos = db.AttributeArray(obj, "position")
pos[:, 2] += 1.0  # Automatically syncs to Blender

Using BlenderObject for convenience:

import databpy as db
import numpy as np

bob = db.create_bob(np.random.rand(10, 3), name="test_bob")
print('Initial position:')
print(bob.position)  # Returns an AttributeArray
Initial position:
AttributeArray 'position' from test_bob.001('test_bob.001')(domain: POINT, shape: (10, 3), dtype: float32)
[[0.48116252 0.59123015 0.7606079 ]
 [0.3947243  0.18178162 0.63557345]
 [0.92384094 0.07174351 0.86319673]
 [0.47288948 0.4056464  0.63373506]
 [0.8608448  0.01129193 0.15811586]
 [0.9624969  0.03956724 0.9545394 ]
 [0.7292622  0.34638062 0.5135335 ]
 [0.8013578  0.1273388  0.26503298]
 [0.8808685  0.84634435 0.8443028 ]
 [0.2566412  0.87557036 0.56772345]]
bob.position[:, 2] += 1.0
print('Updated position:')
print(bob.position)
Updated position:
AttributeArray 'position' from test_bob.001('test_bob.001')(domain: POINT, shape: (10, 3), dtype: float32)
[[0.48116252 0.59123015 1.760608  ]
 [0.3947243  0.18178162 1.6355734 ]
 [0.92384094 0.07174351 1.8631967 ]
 [0.47288948 0.4056464  1.6337351 ]
 [0.8608448  0.01129193 1.1581159 ]
 [0.9624969  0.03956724 1.9545394 ]
 [0.7292622  0.34638062 1.5135335 ]
 [0.8013578  0.1273388  1.265033  ]
 [0.8808685  0.84634435 1.8443028 ]
 [0.2566412  0.87557036 1.5677235 ]]
# Convert to regular numpy array (no sync)
print('As Array:')
print(np.asarray(bob.position))
As Array:
[[0.48116252 0.59123015 1.760608  ]
 [0.3947243  0.18178162 1.6355734 ]
 [0.92384094 0.07174351 1.8631967 ]
 [0.47288948 0.4056464  1.6337351 ]
 [0.8608448  0.01129193 1.1581159 ]
 [0.9624969  0.03956724 1.9545394 ]
 [0.7292622  0.34638062 1.5135335 ]
 [0.8013578  0.1273388  1.265033  ]
 [0.8808685  0.84634435 1.8443028 ]
 [0.2566412  0.87557036 1.5677235 ]]

Working with integer attributes:

import databpy as db
import numpy as np

obj = db.create_object(np.random.rand(10, 3))
# Store integer attribute
ids = np.arange(10, dtype=np.int32)
db.store_named_attribute(obj, ids, "id", atype="INT")

# Access as AttributeArray
id_array = db.AttributeArray(obj, "id")
id_array += 100  # Automatically syncs as int32

See Also

Attribute : Low-level attribute interface without auto-sync store_named_attribute : Function to create/update attributes named_attribute : Function to read attribute data as regular arrays