Skip to main content

Utility Classes and Functions

The Anchorpoint Python API provides various utility functions and classes for common operations such as file management, project operations, application detection, logging, and more. These utilities are distributed across the anchorpoint and apsync modules to support different aspects of Anchorpoint workflows.

Usage

Utility functions are accessed directly from their respective modules:

import anchorpoint
import apsync

# Get application directory
app_dir = anchorpoint.get_application_dir()

# Check if an application exists
has_blender = anchorpoint.check_application("/path/to/blender.exe", "Blender 3D")

# Copy files within Anchorpoint workspace
apsync.copy_file("/source/file.jpg", "/target/file.jpg", workspace_id="ws_123")

# Log error messages
anchorpoint.log_error("Something went wrong during processing")

Anchorpoint Utilities

Application Management

  • check_application(application_path, info='', name=None) Checks if an application exists and is accessible at the specified path.

    Arguments

    • application_path (str): Absolute path to the application executable
    • info (str): Additional information about the application (optional)
    • name (str): Display name for the application (optional)

    Returns (bool): True if the application exists and is accessible

  • get_application_dir() Gets the Anchorpoint application directory path.

    Returns (str): Absolute path to the Anchorpoint installation directory

Configuration and Context

  • get_config() Gets the Anchorpoint configuration object containing default settings and OAuth credentials for various services.

    Returns (class: APConfig): Configuration object with the following properties:

    • gcs_client_id (str): Google Cloud Storage OAuth client ID
    • gcs_key (str): Google Cloud Storage OAuth client key
    • github_client_id (str): GitHub OAuth client ID
    • github_client_key (str): GitHub OAuth client key
    • gitlab_client_id (str): GitLab OAuth client ID
    • gitlab_client_key (str): GitLab OAuth client key

    Example

    import anchorpoint as ap

    config = ap.get_config()
    github_id = config.github_client_id
    gcs_credentials = (config.gcs_client_id, config.gcs_key)
  • get_context() Gets the current execution context containing file, user, and project information.

    Returns (class: Context): Current context object

  • get_api() Gets the main API object for accessing Anchorpoint functionality.

    Returns (class: Api): Main API object

File and System Operations

  • copy_files_to_clipboard(file_paths) Copies file paths to the system clipboard.

    Arguments

    • file_paths (list[str]): List of absolute file paths to copy
  • temp_dir() Gets the temporary directory path used by Anchorpoint.

    Returns (str): Absolute path to the temporary directory

  • join_project_path(path, project_id, workspace_id) Joins a path with project information for cross-project operations.

    Arguments

    • path (str): File or folder path
    • project_id (str): Target project identifier
    • workspace_id (str): Workspace identifier

Logging and Error Handling

  • log_error(message) Logs an error message to the Anchorpoint error log.

    Arguments

    • message (str): Error message to log

Action and Integration Management

  • create_action(yaml_path, action) Creates a new action from an Action object.

    Arguments

    • yaml_path (str): Path where the action YAML file should be created
    • action (class: Action): Action object containing action configuration
  • create_app_link(target) Creates an application link for files or tasks.

    Arguments

    • target (str or class: Task): File path or Task object to create link for

    Returns (str): Generated application link

  • open_integration_preferences(integration_name) Opens the preferences dialog for a specific integration.

    Arguments

    • integration_name (str): Name of the integration to configure

For timeline-related utilities and operations, see the Timeline documentation.

For version control-related utilities and operations, see the Timeline documentation.

For project-related utilities and operations, see the Project documentation.

Apsync Utilities

File Operations

  • copy_file(source, target, overwrite=False, workspace_id=None) Copies a file within the Anchorpoint workspace.

    Arguments

    • source (str): Source file path
    • target (str): Target file path
    • overwrite (bool): Whether to overwrite existing files
    • workspace_id (str): Optional workspace ID for cross-workspace operations
  • copy_folder(source, target, overwrite=False, workspace_id=None) Copies a folder within the Anchorpoint workspace.

    Arguments

    • source (str): Source folder path
    • target (str): Target folder path
    • overwrite (bool): Whether to overwrite existing folders
    • workspace_id (str): Optional workspace ID for cross-workspace operations
  • rename_file(source, target) Renames or moves a file.

    Arguments

    • source (str): Current file path
    • target (str): New file path
  • rename_folder(source, target) Renames or moves a folder.

    Arguments

    • source (str): Current folder path
    • target (str): New folder path

