Attributes
Attributes in Anchorpoint are custom metadata that can be attached to files, folders, and tasks to add context and organization to your assets. The Attributes API provides comprehensive functionality to read, write, and manage different types of attributes including tags, text fields, ratings, links, dates, and checkboxes.
Usage
import apsync
import anchorpoint
from datetime import datetime
ctx = anchorpoint.get_context()
api = anchorpoint.get_api()
# Set a text attribute by name
api.attributes.set_attribute_value(ctx.path, "Description", "Hero character artwork")
# Get a text attribute
description = api.attributes.get_attribute_value(ctx.path, "Description")
print(description) # Output: "Hero character artwork"
# Set a date attribute
api.attributes.set_attribute_value(ctx.path, "Created At", datetime.now())
# Work with attribute objects for more control
attribute = api.attributes.get_attribute("Status")
if not attribute:
attribute = api.attributes.create_attribute("Status", apsync.AttributeType.single_choice_tag)
# Set attribute value using attribute object
api.attributes.set_attribute_value(ctx.path, attribute, "In Progress")
Attribute Types
Anchorpoint supports several attribute types defined in the AttributeType class:
import apsync
# Available attribute types
apsync.AttributeType.single_choice_tag # Select one tag from predefined options
apsync.AttributeType.multiple_choice_tag # Select multiple tags from predefined options
apsync.AttributeType.text # Free text input
apsync.AttributeType.rating # Numeric rating (typically 1-5 stars)
apsync.AttributeType.link # URL or file path links
apsync.AttributeType.date # Date/timestamp values
apsync.AttributeType.checkbox # Boolean true/false values
Attributes API
The Attributes API is accessed through api.attributes and provides methods for creating, managing, and working with attributes.
Getting and Setting Attribute Values
-
api.attributes.get_attribute_value(object_path, attribute_or_name)Retrieves the value of an attribute for a file, folder, or task.Arguments
object_path(str): Full path to the file or folderattribute_or_name(Attribute or str): Attribute object or attribute name
Returns The attribute value (type depends on attribute type)
-
api.attributes.set_attribute_value(object_path, attribute_or_name, value)Sets the value of an attribute for a file, folder, or task.Arguments
object_path(str): Full path to the file or folderattribute_or_name(Attribute or str): Attribute object or attribute namevalue(Any): Value to set (type depends on attribute type)
Managing Attributes
-
api.attributes.get_attribute(name)Retrieves an attribute definition by name.Arguments
name(str): Name of the attribute
Returns (class: Attribute or None) - The attribute object or None if not found
-
api.attributes.create_attribute(name, attribute_type)Creates a new attribute definition.Arguments
name(str): Name of the attributeattribute_type(class: AttributeType): Type of the attribute
Returns (class: Attribute) - The created attribute object
Managing Tags
-
api.attributes.set_attribute_tags(attribute, tags)Sets the available tags for a tag-type attribute.Arguments
attribute(class: Attribute): The attribute objecttags(List[class: AttributeTag]): List of tag objects
AttributeTag Class
Methods
-
apsync.AttributeTag(name, color)Creates a new attribute tag.Arguments
name(str): Name of the tagcolor(str): Color for the tag (e.g., "blue", "red", "green")
Returns (class: AttributeTag): The created tag object
Attribute Class
apsync.Attribute
The Attribute class represents an attribute definition with the following properties:
Properties
name(str): Name of the attribute.type(AttributeType): Type of the attribute (text, rating, tags, etc.).tags(List[AttributeTag]): Available tags for tag-type attributes.id(str): Unique identifier for the attribute.
Examples
Basic Text Attributes
import apsync
import anchorpoint
ctx = anchorpoint.get_context()
api = anchorpoint.get_api()
# Set a text attribute by name (will auto-create if doesn't exist)
api.attributes.set_attribute_value(ctx.path, "Description", "Hero character concept art for level 1")
# Get the description
description = api.attributes.get_attribute_value(ctx.path, "Description")
print(f"Description: {description}")
Working with Tags
import apsync
import anchorpoint
ctx = anchorpoint.get_context()
api = anchorpoint.get_api()
# Create or get a single choice tag attribute
status_attribute = api.attributes.get_attribute("Status")
if not status_attribute:
status_attribute = api.attributes.create_attribute("Status", apsync.AttributeType.single_choice_tag)
# Set up the available tags for this attribute
tags = [
apsync.AttributeTag("In Progress", "blue"),
apsync.AttributeTag("Complete", "green"),
apsync.AttributeTag("On Hold", "orange")
]
api.attributes.set_attribute_tags(status_attribute, tags)
# Set the status value
api.attributes.set_attribute_value(ctx.path, status_attribute, "In Progress")
# Or set using attribute name (simpler for existing attributes)
api.attributes.set_attribute_value(ctx.path, "Status", "Complete")
# Get the current status
current_status = api.attributes.get_attribute_value(ctx.path, "Status")
print(f"Current status: {current_status}")
Rating and Review Workflow
import apsync
import anchorpoint
from datetime import datetime
ctx = anchorpoint.get_context()
api = anchorpoint.get_api()
# Set quality rating (1-5 stars)
api.attributes.set_attribute_value(ctx.path, "Quality", 4)
# Mark as reviewed
api.attributes.set_attribute_value(ctx.path, "Reviewed", True)
# Set review date to current time
api.attributes.set_attribute_value(ctx.path, "Review Date", datetime.now())
# Add reviewer link
api.attributes.set_attribute_value(ctx.path, "Reviewer Profile", "https://company.com/profiles/john.doe")
# Get review information
rating = api.attributes.get_attribute_value(ctx.path, "Quality")
is_reviewed = api.attributes.get_attribute_value(ctx.path, "Reviewed")
review_date = api.attributes.get_attribute_value(ctx.path, "Review Date")
print(f"Rating: {rating}/5 stars")
print(f"Reviewed: {is_reviewed}")
print(f"Review date: {review_date}")
Batch Processing with Attributes
import apsync
import anchorpoint
import os
from datetime import datetime
ctx = anchorpoint.get_context()
api = anchorpoint.get_api()
# Process all selected files
for file_path in ctx.selected_files:
filename = os.path.basename(file_path)
# Set common attributes based on file type
if filename.lower().endswith(('.jpg', '.png', '.tiff')):
api.attributes.set_attribute_value(file_path, "Type", "Image")
api.attributes.set_attribute_value(file_path, "Format", "Raster")
elif filename.lower().endswith(('.fbx', '.obj', '.blend')):
api.attributes.set_attribute_value(file_path, "Type", "3D Model")
api.attributes.set_attribute_value(file_path, "Format", "3D Mesh")
# Set processing timestamp
api.attributes.set_attribute_value(file_path, "Processed", datetime.now())
print(f"Processed: {filename}")
Creating Complex Attribute Workflows
import apsync
import anchorpoint
ctx = anchorpoint.get_context()
api = anchorpoint.get_api()
def create_attribute_example():
# This example shows how to access attributes and update the set of tags
attribute = api.attributes.get_attribute("Python Example")
if not attribute:
attribute = api.attributes.create_attribute(
"Python Example", apsync.AttributeType.single_choice_tag
)
new_tag_name = f"Example Tag {len(attribute.tags) + 1}"
tags = attribute.tags
tags.append(apsync.AttributeTag(new_tag_name, "blue"))
api.attributes.set_attribute_tags(attribute, tags)
return attribute
def set_attributes(file_path, example_attribute):
# We can either use the attribute that we have created before ...
latest_tag = example_attribute.tags[-1]
api.attributes.set_attribute_value(file_path, example_attribute, latest_tag)
print(api.attributes.get_attribute_value(file_path, example_attribute))
# ... or create / use attributes described by their title
api.attributes.set_attribute_value(file_path, "Message", "Hello from Python")
print(api.attributes.get_attribute_value(file_path, "Message"))
# To set a date, use datetime.datetime or a unix timestamp
from datetime import datetime
api.attributes.set_attribute_value(file_path, "Created At", datetime.now())
# Create the example attribute
attribute = create_attribute_example()
# Apply to all selected files
for file_path in ctx.selected_files:
set_attributes(file_path, attribute)