Skip to content

legacy_create

Create workflow moved from avalon-core repository.

Renamed classes and functions - 'Creator' -> 'LegacyCreator' - 'create' -> 'legacy_create'

LegacyCreator

Determine how assets are created

Source code in client/ayon_core/pipeline/create/legacy_create.py
 17
 18
 19
 20
 21
 22
 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
 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
class LegacyCreator:
    """Determine how assets are created"""
    label = None
    product_type = None
    defaults = None
    maintain_selection = True
    enabled = True

    dynamic_product_name_keys = []

    log = logging.getLogger("LegacyCreator")
    log.propagate = True

    def __init__(self, name, folder_path, options=None, data=None):
        self.name = name  # For backwards compatibility
        self.options = options

        # Default data
        self.data = collections.OrderedDict()
        # TODO use 'AYON_INSTANCE_ID' when all hosts support it
        self.data["id"] = AYON_INSTANCE_ID
        self.data["productType"] = self.product_type
        self.data["folderPath"] = folder_path
        self.data["productName"] = name
        self.data["active"] = True

        self.data.update(data or {})

    @classmethod
    def apply_settings(cls, project_settings):
        """Apply AYON settings to a plugin class."""

        host_name = os.environ.get("AYON_HOST_NAME")
        plugin_type = "create"
        plugin_type_settings = (
            project_settings
            .get(host_name, {})
            .get(plugin_type, {})
        )
        global_type_settings = (
            project_settings
            .get("core", {})
            .get(plugin_type, {})
        )
        if not global_type_settings and not plugin_type_settings:
            return

        plugin_name = cls.__name__

        plugin_settings = None
        # Look for plugin settings in host specific settings
        if plugin_name in plugin_type_settings:
            plugin_settings = plugin_type_settings[plugin_name]

        # Look for plugin settings in global settings
        elif plugin_name in global_type_settings:
            plugin_settings = global_type_settings[plugin_name]

        if not plugin_settings:
            return

        cls.log.debug(">>> We have preset for {}".format(plugin_name))
        for option, value in plugin_settings.items():
            if option == "enabled" and value is False:
                cls.log.debug("  - is disabled by preset")
            else:
                cls.log.debug("  - setting `{}`: `{}`".format(option, value))
            setattr(cls, option, value)

    def process(self):
        pass

    @classmethod
    def get_dynamic_data(
        cls, project_name, folder_entity, task_entity, variant, host_name
    ):
        """Return dynamic data for current Creator plugin.

        By default return keys from `dynamic_product_name_keys` attribute
        as mapping to keep formatted template unchanged.

        ```
        dynamic_product_name_keys = ["my_key"]
        ---
        output = {
            "my_key": "{my_key}"
        }
        ```

        Dynamic keys may override default Creator keys (productType, task,
        folderPath, ...) but do it wisely if you need.

        All of keys will be converted into 3 variants unchanged, capitalized
        and all upper letters. Because of that are all keys lowered.

        This method can be modified to prefill some values just keep in mind it
        is class method.

        Args:
            project_name (str): Context's project name.
            folder_entity (dict[str, Any]): Folder entity.
            task_entity (dict[str, Any]): Task entity.
            variant (str): What is entered by user in creator tool.
            host_name (str): Name of host.

        Returns:
            dict: Fill data for product name template.
        """
        dynamic_data = {}
        for key in cls.dynamic_product_name_keys:
            key = key.lower()
            dynamic_data[key] = "{" + key + "}"
        return dynamic_data

    @classmethod
    def get_product_name(
        cls, project_name, folder_entity, task_entity, variant, host_name=None
    ):
        """Return product name created with entered arguments.

        Logic extracted from Creator tool. This method should give ability
        to get product name without the tool.

        TODO: Maybe change `variant` variable.

        By default is output concatenated product type with variant.

        Args:
            project_name (str): Context's project name.
            folder_entity (dict[str, Any]): Folder entity.
            task_entity (dict[str, Any]): Task entity.
            variant (str): What is entered by user in creator tool.
            host_name (str): Name of host.

        Returns:
            str: Formatted product name with entered arguments. Should match
                config's logic.
        """

        dynamic_data = cls.get_dynamic_data(
            project_name, folder_entity, task_entity, variant, host_name
        )
        task_name = task_type = None
        if task_entity:
            task_name = task_entity["name"]
            task_type = task_entity["taskType"]
        return get_product_name(
            project_name,
            task_name,
            task_type,
            host_name,
            cls.product_type,
            variant,
            dynamic_data=dynamic_data
        )

apply_settings(project_settings) classmethod

Apply AYON settings to a plugin class.

Source code in client/ayon_core/pipeline/create/legacy_create.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
@classmethod
def apply_settings(cls, project_settings):
    """Apply AYON settings to a plugin class."""

    host_name = os.environ.get("AYON_HOST_NAME")
    plugin_type = "create"
    plugin_type_settings = (
        project_settings
        .get(host_name, {})
        .get(plugin_type, {})
    )
    global_type_settings = (
        project_settings
        .get("core", {})
        .get(plugin_type, {})
    )
    if not global_type_settings and not plugin_type_settings:
        return

    plugin_name = cls.__name__

    plugin_settings = None
    # Look for plugin settings in host specific settings
    if plugin_name in plugin_type_settings:
        plugin_settings = plugin_type_settings[plugin_name]

    # Look for plugin settings in global settings
    elif plugin_name in global_type_settings:
        plugin_settings = global_type_settings[plugin_name]

    if not plugin_settings:
        return

    cls.log.debug(">>> We have preset for {}".format(plugin_name))
    for option, value in plugin_settings.items():
        if option == "enabled" and value is False:
            cls.log.debug("  - is disabled by preset")
        else:
            cls.log.debug("  - setting `{}`: `{}`".format(option, value))
        setattr(cls, option, value)