Template Operations

  • copy_file_from_template(source, target, variables={}, workspace_id=None) Copies a file from a template with variable substitution.

    Arguments

    • source (str): Template file path
    • target (str): Target file path
    • variables (dict[str, str]): Variables to substitute in the template
    • workspace_id (str): Optional workspace ID

    Returns (str): Path to the created file

  • copy_from_template(source, target, variables={}, skip_root=True, workspace_id=None) Copies files and folders from a template with variable substitution.

    Arguments

    • source (str): Template source path
    • target (str): Target path
    • variables (dict[str, str]): Variables to substitute
    • skip_root (bool): Whether to skip the root template folder
    • workspace_id (str): Optional workspace ID

    Returns (str): Path to the created content

  • create_template(path, name, workspace_id, type) Creates a template from existing content.

    Arguments

    • path (str): Path to create template from
    • name (str): Template name
    • workspace_id (str): Workspace identifier
    • type (class: TemplateType): Type of template to create
  • resolve_variables(text, variables) Resolves template variables in text.

    Arguments

    • text (str): Text containing variable placeholders
    • variables (dict[str, str]): Variables to substitute

    Returns (str): Text with resolved variables

For project-related utilities and operations, see the Project documentation.

User and Access Management

  • add_user_to_project(workspace_id, project_id, invited_from, email, access_level) Adds a user to a project.

    Arguments

    • workspace_id (str): Workspace identifier
    • project_id (str): Project identifier
    • invited_from (str): Email of user sending invitation
    • email (str): Email of user to add
    • access_level (class: AccessLevel): Access level for the user
  • remove_user_from_project(workspace_id, project_id, email) Removes a user from a project.

    Arguments

    • workspace_id (str): Workspace identifier
    • project_id (str): Project identifier
    • email (str): Email of user to remove
  • remove_user_from_workspace(workspace_id, email) Removes a user from a workspace.

    Arguments

    • workspace_id (str): Workspace identifier
    • email (str): Email of user to remove
  • get_workspace_access(workspace_id) Gets the current user's access level in a workspace.

    Arguments

    • workspace_id (str): Workspace identifier

    Returns (class: AccessLevel): User's access level

  • get_workspace_members(workspace_id) Gets all members of a workspace.

    Arguments

    • workspace_id (str): Workspace identifier

    Returns (class: WorkspaceMemberList): List of workspace members

  • get_project_members(workspace_id, project_id) Gets all members of a project.

    Arguments

    • workspace_id (str): Workspace identifier
    • project_id (str): Project identifier

    Returns (class: GroupMemberList): List of project members

For timeline-related utilities and operations, see the Timeline documentation.

For thumbnail-related utilities and operations, see the Thumbnails documentation.

File Metadata Operations

  • comment_file(file_path, comment) Adds or updates a comment on a file.

    Arguments

    • file_path (str): Path to file to comment on
    • comment (str or None): Comment text, or None to remove comment
  • set_folder_icon(folder_path, icon) Sets a custom icon for a folder.

    Arguments

    • folder_path (str): Path to folder
    • icon (class: Icon or None): Icon object or None to remove custom icon

System Configuration

  • get_api() Gets the main API object for apsync operations.

    Returns (class: Api): Main API object

  • get_api_version() Gets the current API version information.

    Returns (class: ApiVersion): API version object

  • configure_daemon(address, port) Configures the Anchorpoint daemon connection.

    Arguments

    • address (str): Daemon address
    • port (str): Daemon port
  • get_daemon_address() Gets the current daemon address.

    Returns (str): Daemon address

  • set_daemon_address(address) Sets the daemon address.

    Arguments

    • address (str): New daemon address
  • get_server_url() Gets the current server URL.

    Returns (str): Server URL

  • set_server_url(url) Sets the server URL.

    Arguments

    • url (str): New server URL
  • get_server_version() Gets the server version.

    Returns (str): Server version string

  • get_client_name() Gets the client name.

    Returns (str): Client name

  • set_client_name(name) Sets the client name.

    Arguments

    • name (str): New client name
  • set_account_email(email) Sets the account email.

    Arguments

    • email (str): Account email address

