Skip to content

api

Public API

Anything that isn't defined here is INTERNAL and unreliable for external use.

WrapHost

Bases: HostBase, ILoadHost

Source code in client/ayon_wrap/api/pipeline.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class WrapHost(HostBase, ILoadHost):
    name = "wrap"

    def __init__(self, workfile_path):
        self._workfile_path = workfile_path
        super(WrapHost, self).__init__()

    def install(self):
        print("Installing Wrap host...")

        pyblish.api.register_host("wrap")
        pyblish.api.register_plugin_path(PUBLISH_PATH)

        register_loader_plugin_path(LOAD_PATH)
        register_creator_plugin_path(CREATE_PATH)
        self.log.debug(PUBLISH_PATH)

    def get_containers(self):
        """Get list of loaded containers.

        Containers are created by filling prepared placeholders with publish
        path of chosen representation and storing this metadata into the
        workfile.

        Returns:
            (list of dict with schema similar to "openpype:container-2.0" -
             "nodeId" added to point to node in Wrap)
        """
        with open(self._workfile_path, "r") as f:
            content = json.load(f)

            metadata = (content.get("metadata", {})
                               .get("AYON_NODE_METADATA", []))

        containers = []
        for item in metadata:
            if item["id"] == AVALON_CONTAINER_ID:
                containers.append(item)

        return containers

get_containers()

Get list of loaded containers.

Containers are created by filling prepared placeholders with publish path of chosen representation and storing this metadata into the workfile.

Returns:

Type Description

(list of dict with schema similar to "openpype:container-2.0" - "nodeId" added to point to node in Wrap)

Source code in client/ayon_wrap/api/pipeline.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def get_containers(self):
    """Get list of loaded containers.

    Containers are created by filling prepared placeholders with publish
    path of chosen representation and storing this metadata into the
    workfile.

    Returns:
        (list of dict with schema similar to "openpype:container-2.0" -
         "nodeId" added to point to node in Wrap)
    """
    with open(self._workfile_path, "r") as f:
        content = json.load(f)

        metadata = (content.get("metadata", {})
                           .get("AYON_NODE_METADATA", []))

    containers = []
    for item in metadata:
        if item["id"] == AVALON_CONTAINER_ID:
            containers.append(item)

    return containers

containerise(name, namespace, context, loader=None, data=None)

Containerisation enables a tracking of version, author and origin for loaded assets.

Creates dictionary payloads that gets saved into file metadata. Each container contains of who loaded (loader) and members (single or multiple in case of background).

Parameters:

Name Type Description Default
name str

Name of resulting assembly

required
namespace str

Namespace under which to host container

required
context dict

Asset information

required
loader str

Name of loader used to produce this container.

None
data dict

additional data to store placeholder, nodeId and node_name

None

Returns:

Name Type Description
container str

Name of container assembly

Source code in client/ayon_wrap/api/pipeline.py
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def containerise(name,
                 namespace,
                 context,
                 loader=None,
                 data=None):
    """
    Containerisation enables a tracking of version, author and origin
    for loaded assets.

    Creates dictionary payloads that gets saved into file metadata. Each
    container contains of who loaded (loader) and members (single or multiple
    in case of background).

    Arguments:
        name (str): Name of resulting assembly
        namespace (str): Namespace under which to host container
        context (dict): Asset information
        loader (str, optional): Name of loader used to produce this container.
        data (dict): additional data to store placeholder, nodeId and node_name

    Returns:
        container (str): Name of container assembly
    """
    data = {
        "schema": "openpype:container-2.0",
        "id": AVALON_CONTAINER_ID,
        "name": name,
        "namespace": namespace,
        "loader": str(loader),
        "representation": str(context["representation"]["id"]),
        "original_value": data["original_value"],
        "nodeId": data["nodeId"],
        "objectName": data["node_name"]
    }

    return data

fill_placeholder(placeholder, workfile_path, context)

Replaces placeholder with actual path to representation

Parameters:

Name Type Description Default
placeholder str

in format PLACEHOLDER_VALUE_PATTERN

required
workfile_path str

absolute path to opened workfile

required
context dict

contains context data from launch context

required

Returns: (dict, str) path to resolved representation file which should be used instead of placeholder Raises (PlaceholderFillException) if path cannot be resolved (cannot find product, version etc.)

Source code in client/ayon_wrap/api/lib.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def fill_placeholder(placeholder, workfile_path, context):
    """Replaces placeholder with actual path to representation

    Args:
        placeholder (str): in format PLACEHOLDER_VALUE_PATTERN
        workfile_path (str): absolute path to opened workfile
        context (dict): contains context data from launch context
    Returns:
        (dict, str) path to resolved representation file which should be used
            instead of placeholder
    Raises
        (PlaceholderFillException) if path cannot be resolved (cannot find
        product, version etc.)

    """
    token_and_values = get_token_and_values(placeholder)

    project_name = context["project_name"]

    folder_token = token_and_values["folder_token"]
    folder_entity = _get_folder_entity(project_name, folder_token, context)
    folder_id = folder_entity["id"]

    product_name = token_and_values["product_name"]
    product_id = _get_product_id(
        project_name,
        folder_id,
        product_name,
        folder_entity["path"]
    )

    version_val = token_and_values["version"]
    version_id = _get_version(
        project_name,
        product_name,
        product_id,
        version_val,
        workfile_path
    )

    ext = token_and_values["ext"]
    repre, repre_path = _get_repre_and_path(
        project_name, product_name, ext, version_id)

    return repre, repre_path