databpy 0.13.0
  • Home
  • Guides
    • Attributes
    • Syncing with Blender
    • Grease pencil and evaluated geometry
  • 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
  • Typed arrays
    • float32
    • vec2
    • vec3
    • vec4
    • color
    • srgb
    • color8
    • quat
    • mat4
    • int32
    • int8
    • ivec2
    • sivec2
    • boolean
    • string
  • Collections
    • create_collection
    • move_to_collection
  • Objects
    • create_object
    • create_mesh_object
    • create_curves_object
    • create_grease_pencil_object
    • create_pointcloud_object
    • create_bob
    • evaluate_object
    • GeometrySet
    • BlenderObject
    • AttributeDomainView
    • InstanceDomainView
    • Drawing
    • Drawings
    • 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, point cloud or grease pencil data. required
data npt.ArrayLike The attribute data, as a numpy array or anything convertible to one, with one value per element of the domain. A single value is stored for every element when it is a plain scalar such as 1.0, or a typed array of one value such as db.color([1, 0.5, 0, 1]). required
name str The name of the attribute. required
atype str or AttributeTypes or None The attribute type to store the data as, converting the values if needed. If None, a typed array such as vec3 is stored as its own type, other data as the type of an existing attribute, and otherwise the type is inferred from the 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’. New attributes on grease pencil objects need the ‘LAYER’ domain, as their points and strokes are on each layer’s drawings and can’t be accessed from the object; any other domain raises a NamedAttributeError. 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