databpy 0.11.0
  • Home
  • Attributes
  • API
  • Changelog
  1. Attribute
  2. store_named_attribute
  • Function reference
  • Attribute
    • named_attribute
    • store_named_attribute
    • remove_named_attribute
    • list_attributes
    • AttributeDomains
    • AttributeTypes
    • AttributeArray
    • Attribute
    • attribute.guess_atype_from_array
  • Collections
    • create_collection
    • move_to_collection
  • Objects
    • create_object
    • create_mesh_object
    • create_curves_object
    • create_pointcloud_object
    • create_bob
    • evaluate_object
    • GeometrySet
    • BlenderObject
    • BlenderObjectAttribute
    • BlenderObjectBase
  • Errors
    • DatabpyError
    • NamedAttributeError
    • AttributeNotFoundError
    • AttributeMismatchError
    • LinkedObjectError
  • Utilities
    • require
    • require_data
    • mesh_data
    • curves_data
    • pointcloud_data
    • volume_data
    • active_scene
    • active_object
    • centre
    • lerp
  • Nodes (deprecated)
    • nodes.new_tree
    • nodes.swap_tree
    • nodes.custom_string_iswitch
    • nodes.append_from_blend
    • nodes.new_socket
    • nodes.tree_interface
    • nodes.input_socket
    • nodes.output_socket
    • nodes.socket_value
    • nodes.set_socket_value
    • nodes.MaintainConnections
    • nodes.DuplicatePrevention

On this page

  • Parameters
  • Returns
  • Raises
  • Examples
  1. Attribute
  2. store_named_attribute

store_named_attribute

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

Name Type Description Default
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

Returns

Name Type Description
bpy.types.Attribute The created or modified attribute.

Raises

Name Type Description
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)
named_attribute
remove_named_attribute