Context#

class anchorpoint.Context#
The context object is your link between Anchorpoint and the world of actions.

It provides you with important information such as the list of selected files or folders, for example. Furthermore, there is a lot of information from the active YAML file, such as defined inputs that the user has entered.

In addition, the context offers a variety of helpful functions that simplify working with actions in Anchorpoint.

You never create the context yourself, instead you can always retrieve it via the instance() function.

Examples:
Retrieving the active context instance is simple:
>>> import anchorpoint
>>> ctx = anchorpoint.Context.instance()
Access an input “my_input” from a YAML file by providing the key to the inputs dictionary like so:
>>> ctx.inputs["my_input"]
42
Iterate over all selected files:
>>> for f in ctx.selected_files:
>>>     print(f)
Attributes:

type (Type): Type.File if the action is running on a file selection, Type.Folder when running on a folder selection.

inputs (dict): A dictionary that passes the inputs from the YAML file to the script. The key to the dictionary is the name of the input.

path (str): The absolute path to the current file or folder. For a multi selection this is the file / folder the context menu was invoked on.

relative_path (str): Project only, the path of the file / folder relative to the project root

project_path (str): The project path, if any

yaml_dir (str): The directory where the action’s YAML lives

folder (str): The parent folder of path

filename (str): File only, the name of the file without the path and without the extension

suffix (str): The suffix of the file (e.g. “blend”)

username (str): The username of the current user, e.g. “John Doe”

email (str): The email of the current user

workspace_id (str): The unique id of the workspace the action is executed in

selected_files (list): The list of selected files (absolute paths)

selected_folders (list): The list of selected folders (absolute paths)

icon (str): The icon as set in the YAML file

icon_color (str): The icon color as set in the YAML file

create_project(path: str, name: str, workspace_id: Optional[str] = None) object#

Create a new project at path. Will create a new folder if necessary.

Parameters
  • path (str) – The path to the project

  • name (str) – The name of the project

  • workspace_id (Optional[str]) – The workspace id - or None to use the user workspace

Example

>>> ctx = anchorpoint.Context.instance()
>>> ctx.create_project("C:/Projects/AP-Commercial", "Anchorpoint Commercial")
install(package: str, upgrade: bool = False) None#

Utility function to pip install a python module to the global python module directory. To not slow down your scripts make sure to only call this function when the module import fails

Parameters
  • package (str) – The name of the package to install (e.g. “Pillow”)

  • upgrade (bool) – Set to True to upgrade the package to the latest version

Example

>>> ctx = anchorpoint.Context.instance()
>>> try:
>>>     from PIL import Image
>>> except:
>>>     ctx.install("Pillow")
static instance() anchorpoint.Context#

Returns the active instance of the anchorpoint context.

Example

>>> ctx = anchorpoint.Context.instance()
run_async(func: function, *args, **kwargs) None#

Utility function to run a function asynchronously so that it does not block the Anchorpoint UI. Always use this for long running processes such as downloading files or running a rendering job. Note: Make sure to capture the Anchorpoint context object on the main thread.

Parameters
  • func (Callable[[*args, **kwargs], None]) – The function to run async

  • args (**kwargs) – The optional arguments for the function

  • args – The optional keyword arguments for the function

Example

Run a function with arguments
>>> ctx = anchorpoint.Context.instance()
>>> def my_func(path):
>>>     print("async: " + path)
>>>
>>> ctx.run_async(my_func, ctx.path)
class anchorpoint.Type(value: int)#

Members:

File

Folder

NewFile

NewFolder

Drive

NewDrive

AddProjectFiles

JoinProjectFiles

Sidebar

ActionEnabled

SwitchBranch

CreateBranch

ResolveConflicts

PendingChangesAction

LoadTimelineChannelPendingChanges

ApplicationClosing

ApplicationStarted

ProjectDirectoryChanged

TimelineChannelAction

LoadTimelineChannelEntryDetails

LoadTimelineChannelInfo

LoadTimelineChannelEntries

FolderOpened

TimeInterval

TimelineDetailAction

AttributesChanged