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([[8.14702213e-01, 4.84915227e-01, 3.37915361e-01],
       [3.16940963e-01, 7.77591527e-01, 8.77216697e-01],
       [7.20350623e-01, 9.35581207e-01, 9.20853764e-02],
       [5.31580269e-01, 3.32719833e-01, 7.35855401e-01],
       [2.72675872e-01, 9.73231912e-01, 3.29646528e-01],
       [4.16190058e-01, 7.54297435e-01, 3.83877232e-05],
       [2.72199422e-01, 5.74955821e-01, 5.79974711e-01],
       [1.73900396e-01, 6.53003037e-01, 5.38799524e-01],
       [7.25256503e-01, 9.96096194e-01, 4.72344100e-01],
       [7.55660176e-01, 6.34358346e-01, 3.61921072e-01]])
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)
[[2.19042420e-01 7.69673169e-01 4.90481764e-01]
 [9.30263340e-01 5.28983176e-01 6.81385696e-01]
 [9.78527486e-01 1.99439734e-01 3.38401705e-01]
 [2.64620990e-01 4.52663928e-01 6.70723766e-02]
 [4.63104129e-01 6.15715742e-01 8.95452321e-01]
 [1.20886855e-01 8.25367749e-01 4.67821002e-01]
 [9.57915962e-01 3.93782824e-01 3.42597574e-01]
 [4.43669796e-01 6.16032541e-01 6.20244324e-01]
 [1.43504813e-01 7.35180795e-01 1.24602564e-01]
 [5.89453042e-01 3.25758883e-04 2.34416723e-02]]
Updated position:
AttributeArray 'position' from test_bob.001('test_bob.001')(domain: POINT, shape: (10, 3), dtype: float64)
[[2.19042420e-01 7.69673169e-01 1.49048173e+00]
 [9.30263340e-01 5.28983176e-01 1.68138576e+00]
 [9.78527486e-01 1.99439734e-01 1.33840168e+00]
 [2.64620990e-01 4.52663928e-01 1.06707239e+00]
 [4.63104129e-01 6.15715742e-01 1.89545226e+00]
 [1.20886855e-01 8.25367749e-01 1.46782100e+00]
 [9.57915962e-01 3.93782824e-01 1.34259760e+00]
 [4.43669796e-01 6.16032541e-01 1.62024426e+00]
 [1.43504813e-01 7.35180795e-01 1.12460256e+00]
 [5.89453042e-01 3.25758883e-04 1.02344167e+00]]
As Array:
[[2.19042420e-01 7.69673169e-01 1.49048173e+00]
 [9.30263340e-01 5.28983176e-01 1.68138576e+00]
 [9.78527486e-01 1.99439734e-01 1.33840168e+00]
 [2.64620990e-01 4.52663928e-01 1.06707239e+00]
 [4.63104129e-01 6.15715742e-01 1.89545226e+00]
 [1.20886855e-01 8.25367749e-01 1.46782100e+00]
 [9.57915962e-01 3.93782824e-01 1.34259760e+00]
 [4.43669796e-01 6.16032541e-01 1.62024426e+00]
 [1.43504813e-01 7.35180795e-01 1.12460256e+00]
 [5.89453042e-01 3.25758883e-04 1.02344167e+00]]