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 executableinfo(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 IDgcs_key(str): Google Cloud Storage OAuth client keygithub_client_id(str): GitHub OAuth client IDgithub_client_key(str): GitHub OAuth client keygitlab_client_id(str): GitLab OAuth client IDgitlab_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 pathproject_id(str): Target project identifierworkspace_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
-
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 pathtarget(str): Target file pathoverwrite(bool): Whether to overwrite existing filesworkspace_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 pathtarget(str): Target folder pathoverwrite(bool): Whether to overwrite existing foldersworkspace_id(str): Optional workspace ID for cross-workspace operations
-
rename_file(source, target)Renames or moves a file.Arguments
source(str): Current file pathtarget(str): New file path
-
rename_folder(source, target)Renames or moves a folder.Arguments
source(str): Current folder pathtarget(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 pathtarget(str): Target file pathvariables(dict[str, str]): Variables to substitute in the templateworkspace_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 pathtarget(str): Target pathvariables(dict[str, str]): Variables to substituteskip_root(bool): Whether to skip the root template folderworkspace_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 fromname(str): Template nameworkspace_id(str): Workspace identifiertype(class: TemplateType): Type of template to create
-
resolve_variables(text, variables)Resolves template variables in text.Arguments
text(str): Text containing variable placeholdersvariables(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 identifierproject_id(str): Project identifierinvited_from(str): Email of user sending invitationemail(str): Email of user to addaccess_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 identifierproject_id(str): Project identifieremail(str): Email of user to remove
-
remove_user_from_workspace(workspace_id, email)Removes a user from a workspace.Arguments
workspace_id(str): Workspace identifieremail(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 identifierproject_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 oncomment(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 foldericon(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 addressport(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
message(class: IpcMessage): Message to publish
-
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 IDproject(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 IDproject(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 modulereload(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 integrationgcs_key(str): Google Cloud Storage API keygithub_client_id(str): GitHub OAuth client ID for integrationgithub_client_key(str): GitHub OAuth client secretgitlab_client_id(str): GitLab OAuth client ID for integrationgitlab_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 actioncategory(str): Category for organizing the actiondescription(str): Description of what the action doesfile_registration(str): File filter pattern for when action should appearfolder_registration(str): Folder filter pattern for when action should appearicon(str): Icon path or identifier for the actionid(str): Unique identifier for the actionis_python(bool): Whether the action uses Python scriptingname(str): Display name of the actionscript(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()