Attributes#
The Attributes class can be used to set and read attributes on files, folders, and tasks. Use the apsync.Api object to access a set up instance. A fully-fledged example that sets attributes on all selected files and folders can be found on GitHub.
- class apsync.Attributes#
- create_attribute(name: str, type: apsync.AttributeType, tags: Optional[Union[apsync.AttributeTagList, list]] = None, rating_max: Optional[int] = None) apsync.Attribute #
Creates a new attribute in the workspace or project
- Parameters
name – str: The name of the attribute (e.g. Status)
type (
AttributeType
) – The attribute typetags (list[
AttributeTag
]) – The list of tags to create - or Nonerating_max – The maximum rating, or None. Only valid for rating attributes
Example
>>> tags = [apsync.AttributeTag("Work in Progress", apsync.TagColor.yellow)] >>> api.attributes.create_attribute("Status", apsync.AttributeType.single_choice_tag, tags=tags)
- get_attribute(name: str, type: Optional[apsync.AttributeType] = None) Optional[apsync.Attribute] #
Returns the attribute or None
- Parameters
name – str: The name of the attribute (e.g. Status)
type (
AttributeType
) – The attribute type to filter for or None
Example
>>> attribute = api.attributes.get_attribute("Status", apsync.AttributeType.single_choice_tag)
- get_attribute_by_id(id: str) apsync.Attribute #
Returns the attribute with a given id.
- Parameters
id (str) – The id of the attribute
Example
>>> attribute = api.attributes.get_attribute_by_id(some_id)
- get_attribute_value(target: Union[apsync.Task, str], attribute: Union[apsync.Attribute, str]) object #
Retrieves the content of an attribute for a given file or folder.
- Parameters
- Returns
The attribute value, or None.
Example
>>> value = apsync.get_attribute_value("image.png", "status")
- get_attributes(type: Optional[apsync.AttributeType] = None) List[apsync.Attribute] #
Returns all attributes, possibly filtered with a type.
- Parameters
type (
AttributeType
) – The attribute type to filter for or None
Example
>>> attributes = api.attributes.get_attributes()
- rename_attribute(attribute: apsync.Attribute, name: str) None #
Renames the attribute
- Parameters
attribute (
Attribute
) – The attribute to updatename (str) – The new name
Example
>>> attribute = api.attributes.get_attribute("Status") >>> api.attributes.rename_attribute(attribute, "State")
- set_attribute_rating_max(attribute: apsync.Attribute, max: int) None #
Sets the maximum rating for a rating attribute
- Parameters
attribute (
Attribute
) – The attribute to updatemax (int) – The new maximum
Example
>>> attribute = api.attributes.get_attribute("Quality") >>> api.attributes.set_attribute_rating_max(attribute, 10)
- set_attribute_tags(attribute: apsync.Attribute, tags: apsync.AttributeTagList) None #
Sets the available tags for a single or multiple choice tag attribute
- Parameters
attribute (
Attribute
) – The attribute to updatetags (list[
AttributeTag
]) – The list of tags to create
Example
>>> attribute = api.attributes.get_attribute("Status") >>> tags = [apsync.AttributeTag("Done", "green")] >>> api.attributes.set_attribute_tags(attribute, tags)
- set_attribute_value(target: Union[apsync.Task, str], attribute: Union[apsync.Attribute, str], value: Union[int, str, List[str], apsync.AttributeTag, apsync.AttributeTagList, object, bool], update_timeline: bool = False) None #
Sets the value of an attribute for a given file or folder. Creates the attribute if it cannot be found. See examples on GitHub: https://github.com/Anchorpoint-Software/ap-actions/tree/main/examples/attributes
- Parameters
Examples
>>> api.attributes.set_attribute_value("asset.blend", "notes", "polygon count is too high") >>> api.attributes.set_attribute_value("asset.blend", "artist", "support@anchorpoint.app")
- class apsync.AttributeType(type: str)#
The AttributeType class is used to identify the type of an attribute.
- single_choice_tag#
Represents a single choice tag attribute
- Type
- multiple_choice_tag#
Represents a multiple choice tag attribute
- Type
- text#
Represents a text
- Type
- user#
Represents a user
- Type
apsync.user
- rating#
Represents a rating
- Type
- hyperlink#
Represents a hyperlink
- Type
- date#
Represents a date
- Type
- checkbox#
Represents a checkbox
- Type
- timestamp#
Represents a timestamp / time tracking attribute
- Type
Example
>>> type = apsync.AttributeType.rating
- class apsync.Attribute#
- property id: str#
str
- Type
type
- property name: str#
str
- Type
type
- property rating_max: Optional[int]#
typing.Optional[int]
- Type
type
- property tags: apsync.AttributeTagList#
AttributeTagList
- Type
type
- property type: apsync.AttributeType#
AttributeType
- Type
type
- class apsync.AttributeTag(name: str)#
- class apsync.AttributeTag(name: str, color: TagColor)
- class apsync.AttributeTag(name: str, color: str)
The AttributeTag class represents a single or multiple choice tag.
- id#
The unique id of the attribute
- Type
str
- name#
The name of the attribute
- Type
str
- color#
The color of the tag
- Type
TagColor
Example
>>> apsync.AttributeTag("Work in Progress", "yellow")
- property color: apsync.TagColor#
TagColor
- Type
type
- property id: str#
str
- Type
type
- property name: str#
str
- Type
type
Copy and Rename#
When copying or renaming files and folders in Anchorpoint, metadata such as attributes are adjusted on the server. Unfortunately, this information is lost when doing rename and copy operations through the OS. Instead, use the following utility functions:
- apsync.copy_from_template(source: str, target: str, variables: Dict[str, str] = {}, skip_root: bool = True, workspace_id: Optional[str] = None) str #
Copies the source (template) folder to the target path and adjusts the metadata (e.g. attributes). Pass a python dictionary of variables that are applied to the folder and all the content of the folder. Raises an exeception when the target folder already exists, use os.remove to delete a folder.
- Parameters
source (str) – The source path
target (str) – The target path
variables (dict) – The variables that are resolved, see example
skip_root (bool) – If true, the root folder of source is skipped
workspace_id (Optional[str]) – Apply the changes in this workspace, or the user workspace if not set
- Returns
The newly created target folder
Example
>>> variables = { >>> "[project]": "Commercial", >>> "[client]": "Anchorpoint" >>> } >>> >>> apsync.copy_from_template("C:/Templates/[client]_[project]", "C:/Projects/[client]_[project]", variables) "C:/Projects/Anchorpoint_Commercial"
- apsync.copy_file_from_template(source: str, target: str, variables: Dict[str, str] = {}, workspace_id: Optional[str] = None) str #
Copies the source (template) folder to the target path and copies the metadata for the files (e.g. reviews). Pass a python dictionary of variables that are applied to the content of the folder. Raises an exeception when the target folder already exists, use os.remove to delete a folder.
- Parameters
source (str) – The source path
target (str) – The target path
variables (dict) – The variables that are resolved, see example
workspace_id (Optional[str]) – Apply the changes in this workspace, or the user workspace if not set
- Returns
The newly created target folder
Example
>>> variables = { >>> "[project]": "Commercial", >>> "[client]": "Anchorpoint" >>> } >>> >>> apsync.copy_file_from_template("C:/Templates/[client]_[project]", "C:/Projects/[client]_[project]", variables) "C:/Projects/Anchorpoint_Commercial"
- apsync.copy_file(source: str, target: str, overwrite: bool = False, workspace_id: Optional[str] = None) None #
Copies the file from source to target including all metadata (e.g. reviews). Raises an exeception when overwrite is False and target already exists.
- Parameters
source (str) – The source file
target (str) – The target file
overwrite (bool) – Overwrite the target file
workspace_id (Optional[str]) – Apply the changes in this workspace, or the user workspace if not set
Example
>>> apsync.copy_file(source, target, True)
- apsync.copy_folder(source: str, target: str, overwrite: bool = False, workspace_id: Optional[str] = None) None #
Copies the entire content from source_folder to the target_folder, including all metadata (e.g. attributes). Raises an exeception when overwrite is False and there is conflicts in the target_folder
- Parameters
source_folder (str) – The source folder
target_folder (str) – The target folder
overwrite (bool) – Overwrite target_folder
workspace_id (Optional[str]) – Apply the changes in this workspace, or the user workspace if not set
Example
>>> apsync.copy_folder(source, target, True)
- apsync.rename_file(source: str, target: str) None #
Renames the source file to the target name and adjusts the metadata (e.g. attributes). Raises an exeception when the target file already exists, use os.remove to delete a file.
- Parameters
source (str) – The source file
target (str) – The target file
Example
>>> apsync.rename_file(source, target)
- apsync.rename_folder(source: str, target: str) None #
Renames the source folder to the target name and adjusts the metadata (e.g. attributes). Raises an exeception when the target folder already exists, use os.remove to delete a folder.
- Parameters
source (str) – The source file
target (str) – The target file
Example
>>> apsync.rename_folder(source, target)
- apsync.resolve_variables(text: str, variables: Dict[str, str]) str #
Takes an input text, e.g. “C:/Projects/[client]_[project]” and converts it to a resolved text, e.g. “C:/Projects/anchorpoint_commercial”. Pass a python dictionary of variables where the values are the resolved variables (see example)
- Parameters
text (str) – The source text
variables (dict) – The variables that are resolved, see example
- Returns
The text with resolved variables
Example
>>> variables = { >>> "[project]": "Commercial", >>> "[client]": "Anchorpoint" >>> } >>> >>> apsync.resolve_variables("C:/Projects/[client]_[project]", "C:/Projects/[client]_[project]", variables) "C:/Projects/Anchorpoint_Commercial"