databpy
  • Home
  • 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_bob
    • evaluate_object
    • BlenderObject
    • LinkedObjectError

On this page

  • Examples:
  1. Attribute
  2. AttributeArray

AttributeArray

AttributeArray()

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

Values are retrieved from the Blender object as a numpy array, the operation is applied and the result is store back on the Blender object. This allows for operations like pos[:, 2] += 1.0 to work seamlessly.

Examples:

import databpy as db
import numpy as np

obj = db.create_object(np.random.rand(10, 3), name="test_bob")
db.AttributeArray(obj, "position")
AttributeArray(name='position', object='test_bob', mesh='test_bob', domain=POINT, type=FLOAT_VECTOR, shape=(10, 3), dtype=float64)
array([[0.29203162, 0.31714809, 0.34324712],
       [0.37308386, 0.54361033, 0.44725364],
       [0.26997793, 0.8939231 , 0.35390806],
       [0.4186478 , 0.05907517, 0.44522715],
       [0.6477055 , 0.38722485, 0.60644263],
       [0.26390332, 0.49744251, 0.85437679],
       [0.47857657, 0.19787669, 0.5423615 ],
       [0.93142331, 0.13817523, 0.67322946],
       [0.2535319 , 0.89441735, 0.07065749],
       [0.68786436, 0.86252987, 0.25374731]])
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)  # Access the position attribute as an AttributeArray
bob.position[:, 2] += 1.0
print('Updated position:')
print(bob.position)

print('As Array:')
print(np.asarray(bob.position))  # Convert to a regular numpy array
Initial position:
AttributeArray 'position' from test_bob.001('test_bob.001')(domain: POINT, shape: (10, 3), dtype: float64)
[[0.68635207 0.85544086 0.57478786]
 [0.81262243 0.12610544 0.75471652]
 [0.69195884 0.29659563 0.29057339]
 [0.86796206 0.05321372 0.88841563]
 [0.00319141 0.46194443 0.91802454]
 [0.46316972 0.62929899 0.56575382]
 [0.24597153 0.31757557 0.71642125]
 [0.53175598 0.16209516 0.44344288]
 [0.98900276 0.81705719 0.81710774]
 [0.86415625 0.71724814 0.24610405]]
Updated position:
AttributeArray 'position' from test_bob.001('test_bob.001')(domain: POINT, shape: (10, 3), dtype: float64)
[[0.68635207 0.85544086 1.57478786]
 [0.81262243 0.12610544 1.75471652]
 [0.69195884 0.29659563 1.29057336]
 [0.86796206 0.05321372 1.88841558]
 [0.00319141 0.46194443 1.91802454]
 [0.46316972 0.62929899 1.56575382]
 [0.24597153 0.31757557 1.71642125]
 [0.53175598 0.16209516 1.44344282]
 [0.98900276 0.81705719 1.81710768]
 [0.86415625 0.71724814 1.246104  ]]
As Array:
[[0.68635207 0.85544086 1.57478786]
 [0.81262243 0.12610544 1.75471652]
 [0.69195884 0.29659563 1.29057336]
 [0.86796206 0.05321372 1.88841558]
 [0.00319141 0.46194443 1.91802454]
 [0.46316972 0.62929899 1.56575382]
 [0.24597153 0.31757557 1.71642125]
 [0.53175598 0.16209516 1.44344282]
 [0.98900276 0.81705719 1.81710768]
 [0.86415625 0.71724814 1.246104  ]]