IPC (Inter-Process Communication)

  • ipc_publish(message) Publishes an IPC message.

    Arguments

  • ipc_get_message(topic) Gets an IPC message from a topic.

    Arguments

    • topic (str): Topic to get message from

    Returns (class: IpcMessage or None): Message object or None if no message

  • ipc_has_messages(topic) Checks if there are messages in a topic.

    Arguments

    • topic (str): Topic to check

    Returns (bool): True if there are messages

  • ipc_unsubscribe(topic) Unsubscribes from an IPC topic.

    Arguments

    • topic (str): Topic to unsubscribe from

File ID Management

  • get_file_id(path) Gets the unique ID for a file.

    Arguments

    • path (str): File path

    Returns (str): Unique file ID

  • get_folder_id(path) Gets the unique ID for a folder.

    Arguments

    • path (str): Folder path

    Returns (str): Unique folder ID

  • get_file_by_id(id, project=None) Gets file path from its unique ID.

    Arguments

    • id (str): File ID
    • project (class: Project): Optional project context

    Returns (str or None): File path or None if not found

  • get_folder_by_id(id, project=None) Gets folder path from its unique ID.

    Arguments

    • id (str): Folder ID
    • project (class: Project): Optional project context

    Returns (str or None): Folder path or None if not found

Dynamic Module Loading

  • import_local(relative_path, reload) Imports a local Python module dynamically.

    Arguments

    • relative_path (str): Relative path to the Python module
    • reload (bool): Whether to reload the module if already loaded

    Returns (object): Imported module object

Utility Classes

APConfig Class

The APConfig class provides default configuration values for various integrations and services used by Anchorpoint.

Properties

  • gcs_client_id (str): Google Cloud Storage client ID for integration
  • gcs_key (str): Google Cloud Storage API key
  • github_client_id (str): GitHub OAuth client ID for integration
  • github_client_key (str): GitHub OAuth client secret
  • gitlab_client_id (str): GitLab OAuth client ID for integration
  • gitlab_client_key (str): GitLab OAuth client secret

Action Class

The Action class represents an Anchorpoint action configuration that can be used to create new actions programmatically.

Constructor

  • Action() Creates a new Action instance.

Properties

  • author (str): Author of the action
  • category (str): Category for organizing the action
  • description (str): Description of what the action does
  • file_registration (str): File filter pattern for when action should appear
  • folder_registration (str): Folder filter pattern for when action should appear
  • icon (str): Icon path or identifier for the action
  • id (str): Unique identifier for the action
  • is_python (bool): Whether the action uses Python scripting
  • name (str): Display name of the action
  • script (str): Script file path or content for the action

Examples

Application Detection and Setup

import anchorpoint
import os

def check_required_applications():
"""Check if required applications are installed"""

# Define application paths to check
apps_to_check = [
("C:/Program Files/Blender Foundation/Blender 3.6/blender.exe", "Blender 3D", "Blender"),
("C:/Program Files/Autodesk/Maya2024/bin/maya.exe", "Autodesk Maya", "Maya"),
("C:/Program Files/Adobe/Adobe Photoshop 2024/Photoshop.exe", "Adobe Photoshop", "Photoshop")
]

available_apps = []

for app_path, info, name in apps_to_check:
if anchorpoint.check_application(app_path, info, name):
available_apps.append(name)
print(f"✓ {name} is available")
else:
print(f"✗ {name} not found at {app_path}")

return available_apps

# Check applications
available = check_required_applications()
print(f"\nFound {len(available)} applications: {', '.join(available)}")

File Operations and Backup

import apsync
import anchorpoint
import os

ctx = anchorpoint.get_context()

def manage_file_operations():
"""Demonstrate file operations and organization"""

if not ctx.path or not os.path.isfile(ctx.path):
ui = anchorpoint.UI()
ui.show_error("Invalid Selection", "Please select a file to process")
return

