store_named_attribute(obj, data, name, atype= None , domain= None , overwrite= True )
Write values to a named attribute on the object, creating it if needed.
Parameters
obj
bpy.types .Object
The Blender object, with mesh, curves or point cloud data.
required
data
npt .ArrayLike
The attribute data, as a numpy array or anything convertible to one.
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, the type of an existing attribute is used, otherwise the type is inferred from data.
None
domain
str or AttributeDomains or None
The domain of the attribute. If None, the domain of an existing attribute is used, otherwise ‘POINT’.
None
overwrite
bool
Whether to write to an existing attribute with the same name, by default True. If False, a new attribute is created, which Blender gives a unique name such as name.001.
True
Raises
ValueError
If atype or domain doesn’t match an available type or domain, no type can be inferred, or atype is FLOAT4 before Blender 5.2.
NamedAttributeError
If the object doesn’t hold attributes, the name is empty, the data size doesn’t match the domain, the atype or domain conflict with an existing attribute, or the attribute can’t be created on the domain.
AttributeMismatchError
If the values can’t be represented by the attribute’s type.
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)= } " )
list_attributes(obj)=['.corner_edge', '.corner_vert', '.edge_verts', '.select_edge', '.select_poly', '.select_vert', '.uv_select_edge', '.uv_select_face', '.uv_select_vert', 'UVMap', 'position', 'sharp_face']
store_named_attribute(obj, np.arange(8 ), "test_attribute" )
print (f" { list_attributes(obj)= } " )
list_attributes(obj)=['.corner_edge', '.corner_vert', '.edge_verts', '.select_edge', '.select_poly', '.select_vert', '.uv_select_edge', '.uv_select_face', '.uv_select_vert', 'UVMap', 'position', 'sharp_face', 'test_attribute']
named_attribute(obj, "test_attribute" )
array([0, 1, 2, 3, 4, 5, 6, 7], dtype=int32)