API
The API class is a container that holds metadata for attributes and tasks. It can also get the current project and workspace information and allows you to set metadata in projects that are not included in the context. E.g. projects, that are currently not open in Anchorpoint.
Usage
The API is obtained using the get_api() function from the anchorpoint module:
import anchorpoint
api = anchorpoint.get_api()
API Class
Properties
attributes(class: AttributeAPI): Access to the Attributes API for managing file and folder metadata. Provides methods for creating, reading, and writing attributes. See Attributes documentation for detailed usage.tasks(class: TaskAPI): Access to the Tasks API for managing task lists and individual tasks. Provides methods for creating, reading, and updating tasks. Supports task organization within task lists.
Methods
Project and Workspace Information
-
get_project()Gets the current project information.Returns (class: Project or None) - The current project or None if not in a project context
-
get_workspace()Gets the current workspace identifier.Returns (str) - The workspace ID
Examples
Working with Project Information
import anchorpoint
api = anchorpoint.get_api()
# Get current project
project = api.get_project()
if project:
print(f"Project name: {project.name}")
print(f"Project ID: {project.id}")
print(f"Project path: {project.path}")
else:
print("Not currently in a project")
# Get workspace information
workspace_id = api.get_workspace()
print(f"Workspace ID: {workspace_id}")
Cross-Project Attribute Management
import anchorpoint
import apsync
api = anchorpoint.get_api()
# Set attributes on files in different projects
# This works even if the project is not currently open in Anchorpoint
file_in_other_project = "/path/to/other/project/asset.jpg"
# Set metadata for files outside current context
api.attributes.set_attribute_value(file_in_other_project, "Status", "Approved")
api.attributes.set_attribute_value(file_in_other_project, "Review Notes", "Ready for production")
# Create attributes that can be used across projects
quality_attribute = api.attributes.get_attribute("Quality Rating")
if not quality_attribute:
quality_attribute = api.attributes.create_attribute("Quality Rating", apsync.AttributeType.rating)
# Apply to multiple files across different projects
files_to_rate = [
"/project1/characters/hero.fbx",
"/project2/environments/level1.ma",
"/project3/props/sword.blend"
]
for file_path in files_to_rate:
api.attributes.set_attribute_value(file_path, quality_attribute, 4)
print(f"Set quality rating for: {file_path}")
Combining API with Context
import anchorpoint
import apsync
# Get both context and API for comprehensive workflow
ctx = anchorpoint.get_context()
api = anchorpoint.get_api()
# Use context for current selection
current_files = ctx.selected_files
# Use API for broader project management
project = api.get_project()
if project and current_files:
print(f"Processing {len(current_files)} files in project: {project.name}")
# Set project-level attributes on selected files
for file_path in current_files:
api.attributes.set_attribute_value(file_path, "Project", project.name)
api.attributes.set_attribute_value(file_path, "Workspace", api.get_workspace())
# Use context information in the metadata
api.attributes.set_attribute_value(file_path, "Processed By", ctx.username)
print("Added project metadata to all selected files")