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.25004575, 0.87999344, 0.92342055],
       [0.04417552, 0.29962352, 0.18691063],
       [0.51875079, 0.24096453, 0.43428454],
       [0.5841741 , 0.29115689, 0.8152681 ],
       [0.84597218, 0.43942446, 0.0857207 ],
       [0.43879139, 0.47029224, 0.25869733],
       [0.96835452, 0.50561708, 0.09578508],
       [0.69189996, 0.46194771, 0.64455998],
       [0.95101672, 0.9241398 , 0.18109068],
       [0.89583176, 0.8326236 , 0.00744385]])
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.4957377  0.02810364 0.65298778]
 [0.37790427 0.85101527 0.90872306]
 [0.95270866 0.84757626 0.33268067]
 [0.24930111 0.52997798 0.53290457]
 [0.93077517 0.12639675 0.06118209]
 [0.90067518 0.44442827 0.81298423]
 [0.34525397 0.09772804 0.88460779]
 [0.35919476 0.89223421 0.47790754]
 [0.13374236 0.80863041 0.10099768]
 [0.30919522 0.95704812 0.47714052]]
Updated position:
AttributeArray 'position' from test_bob.001('test_bob.001')(domain: POINT, shape: (10, 3), dtype: float64)
[[0.4957377  0.02810364 1.65298772]
 [0.37790427 0.85101527 1.90872312]
 [0.95270866 0.84757626 1.3326807 ]
 [0.24930111 0.52997798 1.53290462]
 [0.93077517 0.12639675 1.06118214]
 [0.90067518 0.44442827 1.81298423]
 [0.34525397 0.09772804 1.88460779]
 [0.35919476 0.89223421 1.47790754]
 [0.13374236 0.80863041 1.10099769]
 [0.30919522 0.95704812 1.47714055]]
As Array:
[[0.4957377  0.02810364 1.65298772]
 [0.37790427 0.85101527 1.90872312]
 [0.95270866 0.84757626 1.3326807 ]
 [0.24930111 0.52997798 1.53290462]
 [0.93077517 0.12639675 1.06118214]
 [0.90067518 0.44442827 1.81298423]
 [0.34525397 0.09772804 1.88460779]
 [0.35919476 0.89223421 1.47790754]
 [0.13374236 0.80863041 1.10099769]
 [0.30919522 0.95704812 1.47714055]]