try:
# Copy current file to a backup location
backup_dir = os.path.join(ctx.folder, "backups")
os.makedirs(backup_dir, exist_ok=True)

backup_path = os.path.join(backup_dir, f"backup_{ctx.filename}")
apsync.copy_file(ctx.path, backup_path, overwrite=True, workspace_id=ctx.workspace_id)
print(f"Created backup: {backup_path}")

# Add comment to the original file
apsync.comment_file(ctx.path, f"Backup created on {datetime.now().strftime('%Y-%m-%d %H:%M')}")

# Add timeline entry for the backup action
apsync.add_timeline_entry(ctx.path, f"Created backup of {ctx.filename}")

print(f"File operations completed for: {ctx.filename}")

except Exception as e:
anchorpoint.log_error(f"File operations failed: {str(e)}")
print(f"Error: {e}")

manage_file_operations()

Template System Usage

import apsync
import anchorpoint
import os
from datetime import datetime

ctx = anchorpoint.get_context()

def batch_organize_assets():
"""Organize and process multiple asset files"""

if not ctx.selected_files:
ui = anchorpoint.UI()
ui.show_info("No Selection", "Please select files to organize")
return

# Create organized folder structure
base_path = ctx.folder
folders = {
'textures': ['jpg', 'png', 'tiff', 'exr', 'hdr'],
'models': ['fbx', 'obj', 'ma', 'mb', 'blend', 'max'],
'audio': ['wav', 'mp3', 'ogg', 'aiff'],
'videos': ['mp4', 'avi', 'mov', 'mkv']
}

# Create folders
for folder_name in folders.keys():
folder_path = os.path.join(base_path, folder_name)
os.makedirs(folder_path, exist_ok=True)

moved_files = []

for file_path in ctx.selected_files:
filename = os.path.basename(file_path)
file_ext = os.path.splitext(filename)[1][1:].lower()

# Find appropriate folder
target_folder = None
for folder_name, extensions in folders.items():
if file_ext in extensions:
target_folder = folder_name
break

if target_folder:
# Move file to appropriate folder
target_path = os.path.join(base_path, target_folder, filename)

try:
apsync.rename_file(file_path, target_path)
moved_files.append((filename, target_folder))

# Add comment about the organization
apsync.comment_file(target_path, f"Organized on {datetime.now().strftime('%Y-%m-%d %H:%M')}")

print(f"Moved {filename} to {target_folder}/")

except Exception as e:
anchorpoint.log_error(f"Failed to move {filename}: {str(e)}")
print(f"Error moving {filename}: {e}")

# Create summary timeline entry
if moved_files:
summary = f"Organized {len(moved_files)} files into folders"
apsync.add_timeline_entry(base_path, summary)
print(f"\nSummary: {summary}")

batch_organize_assets()

Template System Usage

import apsync
import anchorpoint
import os

ctx = anchorpoint.get_context()

def create_project_from_template():
"""Create a new project structure from a template"""

# Define template variables
variables = {
"PROJECT_NAME": "MyAwesomeGame",
"CLIENT_NAME": "Epic Games",
"PROJECT_CODE": "EG001",
"CREATION_DATE": "2025-11-15"
}

# Template source (could be a shared template directory)
template_source = "/templates/game_project_template"
target_path = os.path.join(ctx.path, variables["PROJECT_NAME"])

try:
# Copy template with variable substitution
created_path = apsync.copy_from_template(
template_source,
target_path,
variables=variables,
skip_root=True,
workspace_id=ctx.workspace_id
)

print(f"Created project structure at: {created_path}")

# Resolve variables in template text
readme_template = "Project: {{PROJECT_NAME}} for {{CLIENT_NAME}}"
readme_content = apsync.resolve_variables(readme_template, variables)
print(f"README content: {readme_content}")

# Add timeline entry for the template creation
apsync.add_timeline_entry(created_path, f"Project structure created from template")

return created_path

except Exception as e:
anchorpoint.log_error(f"Template project creation failed: {str(e)}")
print(f"Error creating project from template: {e}")
return None

# Create project structure
project_path = create_project_from_template()