Skip to main content

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")

Batch Operations Across Multiple Projects

import anchorpoint
import apsync
import os

api = anchorpoint.get_api()

def update_project_metadata(project_paths):
"""Update metadata for multiple projects"""

for project_path in project_paths:
print(f"Processing project: {project_path}")

# Walk through all files in the project
for root, dirs, files in os.walk(project_path):
for file in files:
file_path = os.path.join(root, file)

# Set common project attributes
api.attributes.set_attribute_value(file_path, "Project Root", project_path)
api.attributes.set_attribute_value(file_path, "Last Updated", apsync.datetime.now())

# Set file type based on extension
_, ext = os.path.splitext(file)
if ext.lower() in ['.jpg', '.png', '.tiff']:
api.attributes.set_attribute_value(file_path, "Asset Type", "Texture")
elif ext.lower() in ['.fbx', '.obj', '.ma', '.blend']:
api.attributes.set_attribute_value(file_path, "Asset Type", "3D Model")

# Process multiple projects
project_list = [
"/path/to/project1",
"/path/to/project2",
"/path/to/project3"
]

update_project_metadata(project_list)

Working with Attributes API

import anchorpoint
import apsync

api = anchorpoint.get_api()

# Create a comprehensive attribute system
def setup_project_attributes():
"""Set up standard attributes for project management"""

# Create status attribute with predefined options
status_attr = api.attributes.get_attribute("Asset Status")
if not status_attr:
status_attr = api.attributes.create_attribute("Asset Status", apsync.AttributeType.single_choice_tag)

# Define status options
status_tags = [
apsync.AttributeTag("Work in Progress", "orange"),
apsync.AttributeTag("Review Required", "yellow"),
apsync.AttributeTag("Approved", "green"),
apsync.AttributeTag("Needs Revision", "red")
]
api.attributes.set_attribute_tags(status_attr, status_tags)

# Create priority attribute
priority_attr = api.attributes.get_attribute("Priority")
if not priority_attr:
priority_attr = api.attributes.create_attribute("Priority", apsync.AttributeType.single_choice_tag)

priority_tags = [
apsync.AttributeTag("High", "red"),
apsync.AttributeTag("Medium", "yellow"),
apsync.AttributeTag("Low", "blue")
]
api.attributes.set_attribute_tags(priority_attr, priority_tags)

return status_attr, priority_attr

# Set up the attribute system
status_attr, priority_attr = setup_project_attributes()

# Apply to files
file_path = "/project/characters/main_character.fbx"
api.attributes.set_attribute_value(file_path, status_attr, "Review Required")
api.attributes.set_attribute_value(file_path, priority_attr, "High")
api.attributes.set_attribute_value(file_path, "Notes", "Final review before production")

print("Project attribute system configured and applied")