store_named_attribute(
obj,
data,
name,
atype=None,
domain=AttributeDomains.POINT,
overwrite=True,
)
Adds and sets the values of an attribute on the object.
Parameters
obj |
bpy.types.Object |
The Blender object. |
required |
data |
np.ndarray |
The attribute data as a numpy array. |
required |
name |
str |
The name of the attribute. |
required |
atype |
str or AttributeTypes or None |
The attribute type to store the data as. If None, type is inferred from data. |
None |
domain |
str or AttributeDomain |
The domain of the attribute, by default ‘POINT’. |
AttributeDomains.POINT |
overwrite |
bool |
Whether to overwrite existing attribute, by default True. |
True |
Returns
|
bpy.types.Attribute |
The added or modified attribute. |
Raises
|
ValueError |
If atype string doesn’t match available types. |
|
AttributeMismatchError |
If data length doesn’t match domain size. |
Examples
import bpy
import numpy as np
from databpy import store_named_attribute, list_attributes, named_attribute
obj = bpy.data.objects["Cube"]
print(f"{list_attributes(obj)=}")
store_named_attribute(obj, np.arange(8), "test_attribute")
print(f"{list_attributes(obj)=}")
named_attribute(obj, "test_attribute")
list_attributes(obj)=['position', '.select_vert', '.edge_verts', '.select_edge', '.select_poly', 'sharp_face', '.corner_vert', '.corner_edge', 'UVMap']
list_attributes(obj)=['test_attribute', 'position', '.select_vert', '.edge_verts', '.select_edge', '.select_poly', 'sharp_face', '.corner_vert', '.corner_edge', 'UVMap']
array([0, 1, 2, 3, 4, 5, 6, 7])