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=float32)
array([[0.5308637 , 0.99826986, 0.843091  ],
       [0.07203292, 0.98913586, 0.09784757],
       [0.77736527, 0.24313526, 0.3605659 ],
       [0.15677385, 0.31428802, 0.6767369 ],
       [0.48980108, 0.02582507, 0.22970714],
       [0.4123465 , 0.21428691, 0.71938455],
       [0.2210958 , 0.5242113 , 0.15554   ],
       [0.7257358 , 0.01727932, 0.05299231],
       [0.7965769 , 0.6843283 , 0.37228397],
       [0.04035985, 0.12276432, 0.02063817]], dtype=float32)
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: float32)
[[0.9480225  0.6088045  0.8260128 ]
 [0.8969585  0.5322019  0.95380175]
 [0.35039315 0.87941766 0.25999364]
 [0.9500261  0.59052986 0.9928509 ]
 [0.95442957 0.3797441  0.40974173]
 [0.8895527  0.2914089  0.8573232 ]
 [0.7996647  0.9975916  0.5563563 ]
 [0.9890413  0.6469845  0.43517208]
 [0.02441751 0.22309035 0.38854185]
 [0.27548    0.3648589  0.00334484]]
Updated position:
AttributeArray 'position' from test_bob.001('test_bob.001')(domain: POINT, shape: (10, 3), dtype: float32)
[[0.9480225  0.6088045  1.8260128 ]
 [0.8969585  0.5322019  1.9538018 ]
 [0.35039315 0.87941766 1.2599937 ]
 [0.9500261  0.59052986 1.9928509 ]
 [0.95442957 0.3797441  1.4097418 ]
 [0.8895527  0.2914089  1.8573232 ]
 [0.7996647  0.9975916  1.5563563 ]
 [0.9890413  0.6469845  1.4351721 ]
 [0.02441751 0.22309035 1.3885418 ]
 [0.27548    0.3648589  1.0033449 ]]
As Array:
[[0.9480225  0.6088045  1.8260128 ]
 [0.8969585  0.5322019  1.9538018 ]
 [0.35039315 0.87941766 1.2599937 ]
 [0.9500261  0.59052986 1.9928509 ]
 [0.95442957 0.3797441  1.4097418 ]
 [0.8895527  0.2914089  1.8573232 ]
 [0.7996647  0.9975916  1.5563563 ]
 [0.9890413  0.6469845  1.4351721 ]
 [0.02441751 0.22309035 1.3885418 ]
 [0.27548    0.3648589  1.0033449 ]]