Add Attribute class for named attributes

This commit is contained in:
Carson Katri 2022-11-28 21:09:27 -05:00
commit dddf0d93d9
4 changed files with 94 additions and 1 deletions

View file

@ -45,4 +45,24 @@ Any additional keyword arguments can be passed as normal.
```python
c.transfer(position(), mapping=TransferAttribute.Mapping.INDEX)
```
## Named Attributes
Custom attributes can be created by name.
The safest way to use named attributes is with the `Attribute` class.
Create a named attribute with a data type and optional domain, then use the `store(...)`, `exists()`, and `__call__(...)` methods to use it.
```python
# Create the attribute
my_custom_attribute = Attribute(
"my_custom_attribute",
NamedAttribute.DataType.FLOAT, # declare the data type once
StoreNamedAttribute.Domain.INSTANCE # optional
)
# Store a value
geometry = my_custom_attribute.store(geometry, 0.5)
# Use the value by calling the attribute
geometry = geometry.set_position(offset=my_custom_attribute())
```