Event Hooks#

Beside writing powerful actions that extend the UI of Anchorpoint through a registration, Anchorpoint offers a set of event hooks that can be implemented in Python. Every time a certain event is happening within the application, a Python callback is triggered.

To get started, simply implement one of the following callback functions within an existing action. Of course, you can also create a new action - a registration is not required. Each callback gets passed a unique set of arguments. One argument is the same for all actions: The current anchorpoint.Context object which contains the state of the current active browser state.

Note

By loading up a Python script, the entire non-guarded code is executed, hence you might observe unwanted side effects if you don’t guard your code.

This becomes especially important when mixing event hook callbacks with normal action code make sure to guard your normal code using the infamous if __name__ == __main__: syntax.

Example:

import anchorpoint as ap

def on_timeout(ctx: ap.Context):
   # This code will be automatically executed once every minute
   print("timeout callback")

if __name__ == __main__:
   # This code will be executed when the user triggers the action
   print("Action Invoked!")

on_timeout#

on_timeout(ctx: anchorpoint.Context) None#

This function is called once every minute. Userful to check certain state on the file system, for example.

Example:

>>> def on_timeout(ctx: ap.Context):
>>>     # This code will be automatically executed once every minute
>>>     print("timeout callback")

on_folder_opened#

on_folder_opened(ctx: anchorpoint.Context) None#

This function is called whenever the user navigates to a folder in Anchorpoint.

Example:

>>> def on_folder_opened(ctx: ap.Context):
>>>     print("folder opened: " + ctx.path)

on_project_directory_changed#

on_project_directory_changed(ctx: anchorpoint.Context) None#

Called whenever a change within the project directory is detected, e.g. when a file was modified. This only works for the active project in Anchorpoint.

Example:

>>> def on_project_directory_changed(ctx: ap.Context):
>>>     print("something has changed")

on_application_started#

on_application_started(ctx: anchorpoint.Context) None#

Called once for each workspace on startup of Anchorpoint.

Example:

>>> def on_application_started(ctx: ap.Context):
>>>     print("application has started")

on_application_closing#

on_application_closing(ctx: anchorpoint.Context) None#

Called just before Anchorpoint is closing.

Example:

>>> def on_application_closing(ctx: ap.Context):
>>>     print("application is closing")

Task Hooks#

on_task_created(task_id: str, source: anchorpoint.ChangeSource, ctx: anchorpoint.Context) None#

Called when a task has been created.

Example:

>>> def on_task_created(task_id, src, ctx):
>>>    api = ap.get_api()
>>>    task = api.tasks.get_task_by_id(task_id)
>>>    print(f"Task {task.name} created")
on_task_changed(task_id: str, source: anchorpoint.ChangeSource, ctx: anchorpoint.Context) None#

Called when a task has been changed.

on_task_removed(task_id: str, source: anchorpoint.ChangeSource, ctx: anchorpoint.Context) None#

Called when a task has been removed.

class anchorpoint.ChangeSource(value: int)#

Members:

You : The change was made by yourself

Action : The change was made by an action on your machine

Other : The change was made by someone else

on_attributes_changed#

anchorpoint.on_attributes_changed(parent_path: str, attributes: list[anchorpoint.AttributeChange], ctx: anchorpoint.Context) None#

This function is called when attributes have changed. The list of AttributeChange is provided for a specific parent_path. You can check the ChangeSource of the attribute change. The source is You if you have changed the attribute in the Anchorpoint UI, for example.

Example:

>>> def on_attributes_changed(parent_path: str, attributes: list[ap.AttributeChange], ctx: ap.Context):
>>> print("attributes have changed")
>>>     for attribute in attributes:
>>>        if attribute.task_id:
>>>             task = ap.get_api().tasks.get_task_by_id(attribute.task_id)
>>>             print(f"attribute of name {attribute.name} has changed from {attribute.old_value} to {attribute.value} for object {task.name}")
>>>        else:
>>>             print(f"attribute of name {attribute.name} has changed from {attribute.old_value} to {attribute.value} for object {attribute.path}")
class anchorpoint.AttributeChange#

Represents a value change of an attribute called name. Access the old_value and the new value. Using the type property you can check the type of the attribute (e.g. single_choice_tag). The source value can be used to identify the source of the trigger:

  • You: The change was made by yourself

  • Action: The change was made by an action on your machine

  • Other: The change was made by someone else

For Other, you can check the client_name (e.g. UnrealEngine) with source_value

path#

The path of the object the attribute was changed for - or None

Type

str

task_id#

The id of the task the attribute was changed for - or None

Type

str

object_type#

The type of the object

Type

ObjectType

name#

The name of the Attribute

Type

str

type#

The type of the attribute

Type

AttributeType

value#

The new value of the attribute

Type

object

old_value#

The old value of the attribute

Type

object

source#

The source of the change

Type

ChangeSource

source_value#

The client_name of the Other source, if any

Type

str

on_is_action_enabled#

This is a special event hook that is called when Anchorpoint checks whether or not an action should be presented to the user. To make this hook work you have to tell Anchorpoint in the YAML when to call the hook:

register:
    folder:
        enable: script_with_hook.py
anchorpoint.on_is_action_enabled(path: str, type: anchorpoint.Type, ctx: anchorpoint.Context) bool#
Args:

path (str): The path that should be used to check if the action is enabled. Might be different to ctx.path

type (Type): The type of the action

ctx (Context): The context of the current browser

Example:

>>> def on_is_action_enabled(path: str, type: anchorpoint.Type, ctx: anchorpoint.Context) :
>>>     # Enable the action when the path contains the word "shot"
>>>     return "shot" in path: