databpy 0.11.0
  • Home
  • Attributes
  • API
  • Changelog
  1. Attribute
  2. 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

  • Attribute
    • Architecture
    • Parameters
    • Raises
    • Attributes
    • Examples
    • See Also
    • Methods
  1. Attribute
  2. Attribute

Attribute

Attribute(attribute)

Low-level wrapper around a Blender attribute with explicit reads and writes.

Values are only read by as_array and only written by from_array. Use this class to control when values are transferred, for example to apply several whole-array operations with a single write, or to inspect an attribute’s type, domain and shape without reading its values.

For automatic syncing, use AttributeArray, a numpy array subclass that writes changes back to Blender as they are made.

Architecture

  • Attribute: Low-level, manual control (this class)
  • AttributeArray: High-level, automatically syncing numpy subclass
  • BlenderObject["attr"]: Convenience accessor returning AttributeArray

Parameters

Name Type Description Default
attribute bpy.types.Attribute The Blender attribute to wrap. required

Raises

Name Type Description
NamedAttributeError If the attribute has an unsupported data type.

Attributes

Name Type Description
attribute bpy.types.Attribute The underlying Blender attribute.
name str Name of the attribute.
atype AttributeTypes Enum value representing the attribute’s data type.
domain AttributeDomains Enum value representing the attribute’s domain (POINT, EDGE, FACE, etc.).
shape tuple Full shape including number of elements and component dimensions.
dtype Type NumPy dtype corresponding to the attribute type.

Examples

Manual read/write workflow:

import databpy as db
import numpy as np

obj = db.create_object(np.random.rand(10, 3))
attr = db.Attribute(obj.data.attributes["position"])

# Read once
positions = attr.as_array()
positions[:, 2] += 1.0

# Write once
attr.from_array(positions)

Compare with AttributeArray, which writes each change as it is made:

import databpy as db
import numpy as np

bob = db.create_bob(np.random.rand(10, 3))
bob.position[:, 2] += 1.0  # writes the new z values immediately

See Also

AttributeArray : Automatically syncing numpy subclass store_named_attribute : Create or update attributes named_attribute : Convenience function to read attribute data

Methods

Name Description
as_array Read the attribute’s values into a new numpy array.
from_array Write the values of an array to the attribute.

as_array

Attribute.as_array()

Read the attribute’s values into a new numpy array.

Returns

Name Type Description
np.ndarray The values, with the attribute’s shape and dtype. BYTE_COLOR values are uint8 from 0 to 255.

from_array

Attribute.from_array(array)

Write the values of an array to the attribute.

The array can have any shape with the same number of values as the attribute, such as a flat array, and is read in C order. Values are cast to the attribute’s storage dtype.

Parameters

Name Type Description Default
array npt.ArrayLike The values to write, as a numpy array or anything convertible to one. required

Raises

Name Type Description
AttributeMismatchError If the number of values doesn’t match the attribute’s size, or the values can’t be represented by the attribute’s type.
AttributeArray
attribute.guess_atype_from_array