get_dynamic_data(project_name, folder_entity, task_entity, variant, host_name) classmethod

Return dynamic data for current Creator plugin.

By default return keys from dynamic_product_name_keys attribute as mapping to keep formatted template unchanged.

dynamic_product_name_keys = ["my_key"]
---
output = {
    "my_key": "{my_key}"
}

Dynamic keys may override default Creator keys (productType, task, folderPath, ...) but do it wisely if you need.

All of keys will be converted into 3 variants unchanged, capitalized and all upper letters. Because of that are all keys lowered.

This method can be modified to prefill some values just keep in mind it is class method.

Parameters:

Name Type Description Default
project_name str

Context's project name.

required
folder_entity dict[str, Any]

Folder entity.

required
task_entity dict[str, Any]

Task entity.

required
variant str

What is entered by user in creator tool.

required
host_name str

Name of host.

required

Returns:

Name Type Description
dict

Fill data for product name template.

Source code in client/ayon_core/pipeline/create/legacy_create.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
@classmethod
def get_dynamic_data(
    cls, project_name, folder_entity, task_entity, variant, host_name
):
    """Return dynamic data for current Creator plugin.

    By default return keys from `dynamic_product_name_keys` attribute
    as mapping to keep formatted template unchanged.

    ```
    dynamic_product_name_keys = ["my_key"]
    ---
    output = {
        "my_key": "{my_key}"
    }
    ```

    Dynamic keys may override default Creator keys (productType, task,
    folderPath, ...) but do it wisely if you need.

    All of keys will be converted into 3 variants unchanged, capitalized
    and all upper letters. Because of that are all keys lowered.

    This method can be modified to prefill some values just keep in mind it
    is class method.

    Args:
        project_name (str): Context's project name.
        folder_entity (dict[str, Any]): Folder entity.
        task_entity (dict[str, Any]): Task entity.
        variant (str): What is entered by user in creator tool.
        host_name (str): Name of host.

    Returns:
        dict: Fill data for product name template.
    """
    dynamic_data = {}
    for key in cls.dynamic_product_name_keys:
        key = key.lower()
        dynamic_data[key] = "{" + key + "}"
    return dynamic_data

get_product_name(project_name, folder_entity, task_entity, variant, host_name=None) classmethod

Return product name created with entered arguments.

Logic extracted from Creator tool. This method should give ability to get product name without the tool.

TODO: Maybe change variant variable.

By default is output concatenated product type with variant.

Parameters:

Name Type Description Default
project_name str

Context's project name.

required
folder_entity dict[str, Any]

Folder entity.

required
task_entity dict[str, Any]

Task entity.

required
variant str

What is entered by user in creator tool.

required
host_name str

Name of host.

None

Returns:

Name Type Description
str

Formatted product name with entered arguments. Should match config's logic.

Source code in client/ayon_core/pipeline/create/legacy_create.py
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
@classmethod
def get_product_name(
    cls, project_name, folder_entity, task_entity, variant, host_name=None
):
    """Return product name created with entered arguments.

    Logic extracted from Creator tool. This method should give ability
    to get product name without the tool.

    TODO: Maybe change `variant` variable.

    By default is output concatenated product type with variant.

    Args:
        project_name (str): Context's project name.
        folder_entity (dict[str, Any]): Folder entity.
        task_entity (dict[str, Any]): Task entity.
        variant (str): What is entered by user in creator tool.
        host_name (str): Name of host.

    Returns:
        str: Formatted product name with entered arguments. Should match
            config's logic.
    """

    dynamic_data = cls.get_dynamic_data(
        project_name, folder_entity, task_entity, variant, host_name
    )
    task_name = task_type = None
    if task_entity:
        task_name = task_entity["name"]
        task_type = task_entity["taskType"]
    return get_product_name(
        project_name,
        task_name,
        task_type,
        host_name,
        cls.product_type,
        variant,
        dynamic_data=dynamic_data
    )

legacy_create(Creator, product_name, folder_path, options=None, data=None)

Create a new instance

Associate nodes with a product name and type. These nodes are later validated, according to their product type, and integrated into the shared environment, relative their productName.

Data relative each product type, along with default data, are imprinted into the resulting objectSet. This data is later used by extractors and finally asset browsers to help identify the origin of the asset.

Parameters:

Name Type Description Default
Creator Creator

Class of creator.

required
product_name str

Name of product.

required
folder_path str

Folder path.

required
options dict

Additional options from GUI.

None
data dict

Additional data from GUI.

None

Returns:

Type Description

Name of instance

Source code in client/ayon_core/pipeline/create/legacy_create.py
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
def legacy_create(
    Creator, product_name, folder_path, options=None, data=None
):
    """Create a new instance

    Associate nodes with a product name and type. These nodes are later
    validated, according to their `product type`, and integrated into the
    shared environment, relative their `productName`.

    Data relative each product type, along with default data, are imprinted
    into the resulting objectSet. This data is later used by extractors
    and finally asset browsers to help identify the origin of the asset.

    Arguments:
        Creator (Creator): Class of creator.
        product_name (str): Name of product.
        folder_path (str): Folder path.
        options (dict, optional): Additional options from GUI.
        data (dict, optional): Additional data from GUI.

    Raises:
        NameError on `productName` already exists
        KeyError on invalid dynamic property
        RuntimeError on host error

    Returns:
        Name of instance

    """
    from ayon_core.pipeline import registered_host

    host = registered_host()
    plugin = Creator(product_name, folder_path, options, data)

    if plugin.maintain_selection is True:
        with host.maintained_selection():
            print("Running %s with maintained selection" % plugin)
            instance = plugin.process()
        return instance

    print("Running %s" % plugin)
    instance = plugin.process()
    return instance