Skip to content

actions

ActionForm dataclass

Form for loader action.

If an action needs to collect information from a user before or during of the action execution, it can return a response with a form. When the form is submitted, a new execution of the action is triggered.

It is also possible to just show a label message without the submit button to make sure the user has seen the message.

Attributes:

Name Type Description
title str

Title of the form -> title of the window.

fields list[AbstractAttrDef]

Fields of the form.

submit_label Optional[str]

Label of the submit button. Is hidden if is set to None.

submit_icon Optional[dict[str, Any]]

Icon definition of the submit button.

cancel_label Optional[str]

Label of the cancel button. Is hidden if is set to None. User can still close the window tho.

cancel_icon Optional[dict[str, Any]]

Icon definition of the cancel button.

Source code in client/ayon_core/pipeline/actions/structures.py
11
12
13
14
15
16
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
@dataclass
class ActionForm:
    """Form for loader action.

    If an action needs to collect information from a user before or during of
        the action execution, it can return a response with a form. When the
        form is submitted, a new execution of the action is triggered.

    It is also possible to just show a label message without the submit
        button to make sure the user has seen the message.

    Attributes:
        title (str): Title of the form -> title of the window.
        fields (list[AbstractAttrDef]): Fields of the form.
        submit_label (Optional[str]): Label of the submit button. Is hidden
            if is set to None.
        submit_icon (Optional[dict[str, Any]]): Icon definition of the submit
            button.
        cancel_label (Optional[str]): Label of the cancel button. Is hidden
            if is set to None. User can still close the window tho.
        cancel_icon (Optional[dict[str, Any]]): Icon definition of the cancel
            button.

    """
    title: str
    fields: list[AbstractAttrDef]
    submit_label: Optional[str] = "Submit"
    submit_icon: Optional[dict[str, Any]] = None
    cancel_label: Optional[str] = "Cancel"
    cancel_icon: Optional[dict[str, Any]] = None

    def to_json_data(self) -> dict[str, Any]:
        fields = self.fields
        if fields is not None:
            fields = serialize_attr_defs(fields)
        return {
            "title": self.title,
            "fields": fields,
            "submit_label": self.submit_label,
            "submit_icon": self.submit_icon,
            "cancel_label": self.cancel_label,
            "cancel_icon": self.cancel_icon,
        }

    @classmethod
    def from_json_data(cls, data: dict[str, Any]) -> "ActionForm":
        fields = data["fields"]
        if fields is not None:
            data["fields"] = deserialize_attr_defs(fields)
        return cls(**data)

InventoryAction

A custom action for the scene inventory tool

If registered the action will be visible in the Right Mouse Button menu under the submenu "Actions".

Source code in client/ayon_core/pipeline/actions/inventory.py
13
14
15
16
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
class InventoryAction:
    """A custom action for the scene inventory tool

    If registered the action will be visible in the Right Mouse Button menu
    under the submenu "Actions".

    """

    label = None
    icon = None
    color = None
    order = 0

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

    @staticmethod
    def is_compatible(container):
        """Override function in a custom class

        This method is specifically used to ensure the action can operate on
        the container.

        Args:
            container(dict): the data of a loaded asset, see host.ls()

        Returns:
            bool
        """
        return bool(container.get("objectName"))

    def process(self, containers):
        """Override function in a custom class

        This method will receive all containers even those which are
        incompatible. It is advised to create a small filter along the lines
        of this example:

        valid_containers = filter(self.is_compatible(c) for c in containers)

        The return value will need to be a True-ish value to trigger
        the data_changed signal in order to refresh the view.

        You can return a list of container names to trigger GUI to select
        treeview items.

        You can return a dict to carry extra GUI options. For example:
            {
                "objectNames": [container names...],
                "options": {"mode": "toggle",
                            "clear": False}
            }
        Currently workable GUI options are:
            - clear (bool): Clear current selection before selecting by action.
                            Default `True`.
            - mode (str): selection mode, use one of these:
                          "select", "deselect", "toggle". Default is "select".

        Args:
            containers (list): list of dictionaries

        Return:
            bool, list or dict

        """
        return True

    @classmethod
    def filepath_from_context(cls, context):
        return get_representation_path_from_context(context)

is_compatible(container) staticmethod

Override function in a custom class

This method is specifically used to ensure the action can operate on the container.

Parameters:

Name Type Description Default
container dict

the data of a loaded asset, see host.ls()

required

Returns:

Type Description

bool

Source code in client/ayon_core/pipeline/actions/inventory.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@staticmethod
def is_compatible(container):
    """Override function in a custom class

    This method is specifically used to ensure the action can operate on
    the container.

    Args:
        container(dict): the data of a loaded asset, see host.ls()

    Returns:
        bool
    """
    return bool(container.get("objectName"))

process(containers)

Override function in a custom class

This method will receive all containers even those which are incompatible. It is advised to create a small filter along the lines of this example:

valid_containers = filter(self.is_compatible(c) for c in containers)

The return value will need to be a True-ish value to trigger the data_changed signal in order to refresh the view.

You can return a list of container names to trigger GUI to select treeview items.

You can return a dict to carry extra GUI options. For example: { "objectNames": [container names...], "options": {"mode": "toggle", "clear": False} } Currently workable GUI options are: - clear (bool): Clear current selection before selecting by action. Default True. - mode (str): selection mode, use one of these: "select", "deselect", "toggle". Default is "select".

Parameters:

Name Type Description Default
containers list

list of dictionaries

required
Return

bool, list or dict

Source code in client/ayon_core/pipeline/actions/inventory.py
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
def process(self, containers):
    """Override function in a custom class

    This method will receive all containers even those which are
    incompatible. It is advised to create a small filter along the lines
    of this example:

    valid_containers = filter(self.is_compatible(c) for c in containers)

    The return value will need to be a True-ish value to trigger
    the data_changed signal in order to refresh the view.

    You can return a list of container names to trigger GUI to select
    treeview items.

    You can return a dict to carry extra GUI options. For example:
        {
            "objectNames": [container names...],
            "options": {"mode": "toggle",
                        "clear": False}
        }
    Currently workable GUI options are:
        - clear (bool): Clear current selection before selecting by action.
                        Default `True`.
        - mode (str): selection mode, use one of these:
                      "select", "deselect", "toggle". Default is "select".

    Args:
        containers (list): list of dictionaries

    Return:
        bool, list or dict

    """
    return True

LauncherAction

Bases: object

A custom action available

Source code in client/ayon_core/pipeline/actions/launcher.py
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
class LauncherAction(object):
    """A custom action available"""
    name = None
    label = None
    icon = None
    color = None
    order = 0

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

    def is_compatible(self, selection):
        """Return whether the class is compatible with the Session.

        Args:
            selection (LauncherActionSelection): Data with selection.

        """
        return True

    def process(self, selection, **kwargs):
        """Process the action.

        Args:
            selection (LauncherActionSelection): Data with selection.
            **kwargs: Additional arguments.

        """
        pass

is_compatible(selection)

Return whether the class is compatible with the Session.

Parameters:

Name Type Description Default
selection LauncherActionSelection

Data with selection.

required
Source code in client/ayon_core/pipeline/actions/launcher.py
369
370
371
372
373
374
375
376
def is_compatible(self, selection):
    """Return whether the class is compatible with the Session.

    Args:
        selection (LauncherActionSelection): Data with selection.

    """
    return True

process(selection, **kwargs)

Process the action.

Parameters:

Name Type Description Default
selection LauncherActionSelection

Data with selection.

required
**kwargs

Additional arguments.

{}
Source code in client/ayon_core/pipeline/actions/launcher.py
378
379
380
381
382
383
384
385
386
def process(self, selection, **kwargs):
    """Process the action.

    Args:
        selection (LauncherActionSelection): Data with selection.
        **kwargs: Additional arguments.

    """
    pass

LauncherActionSelection

Object helper to pass selection to actions.

Object support backwards compatibility for 'session' from OpenPype where environment variable keys were used to define selection.

Parameters:

Name Type Description Default
project_name str

Selected project name.

required
folder_id str

Selected folder id.

required
task_id str

Selected task id.

required
folder_path Optional[str]

Selected folder path.

None
task_name Optional[str]

Selected task name.

None
project_entity Optional[dict[str, Any]]

Project entity.

None
folder_entity Optional[dict[str, Any]]

Folder entity.

None
task_entity Optional[dict[str, Any]]

Task entity.

None
Source code in client/ayon_core/pipeline/actions/launcher.py
 14
 15
 16
 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
172
173
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
class LauncherActionSelection:
    """Object helper to pass selection to actions.

    Object support backwards compatibility for 'session' from OpenPype where
    environment variable keys were used to define selection.

    Args:
        project_name (str): Selected project name.
        folder_id (str): Selected folder id.
        task_id (str): Selected task id.
        folder_path (Optional[str]): Selected folder path.
        task_name (Optional[str]): Selected task name.
        project_entity (Optional[dict[str, Any]]): Project entity.
        folder_entity (Optional[dict[str, Any]]): Folder entity.
        task_entity (Optional[dict[str, Any]]): Task entity.

    """
    def __init__(
        self,
        project_name,
        folder_id,
        task_id,
        workfile_id,
        folder_path=None,
        task_name=None,
        project_entity=None,
        folder_entity=None,
        task_entity=None,
        workfile_entity=None,
        project_settings=None,
    ):
        self._project_name = project_name
        self._folder_id = folder_id
        self._task_id = task_id
        self._workfile_id = workfile_id

        self._folder_path = folder_path
        self._task_name = task_name

        self._project_entity = project_entity
        self._folder_entity = folder_entity
        self._task_entity = task_entity
        self._workfile_entity = workfile_entity

        self._project_settings = project_settings

    def __getitem__(self, key):
        warnings.warn(
            (
                "Using deprecated access to selection data. Please use"
                " attributes and methods"
                " defined by 'LauncherActionSelection'."
            ),
            category=DeprecationWarning
        )
        if key in {"AYON_PROJECT_NAME", "AVALON_PROJECT"}:
            return self.project_name
        if key in {"AYON_FOLDER_PATH", "AVALON_ASSET"}:
            return self.folder_path
        if key in {"AYON_TASK_NAME", "AVALON_TASK"}:
            return self.task_name
        raise KeyError(f"Key: {key} not found")

    def __iter__(self):
        for key in self.keys():
            yield key

    def __contains__(self, key):
        warnings.warn(
            (
                "Using deprecated access to selection data. Please use"
                " attributes and methods"
                " defined by 'LauncherActionSelection'."
            ),
            category=DeprecationWarning
        )
        # Fake missing keys check for backwards compatibility
        if key in {
            "AYON_PROJECT_NAME",
            "AVALON_PROJECT",
        }:
            return self._project_name is not None
        if key in {
            "AYON_FOLDER_PATH",
            "AVALON_ASSET",
        }:
            return self._folder_id is not None
        if key in {
            "AYON_TASK_NAME",
            "AVALON_TASK",
        }:
            return self._task_id is not None
        return False

    def get(self, key, default=None):
        """

        Deprecated:
            Added for backwards compatibility with older actions.

        """
        warnings.warn(
            (
                "Using deprecated access to selection data. Please use"
                " attributes and methods"
                " defined by 'LauncherActionSelection'."
            ),
            category=DeprecationWarning
        )
        try:
            return self[key]
        except KeyError:
            return default

    def items(self):
        """

        Deprecated:
            Added for backwards compatibility with older actions.

        """
        for key, value in (
            ("AYON_PROJECT_NAME", self.project_name),
            ("AYON_FOLDER_PATH", self.folder_path),
            ("AYON_TASK_NAME", self.task_name),
        ):
            if value is not None:
                yield (key, value)

    def keys(self):
        """

        Deprecated:
            Added for backwards compatibility with older actions.

        """
        for key, _ in self.items():
            yield key

    def values(self):
        """

        Deprecated:
            Added for backwards compatibility with older actions.

        """
        for _, value in self.items():
            yield value

    def get_project_name(self):
        """Selected project name.

        Returns:
            Union[str, None]: Selected project name.

        """
        return self._project_name

    def get_folder_id(self):
        """Selected folder id.

        Returns:
            Union[str, None]: Selected folder id.

        """
        return self._folder_id

    def get_folder_path(self):
        """Selected folder path.

        Returns:
            Union[str, None]: Selected folder path.

        """
        if self._folder_id is None:
            return None
        if self._folder_path is None:
            self._folder_path = self.folder_entity["path"]
        return self._folder_path

    def get_task_id(self):
        """Selected task id.

        Returns:
            Union[str, None]: Selected task id.

        """
        return self._task_id

    def get_task_name(self):
        """Selected task name.

        Returns:
            Union[str, None]: Selected task name.

        """
        if self._task_id is None:
            return None
        if self._task_name is None:
            self._task_name = self.task_entity["name"]
        return self._task_name

    def get_workfile_id(self):
        """Selected workfile id.

        Returns:
            Union[str, None]: Selected workfile id.

        """
        return self._workfile_id

    def get_project_entity(self):
        """Project entity for the selection.

        Returns:
            Union[dict[str, Any], None]: Project entity.

        """
        if self._project_name is None:
            return None
        if self._project_entity is None:
            self._project_entity = ayon_api.get_project(self._project_name)
        return self._project_entity

    def get_folder_entity(self):
        """Folder entity for the selection.

        Returns:
            Union[dict[str, Any], None]: Folder entity.

        """
        if self._project_name is None or self._folder_id is None:
            return None
        if self._folder_entity is None:
            self._folder_entity = ayon_api.get_folder_by_id(
                self._project_name, self._folder_id
            )
        return self._folder_entity

    def get_task_entity(self):
        """Task entity for the selection.

        Returns:
            Union[dict[str, Any], None]: Task entity.

        """
        if (
            self._project_name is None
            or self._task_id is None
        ):
            return None
        if self._task_entity is None:
            self._task_entity = ayon_api.get_task_by_id(
                self._project_name, self._task_id
            )
        return self._task_entity

    def get_workfile_entity(self):
        """Workfile entity for the selection.

        Returns:
            Union[dict[str, Any], None]: Workfile entity.

        """
        if (
            self._project_name is None
            or self._workfile_id is None
        ):
            return None
        if self._workfile_entity is None:
            self._workfile_entity = ayon_api.get_workfile_info_by_id(
                self._project_name, self._workfile_id
            )
        return self._workfile_entity

    def get_project_settings(self):
        """Project settings for the selection.

        Returns:
            dict[str, Any]: Project settings or studio settings if
                project is not selected.

        """
        if self._project_settings is None:
            if self._project_name is None:
                settings = get_studio_settings()
            else:
                settings = get_project_settings(self._project_name)
            self._project_settings = settings
        return self._project_settings

    @property
    def is_project_selected(self):
        """Return whether a project is selected.

        Returns:
            bool: Whether a project is selected.

        """
        return self._project_name is not None

    @property
    def is_folder_selected(self):
        """Return whether a folder is selected.

        Returns:
            bool: Whether a folder is selected.

        """
        return self._folder_id is not None

    @property
    def is_task_selected(self):
        """Return whether a task is selected.

        Returns:
            bool: Whether a task is selected.

        """
        return self._task_id is not None

    @property
    def is_workfile_selected(self):
        """Return whether a task is selected.

        Returns:
            bool: Whether a task is selected.

        """
        return self._workfile_id is not None

    project_name = property(get_project_name)
    folder_id = property(get_folder_id)
    task_id = property(get_task_id)
    workfile_id = property(get_workfile_id)
    folder_path = property(get_folder_path)
    task_name = property(get_task_name)

    project_entity = property(get_project_entity)
    folder_entity = property(get_folder_entity)
    task_entity = property(get_task_entity)
    workfile_entity = property(get_workfile_entity)

is_folder_selected property

Return whether a folder is selected.

Returns:

Name Type Description
bool

Whether a folder is selected.

is_project_selected property

Return whether a project is selected.

Returns:

Name Type Description
bool

Whether a project is selected.

is_task_selected property

Return whether a task is selected.

Returns:

Name Type Description
bool

Whether a task is selected.

is_workfile_selected property

Return whether a task is selected.

Returns:

Name Type Description
bool

Whether a task is selected.

get(key, default=None)

Deprecated

Added for backwards compatibility with older actions.

Source code in client/ayon_core/pipeline/actions/launcher.py
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
def get(self, key, default=None):
    """

    Deprecated:
        Added for backwards compatibility with older actions.

    """
    warnings.warn(
        (
            "Using deprecated access to selection data. Please use"
            " attributes and methods"
            " defined by 'LauncherActionSelection'."
        ),
        category=DeprecationWarning
    )
    try:
        return self[key]
    except KeyError:
        return default

get_folder_entity()

Folder entity for the selection.

Returns:

Type Description

Union[dict[str, Any], None]: Folder entity.

Source code in client/ayon_core/pipeline/actions/launcher.py
238
239
240
241
242
243
244
245
246
247
248
249
250
251
def get_folder_entity(self):
    """Folder entity for the selection.

    Returns:
        Union[dict[str, Any], None]: Folder entity.

    """
    if self._project_name is None or self._folder_id is None:
        return None
    if self._folder_entity is None:
        self._folder_entity = ayon_api.get_folder_by_id(
            self._project_name, self._folder_id
        )
    return self._folder_entity

get_folder_id()

Selected folder id.

Returns:

Type Description

Union[str, None]: Selected folder id.

Source code in client/ayon_core/pipeline/actions/launcher.py
172
173
174
175
176
177
178
179
def get_folder_id(self):
    """Selected folder id.

    Returns:
        Union[str, None]: Selected folder id.

    """
    return self._folder_id

get_folder_path()

Selected folder path.

Returns:

Type Description

Union[str, None]: Selected folder path.

Source code in client/ayon_core/pipeline/actions/launcher.py
181
182
183
184
185
186
187
188
189
190
191
192
def get_folder_path(self):
    """Selected folder path.

    Returns:
        Union[str, None]: Selected folder path.

    """
    if self._folder_id is None:
        return None
    if self._folder_path is None:
        self._folder_path = self.folder_entity["path"]
    return self._folder_path

get_project_entity()

Project entity for the selection.

Returns:

Type Description

Union[dict[str, Any], None]: Project entity.

Source code in client/ayon_core/pipeline/actions/launcher.py
225
226
227
228
229
230
231
232
233
234
235
236
def get_project_entity(self):
    """Project entity for the selection.

    Returns:
        Union[dict[str, Any], None]: Project entity.

    """
    if self._project_name is None:
        return None
    if self._project_entity is None:
        self._project_entity = ayon_api.get_project(self._project_name)
    return self._project_entity

get_project_name()

Selected project name.

Returns:

Type Description

Union[str, None]: Selected project name.

Source code in client/ayon_core/pipeline/actions/launcher.py
163
164
165
166
167
168
169
170
def get_project_name(self):
    """Selected project name.

    Returns:
        Union[str, None]: Selected project name.

    """
    return self._project_name

get_project_settings()

Project settings for the selection.

Returns:

Type Description

dict[str, Any]: Project settings or studio settings if project is not selected.

Source code in client/ayon_core/pipeline/actions/launcher.py
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
def get_project_settings(self):
    """Project settings for the selection.

    Returns:
        dict[str, Any]: Project settings or studio settings if
            project is not selected.

    """
    if self._project_settings is None:
        if self._project_name is None:
            settings = get_studio_settings()
        else:
            settings = get_project_settings(self._project_name)
        self._project_settings = settings
    return self._project_settings

get_task_entity()

Task entity for the selection.

Returns:

Type Description

Union[dict[str, Any], None]: Task entity.

Source code in client/ayon_core/pipeline/actions/launcher.py
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
def get_task_entity(self):
    """Task entity for the selection.

    Returns:
        Union[dict[str, Any], None]: Task entity.

    """
    if (
        self._project_name is None
        or self._task_id is None
    ):
        return None
    if self._task_entity is None:
        self._task_entity = ayon_api.get_task_by_id(
            self._project_name, self._task_id
        )
    return self._task_entity

get_task_id()

Selected task id.

Returns:

Type Description

Union[str, None]: Selected task id.

Source code in client/ayon_core/pipeline/actions/launcher.py
194
195
196
197
198
199
200
201
def get_task_id(self):
    """Selected task id.

    Returns:
        Union[str, None]: Selected task id.

    """
    return self._task_id

get_task_name()

Selected task name.

Returns:

Type Description

Union[str, None]: Selected task name.

Source code in client/ayon_core/pipeline/actions/launcher.py
203
204
205
206
207
208
209
210
211
212
213
214
def get_task_name(self):
    """Selected task name.

    Returns:
        Union[str, None]: Selected task name.

    """
    if self._task_id is None:
        return None
    if self._task_name is None:
        self._task_name = self.task_entity["name"]
    return self._task_name

get_workfile_entity()

Workfile entity for the selection.

Returns:

Type Description

Union[dict[str, Any], None]: Workfile entity.

Source code in client/ayon_core/pipeline/actions/launcher.py
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
def get_workfile_entity(self):
    """Workfile entity for the selection.

    Returns:
        Union[dict[str, Any], None]: Workfile entity.

    """
    if (
        self._project_name is None
        or self._workfile_id is None
    ):
        return None
    if self._workfile_entity is None:
        self._workfile_entity = ayon_api.get_workfile_info_by_id(
            self._project_name, self._workfile_id
        )
    return self._workfile_entity

get_workfile_id()

Selected workfile id.

Returns:

Type Description

Union[str, None]: Selected workfile id.

Source code in client/ayon_core/pipeline/actions/launcher.py
216
217
218
219
220
221
222
223
def get_workfile_id(self):
    """Selected workfile id.

    Returns:
        Union[str, None]: Selected workfile id.

    """
    return self._workfile_id

items()

Deprecated

Added for backwards compatibility with older actions.

Source code in client/ayon_core/pipeline/actions/launcher.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
def items(self):
    """

    Deprecated:
        Added for backwards compatibility with older actions.

    """
    for key, value in (
        ("AYON_PROJECT_NAME", self.project_name),
        ("AYON_FOLDER_PATH", self.folder_path),
        ("AYON_TASK_NAME", self.task_name),
    ):
        if value is not None:
            yield (key, value)

keys()

Deprecated

Added for backwards compatibility with older actions.

Source code in client/ayon_core/pipeline/actions/launcher.py
143
144
145
146
147
148
149
150
151
def keys(self):
    """

    Deprecated:
        Added for backwards compatibility with older actions.

    """
    for key, _ in self.items():
        yield key

values()

Deprecated

Added for backwards compatibility with older actions.

Source code in client/ayon_core/pipeline/actions/launcher.py
153
154
155
156
157
158
159
160
161
def values(self):
    """

    Deprecated:
        Added for backwards compatibility with older actions.

    """
    for _, value in self.items():
        yield value

LoaderActionItem dataclass

Item of loader action.

Action plugins return these items as possible actions to run for a given context.

Because the action item can be related to a specific entity and not the whole selection, they also have to define the entity type and ids to be executed on.

Attributes:

Name Type Description
label str

Text shown in UI.

order int

Order of the action in UI.

group_label Optional[str]

Label of the group to which the action belongs.

icon Optional[dict[str, Any]

Icon definition.

data Optional[DataType]

Action item data.

identifier Optional[str]

Identifier of the plugin which created the action item. Is filled automatically. Is not changed if is filled -> can lead to different plugin.

Source code in client/ayon_core/pipeline/actions/loader.py
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
@dataclass
class LoaderActionItem:
    """Item of loader action.

    Action plugins return these items as possible actions to run for a given
        context.

    Because the action item can be related to a specific entity
        and not the whole selection, they also have to define the entity type
        and ids to be executed on.

    Attributes:
        label (str): Text shown in UI.
        order (int): Order of the action in UI.
        group_label (Optional[str]): Label of the group to which the action
            belongs.
        icon (Optional[dict[str, Any]): Icon definition.
        data (Optional[DataType]): Action item data.
        identifier (Optional[str]): Identifier of the plugin which
            created the action item. Is filled automatically. Is not changed
            if is filled -> can lead to different plugin.

    """
    label: str
    order: int = 0
    group_label: Optional[str] = None
    icon: Optional[dict[str, Any]] = None
    data: Optional[DataType] = None
    # Is filled automatically
    identifier: str = None

LoaderActionPlugin

Bases: ABC

Plugin for loader actions.

Plugin is responsible for getting action items and executing actions.

Source code in client/ayon_core/pipeline/actions/loader.py
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
class LoaderActionPlugin(ABC):
    """Plugin for loader actions.

    Plugin is responsible for getting action items and executing actions.

    """
    _log: Optional[logging.Logger] = None
    enabled: bool = True

    def __init__(self, context: "LoaderActionsContext") -> None:
        self._context = context
        self.apply_settings(context.get_studio_settings())

    def apply_settings(self, studio_settings: dict[str, Any]) -> None:
        """Apply studio settings to the plugin.

        Args:
            studio_settings (dict[str, Any]): Studio settings.

        """
        pass

    @property
    def log(self) -> logging.Logger:
        if self._log is None:
            self._log = Logger.get_logger(self.__class__.__name__)
        return self._log

    @property
    def identifier(self) -> str:
        """Identifier of the plugin.

        Returns:
            str: Plugin identifier.

        """
        return self.__class__.__name__

    @property
    def host_name(self) -> Optional[str]:
        """Name of the current host."""
        return self._context.get_host_name()

    @abstractmethod
    def get_action_items(
        self, selection: LoaderActionSelection
    ) -> list[LoaderActionItem]:
        """Action items for the selection.

        Args:
            selection (LoaderActionSelection): Selection.

        Returns:
            list[LoaderActionItem]: Action items.

        """
        pass

    @abstractmethod
    def execute_action(
        self,
        selection: LoaderActionSelection,
        data: Optional[DataType],
        form_values: dict[str, Any],
    ) -> Optional[LoaderActionResult]:
        """Execute an action.

        Args:
            selection (LoaderActionSelection): Selection wrapper. Can be used
                to get entities or get context of original selection.
            data (Optional[DataType]): Additional action item data.
            form_values (dict[str, Any]): Attribute values.

        Returns:
            Optional[LoaderActionResult]: Result of the action execution.

        """
        pass

host_name property

Name of the current host.

identifier property

Identifier of the plugin.

Returns:

Name Type Description
str str

Plugin identifier.

apply_settings(studio_settings)

Apply studio settings to the plugin.

Parameters:

Name Type Description Default
studio_settings dict[str, Any]

Studio settings.

required
Source code in client/ayon_core/pipeline/actions/loader.py
564
565
566
567
568
569
570
571
def apply_settings(self, studio_settings: dict[str, Any]) -> None:
    """Apply studio settings to the plugin.

    Args:
        studio_settings (dict[str, Any]): Studio settings.

    """
    pass

execute_action(selection, data, form_values) abstractmethod

Execute an action.

Parameters:

Name Type Description Default
selection LoaderActionSelection

Selection wrapper. Can be used to get entities or get context of original selection.

required
data Optional[DataType]

Additional action item data.

required
form_values dict[str, Any]

Attribute values.

required

Returns:

Type Description
Optional[LoaderActionResult]

Optional[LoaderActionResult]: Result of the action execution.

Source code in client/ayon_core/pipeline/actions/loader.py
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
@abstractmethod
def execute_action(
    self,
    selection: LoaderActionSelection,
    data: Optional[DataType],
    form_values: dict[str, Any],
) -> Optional[LoaderActionResult]:
    """Execute an action.

    Args:
        selection (LoaderActionSelection): Selection wrapper. Can be used
            to get entities or get context of original selection.
        data (Optional[DataType]): Additional action item data.
        form_values (dict[str, Any]): Attribute values.

    Returns:
        Optional[LoaderActionResult]: Result of the action execution.

    """
    pass

get_action_items(selection) abstractmethod

Action items for the selection.

Parameters:

Name Type Description Default
selection LoaderActionSelection

Selection.

required

Returns:

Type Description
list[LoaderActionItem]

list[LoaderActionItem]: Action items.

Source code in client/ayon_core/pipeline/actions/loader.py
594
595
596
597
598
599
600
601
602
603
604
605
606
607
@abstractmethod
def get_action_items(
    self, selection: LoaderActionSelection
) -> list[LoaderActionItem]:
    """Action items for the selection.

    Args:
        selection (LoaderActionSelection): Selection.

    Returns:
        list[LoaderActionItem]: Action items.

    """
    pass

LoaderActionResult dataclass

Result of loader action execution.

Attributes:

Name Type Description
message Optional[str]

Message to show in UI.

success bool

If the action was successful. Affects color of the message.

form Optional[ActionForm]

Form to show in UI.

form_values Optional[dict[str, Any]]

Values for the form. Can be used if the same form is re-shown e.g. because a user forgot to fill a required field.

Source code in client/ayon_core/pipeline/actions/loader.py
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
@dataclass
class LoaderActionResult:
    """Result of loader action execution.

    Attributes:
        message (Optional[str]): Message to show in UI.
        success (bool): If the action was successful. Affects color of
            the message.
        form (Optional[ActionForm]): Form to show in UI.
        form_values (Optional[dict[str, Any]]): Values for the form. Can be
            used if the same form is re-shown e.g. because a user forgot to
            fill a required field.

    """
    message: Optional[str] = None
    success: bool = True
    form: Optional[ActionForm] = None
    form_values: Optional[dict[str, Any]] = None

    def to_json_data(self) -> dict[str, Any]:
        form = self.form
        if form is not None:
            form = form.to_json_data()
        return {
            "message": self.message,
            "success": self.success,
            "form": form,
            "form_values": self.form_values,
        }

    @classmethod
    def from_json_data(cls, data: dict[str, Any]) -> "LoaderActionResult":
        form = data["form"]
        if form is not None:
            data["form"] = ActionForm.from_json_data(form)
        return LoaderActionResult(**data)

LoaderActionSelection

Selection of entities for loader actions.

Selection tells action plugins what exactly is selected in the tool and which ids.

Contains entity cache which can be used to get entities by their ids. Or to get project settings and anatomy.

Source code in client/ayon_core/pipeline/actions/loader.py
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
class LoaderActionSelection:
    """Selection of entities for loader actions.

    Selection tells action plugins what exactly is selected in the tool and
        which ids.

    Contains entity cache which can be used to get entities by their ids. Or
        to get project settings and anatomy.

    """
    def __init__(
        self,
        project_name: str,
        selected_ids: set[str],
        selected_type: LoaderSelectedType,
        *,
        project_anatomy: Optional[Anatomy] = None,
        project_settings: Optional[dict[str, Any]] = None,
        entities_cache: Optional[SelectionEntitiesCache] = None,
    ):
        self._project_name = project_name
        self._selected_ids = selected_ids
        self._selected_type = selected_type

        self._project_anatomy = project_anatomy
        self._project_settings = project_settings

        if entities_cache is None:
            entities_cache = SelectionEntitiesCache(project_name)
        self._entities_cache = entities_cache

    def get_entities_cache(self) -> SelectionEntitiesCache:
        return self._entities_cache

    def get_project_name(self) -> str:
        return self._project_name

    def get_selected_ids(self) -> set[str]:
        return set(self._selected_ids)

    def get_selected_type(self) -> str:
        return self._selected_type

    def get_project_settings(self) -> dict[str, Any]:
        if self._project_settings is None:
            self._project_settings = get_project_settings(self._project_name)
        return copy.deepcopy(self._project_settings)

    def get_project_anatomy(self) -> Anatomy:
        if self._project_anatomy is None:
            self._project_anatomy = Anatomy(
                self._project_name,
                project_entity=self.get_entities_cache().get_project(),
            )
        return self._project_anatomy

    project_name = property(get_project_name)
    selected_ids = property(get_selected_ids)
    selected_type = property(get_selected_type)
    project_settings = property(get_project_settings)
    project_anatomy = property(get_project_anatomy)
    entities = property(get_entities_cache)

    # --- Helper methods ---
    def versions_selected(self) -> bool:
        """Selected entity type is version.

        Returns:
            bool: True if selected entity type is version.

        """
        return self._selected_type == LoaderSelectedType.version

    def representations_selected(self) -> bool:
        """Selected entity type is representation.

        Returns:
            bool: True if selected entity type is representation.

        """
        return self._selected_type == LoaderSelectedType.representation

    def get_selected_version_entities(self) -> list[dict[str, Any]]:
        """Retrieve selected version entities.

        An empty list is returned if 'version' is not the selected
            entity type.

        Returns:
            list[dict[str, Any]]: List of selected version entities.

        """
        if self.versions_selected():
            return self.entities.get_versions(self.selected_ids)
        return []

    def get_selected_representation_entities(self) -> list[dict[str, Any]]:
        """Retrieve selected representation entities.

        An empty list is returned if 'representation' is not the selected
            entity type.

        Returns:
            list[dict[str, Any]]: List of selected representation entities.

        """
        if self.representations_selected():
            return self.entities.get_representations(self.selected_ids)
        return []

get_selected_representation_entities()

Retrieve selected representation entities.

An empty list is returned if 'representation' is not the selected entity type.

Returns:

Type Description
list[dict[str, Any]]

list[dict[str, Any]]: List of selected representation entities.

Source code in client/ayon_core/pipeline/actions/loader.py
466
467
468
469
470
471
472
473
474
475
476
477
478
def get_selected_representation_entities(self) -> list[dict[str, Any]]:
    """Retrieve selected representation entities.

    An empty list is returned if 'representation' is not the selected
        entity type.

    Returns:
        list[dict[str, Any]]: List of selected representation entities.

    """
    if self.representations_selected():
        return self.entities.get_representations(self.selected_ids)
    return []

get_selected_version_entities()

Retrieve selected version entities.

An empty list is returned if 'version' is not the selected entity type.

Returns:

Type Description
list[dict[str, Any]]

list[dict[str, Any]]: List of selected version entities.

Source code in client/ayon_core/pipeline/actions/loader.py
452
453
454
455
456
457
458
459
460
461
462
463
464
def get_selected_version_entities(self) -> list[dict[str, Any]]:
    """Retrieve selected version entities.

    An empty list is returned if 'version' is not the selected
        entity type.

    Returns:
        list[dict[str, Any]]: List of selected version entities.

    """
    if self.versions_selected():
        return self.entities.get_versions(self.selected_ids)
    return []

representations_selected()

Selected entity type is representation.

Returns:

Name Type Description
bool bool

True if selected entity type is representation.

Source code in client/ayon_core/pipeline/actions/loader.py
443
444
445
446
447
448
449
450
def representations_selected(self) -> bool:
    """Selected entity type is representation.

    Returns:
        bool: True if selected entity type is representation.

    """
    return self._selected_type == LoaderSelectedType.representation

versions_selected()

Selected entity type is version.

Returns:

Name Type Description
bool bool

True if selected entity type is version.

Source code in client/ayon_core/pipeline/actions/loader.py
434
435
436
437
438
439
440
441
def versions_selected(self) -> bool:
    """Selected entity type is version.

    Returns:
        bool: True if selected entity type is version.

    """
    return self._selected_type == LoaderSelectedType.version

LoaderActionsContext

Wrapper for loader actions and their logic.

Takes care about the public api of loader actions and internal logic like discovery and initialization of plugins.

Source code in client/ayon_core/pipeline/actions/loader.py
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
class LoaderActionsContext:
    """Wrapper for loader actions and their logic.

    Takes care about the public api of loader actions and internal logic like
        discovery and initialization of plugins.

    """
    def __init__(
        self,
        studio_settings: Optional[dict[str, Any]] = None,
        addons_manager: Optional[AddonsManager] = None,
        host: Optional[AbstractHost] = _PLACEHOLDER,
    ) -> None:
        self._log = Logger.get_logger(self.__class__.__name__)

        self._addons_manager = addons_manager
        self._host = host

        # Attributes that are re-cached on reset
        self._studio_settings = studio_settings
        self._plugins = None

    def reset(
        self, studio_settings: Optional[dict[str, Any]] = None
    ) -> None:
        """Reset context cache.

        Reset plugins and studio settings to reload them.

        Notes:
             Does not reset the cache of AddonsManger because there should not
                be a reason to do so.

        """
        self._studio_settings = studio_settings
        self._plugins = None

    def get_addons_manager(self) -> AddonsManager:
        if self._addons_manager is None:
            self._addons_manager = AddonsManager(
                settings=self.get_studio_settings()
            )
        return self._addons_manager

    def get_host(self) -> Optional[AbstractHost]:
        """Get current host integration.

        Returns:
            Optional[AbstractHost]: Host integration. Can be None if host
                integration is not registered -> probably not used in the
                host integration process.

        """
        if self._host is _PLACEHOLDER:
            from ayon_core.pipeline import registered_host

            self._host = registered_host()
        return self._host

    def get_host_name(self) -> Optional[str]:
        host = self.get_host()
        if host is None:
            return None
        return host.name

    def get_studio_settings(self) -> dict[str, Any]:
        if self._studio_settings is None:
            self._studio_settings = get_studio_settings()
        return copy.deepcopy(self._studio_settings)

    def get_action_items(
        self, selection: LoaderActionSelection
    ) -> list[LoaderActionItem]:
        """Collect action items from all plugins for given selection.

        Args:
            selection (LoaderActionSelection): Selection wrapper.

        """
        output = []
        for plugin_id, plugin in self._get_plugins().items():
            try:
                for action_item in plugin.get_action_items(selection):
                    if action_item.identifier is None:
                        action_item.identifier = plugin_id
                    output.append(action_item)

            except Exception:
                self._log.warning(
                    "Failed to get action items for"
                    f" plugin '{plugin.identifier}'",
                    exc_info=True,
                )
        return output

    def execute_action(
        self,
        identifier: str,
        selection: LoaderActionSelection,
        data: Optional[DataType],
        form_values: dict[str, Any],
    ) -> Optional[LoaderActionResult]:
        """Trigger action execution.

        Args:
            identifier (str): Identifier of the plugin.
            selection (LoaderActionSelection): Selection wrapper. Can be used
                to get what is selected in UI and to get access to entity
                cache.
            data (Optional[DataType]): Additional action item data.
            form_values (dict[str, Any]): Form values related to action.
                Usually filled if action returned response with form.

        """
        plugins_by_id = self._get_plugins()
        plugin = plugins_by_id[identifier]
        return plugin.execute_action(
            selection,
            data,
            form_values,
        )

    def _get_plugins(self) -> dict[str, LoaderActionPlugin]:
        if self._plugins is None:
            host_name = self.get_host_name()
            addons_manager = self.get_addons_manager()
            all_paths = [
                os.path.join(AYON_CORE_ROOT, "plugins", "loader")
            ]
            for addon in addons_manager.addons:
                if not isinstance(addon, IPluginPaths):
                    continue

                try:
                    if is_func_signature_supported(
                        addon.get_loader_action_plugin_paths,
                        host_name
                    ):
                        paths = addon.get_loader_action_plugin_paths(
                            host_name
                        )
                    else:
                        paths = addon.get_loader_action_plugin_paths()
                except Exception:
                    self._log.warning(
                        "Failed to get plugin paths for addon",
                        exc_info=True
                    )
                    continue

                if paths:
                    all_paths.extend(paths)

            result = discover_plugins(LoaderActionPlugin, all_paths)
            result.log_report()
            plugins = {}
            for cls in result.plugins:
                try:
                    plugin = cls(self)
                    if not plugin.enabled:
                        continue

                    plugin_id = plugin.identifier
                    if plugin_id not in plugins:
                        plugins[plugin_id] = plugin
                        continue

                    self._log.warning(
                        f"Duplicated plugins identifier found '{plugin_id}'."
                    )

                except Exception:
                    self._log.warning(
                        f"Failed to initialize plugin '{cls.__name__}'",
                        exc_info=True,
                    )
            self._plugins = plugins
        return self._plugins

execute_action(identifier, selection, data, form_values)

Trigger action execution.

Parameters:

Name Type Description Default
identifier str

Identifier of the plugin.

required
selection LoaderActionSelection

Selection wrapper. Can be used to get what is selected in UI and to get access to entity cache.

required
data Optional[DataType]

Additional action item data.

required
form_values dict[str, Any]

Form values related to action. Usually filled if action returned response with form.

required
Source code in client/ayon_core/pipeline/actions/loader.py
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
def execute_action(
    self,
    identifier: str,
    selection: LoaderActionSelection,
    data: Optional[DataType],
    form_values: dict[str, Any],
) -> Optional[LoaderActionResult]:
    """Trigger action execution.

    Args:
        identifier (str): Identifier of the plugin.
        selection (LoaderActionSelection): Selection wrapper. Can be used
            to get what is selected in UI and to get access to entity
            cache.
        data (Optional[DataType]): Additional action item data.
        form_values (dict[str, Any]): Form values related to action.
            Usually filled if action returned response with form.

    """
    plugins_by_id = self._get_plugins()
    plugin = plugins_by_id[identifier]
    return plugin.execute_action(
        selection,
        data,
        form_values,
    )

get_action_items(selection)

Collect action items from all plugins for given selection.

Parameters:

Name Type Description Default
selection LoaderActionSelection

Selection wrapper.

required
Source code in client/ayon_core/pipeline/actions/loader.py
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
def get_action_items(
    self, selection: LoaderActionSelection
) -> list[LoaderActionItem]:
    """Collect action items from all plugins for given selection.

    Args:
        selection (LoaderActionSelection): Selection wrapper.

    """
    output = []
    for plugin_id, plugin in self._get_plugins().items():
        try:
            for action_item in plugin.get_action_items(selection):
                if action_item.identifier is None:
                    action_item.identifier = plugin_id
                output.append(action_item)

        except Exception:
            self._log.warning(
                "Failed to get action items for"
                f" plugin '{plugin.identifier}'",
                exc_info=True,
            )
    return output

get_host()

Get current host integration.

Returns:

Type Description
Optional[AbstractHost]

Optional[AbstractHost]: Host integration. Can be None if host integration is not registered -> probably not used in the host integration process.

Source code in client/ayon_core/pipeline/actions/loader.py
675
676
677
678
679
680
681
682
683
684
685
686
687
688
def get_host(self) -> Optional[AbstractHost]:
    """Get current host integration.

    Returns:
        Optional[AbstractHost]: Host integration. Can be None if host
            integration is not registered -> probably not used in the
            host integration process.

    """
    if self._host is _PLACEHOLDER:
        from ayon_core.pipeline import registered_host

        self._host = registered_host()
    return self._host

reset(studio_settings=None)

Reset context cache.

Reset plugins and studio settings to reload them.

Notes

Does not reset the cache of AddonsManger because there should not be a reason to do so.

Source code in client/ayon_core/pipeline/actions/loader.py
653
654
655
656
657
658
659
660
661
662
663
664
665
666
def reset(
    self, studio_settings: Optional[dict[str, Any]] = None
) -> None:
    """Reset context cache.

    Reset plugins and studio settings to reload them.

    Notes:
         Does not reset the cache of AddonsManger because there should not
            be a reason to do so.

    """
    self._studio_settings = studio_settings
    self._plugins = None

LoaderSelectedType

Bases: StrEnum

Selected entity type.

Source code in client/ayon_core/pipeline/actions/loader.py
91
92
93
94
95
96
class LoaderSelectedType(StrEnum):
    """Selected entity type."""
    # folder = "folder"
    # task = "task"
    version = "version"
    representation = "representation"

LoaderSimpleActionPlugin

Bases: LoaderActionPlugin

Simple action plugin.

This action will show exactly one action item defined by attributes on the class.

Attributes:

Name Type Description
label Optional[str]

Label of the action item.

order int

Order of the action item.

group_label Optional[str]

Label of the group to which the action belongs.

icon Optional[dict[str, Any]]

Icon definition shown next to label.

Source code in client/ayon_core/pipeline/actions/loader.py
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
class LoaderSimpleActionPlugin(LoaderActionPlugin):
    """Simple action plugin.

    This action will show exactly one action item defined by attributes
        on the class.

    Attributes:
        label: Label of the action item.
        order: Order of the action item.
        group_label: Label of the group to which the action belongs.
        icon: Icon definition shown next to label.

    """

    label: Optional[str] = None
    order: int = 0
    group_label: Optional[str] = None
    icon: Optional[dict[str, Any]] = None

    @abstractmethod
    def is_compatible(self, selection: LoaderActionSelection) -> bool:
        """Check if plugin is compatible with selection.

        Args:
            selection (LoaderActionSelection): Selection information.

        Returns:
            bool: True if plugin is compatible with selection.

        """
        pass

    @abstractmethod
    def execute_simple_action(
        self,
        selection: LoaderActionSelection,
        form_values: dict[str, Any],
    ) -> Optional[LoaderActionResult]:
        """Process action based on selection.

        Args:
            selection (LoaderActionSelection): Selection information.
            form_values (dict[str, Any]): Values from a form if there are any.

        Returns:
            Optional[LoaderActionResult]: Result of the action.

        """
        pass

    def get_action_items(
        self, selection: LoaderActionSelection
    ) -> list[LoaderActionItem]:
        if self.is_compatible(selection):
            label = self.label or self.__class__.__name__
            return [
                LoaderActionItem(
                    label=label,
                    order=self.order,
                    group_label=self.group_label,
                    icon=self.icon,
                )
            ]
        return []

    def execute_action(
        self,
        selection: LoaderActionSelection,
        data: Optional[DataType],
        form_values: dict[str, Any],
    ) -> Optional[LoaderActionResult]:
        return self.execute_simple_action(selection, form_values)

execute_simple_action(selection, form_values) abstractmethod

Process action based on selection.

Parameters:

Name Type Description Default
selection LoaderActionSelection

Selection information.

required
form_values dict[str, Any]

Values from a form if there are any.

required

Returns:

Type Description
Optional[LoaderActionResult]

Optional[LoaderActionResult]: Result of the action.

Source code in client/ayon_core/pipeline/actions/loader.py
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
@abstractmethod
def execute_simple_action(
    self,
    selection: LoaderActionSelection,
    form_values: dict[str, Any],
) -> Optional[LoaderActionResult]:
    """Process action based on selection.

    Args:
        selection (LoaderActionSelection): Selection information.
        form_values (dict[str, Any]): Values from a form if there are any.

    Returns:
        Optional[LoaderActionResult]: Result of the action.

    """
    pass

is_compatible(selection) abstractmethod

Check if plugin is compatible with selection.

Parameters:

Name Type Description Default
selection LoaderActionSelection

Selection information.

required

Returns:

Name Type Description
bool bool

True if plugin is compatible with selection.

Source code in client/ayon_core/pipeline/actions/loader.py
830
831
832
833
834
835
836
837
838
839
840
841
@abstractmethod
def is_compatible(self, selection: LoaderActionSelection) -> bool:
    """Check if plugin is compatible with selection.

    Args:
        selection (LoaderActionSelection): Selection information.

    Returns:
        bool: True if plugin is compatible with selection.

    """
    pass

SelectionEntitiesCache

Cache of entities used as helper in the selection wrapper.

It is possible to get entities based on ids with helper methods to get entities, their parents or their children's entities.

The goal is to avoid multiple API calls for the same entity in multiple action plugins.

The cache is based on the selected project. Entities are fetched if are not in cache yet.

Source code in client/ayon_core/pipeline/actions/loader.py
 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
172
173
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
class SelectionEntitiesCache:
    """Cache of entities used as helper in the selection wrapper.

    It is possible to get entities based on ids with helper methods to get
        entities, their parents or their children's entities.

    The goal is to avoid multiple API calls for the same entity in multiple
        action plugins.

    The cache is based on the selected project. Entities are fetched
        if are not in cache yet.
    """
    def __init__(
        self,
        project_name: str,
        project_entity: Optional[dict[str, Any]] = None,
        folders_by_id: Optional[dict[str, dict[str, Any]]] = None,
        tasks_by_id: Optional[dict[str, dict[str, Any]]] = None,
        products_by_id: Optional[dict[str, dict[str, Any]]] = None,
        versions_by_id: Optional[dict[str, dict[str, Any]]] = None,
        representations_by_id: Optional[dict[str, dict[str, Any]]] = None,
        task_ids_by_folder_id: Optional[dict[str, set[str]]] = None,
        product_ids_by_folder_id: Optional[dict[str, set[str]]] = None,
        version_ids_by_product_id: Optional[dict[str, set[str]]] = None,
        representation_ids_by_version_id: Optional[dict[str, set[str]]] = None,
    ):
        self._project_name = project_name
        self._project_entity = project_entity
        self._folders_by_id = folders_by_id or {}
        self._tasks_by_id = tasks_by_id or {}
        self._products_by_id = products_by_id or {}
        self._versions_by_id = versions_by_id or {}
        self._representations_by_id = representations_by_id or {}

        self._task_ids_by_folder_id = task_ids_by_folder_id or {}
        self._product_ids_by_folder_id = product_ids_by_folder_id or {}
        self._version_ids_by_product_id = version_ids_by_product_id or {}
        self._representation_ids_by_version_id = (
            representation_ids_by_version_id or {}
        )

    def get_project(self) -> dict[str, Any]:
        """Get project entity"""
        if self._project_entity is None:
            self._project_entity = ayon_api.get_project(self._project_name)
        return copy.deepcopy(self._project_entity)

    def get_folders(
        self, folder_ids: set[str]
    ) -> list[dict[str, Any]]:
        return self._get_entities(
            folder_ids,
            self._folders_by_id,
            "folder_ids",
            ayon_api.get_folders,
        )

    def get_tasks(
        self, task_ids: set[str]
    ) -> list[dict[str, Any]]:
        return self._get_entities(
            task_ids,
            self._tasks_by_id,
            "task_ids",
            ayon_api.get_tasks,
        )

    def get_products(
        self, product_ids: set[str]
    ) -> list[dict[str, Any]]:
        return self._get_entities(
            product_ids,
            self._products_by_id,
            "product_ids",
            ayon_api.get_products,
        )

    def get_versions(
        self, version_ids: set[str]
    ) -> list[dict[str, Any]]:
        return self._get_entities(
            version_ids,
            self._versions_by_id,
            "version_ids",
            ayon_api.get_versions,
        )

    def get_representations(
        self, representation_ids: set[str]
    ) -> list[dict[str, Any]]:
        return self._get_entities(
            representation_ids,
            self._representations_by_id,
            "representation_ids",
            ayon_api.get_representations,
        )

    def get_folders_tasks(
        self, folder_ids: set[str]
    ) -> list[dict[str, Any]]:
        task_ids = self._fill_parent_children_ids(
            folder_ids,
            "folderId",
            "folder_ids",
            self._task_ids_by_folder_id,
            ayon_api.get_tasks,
        )
        return self.get_tasks(task_ids)

    def get_folders_products(
        self, folder_ids: set[str]
    ) -> list[dict[str, Any]]:
        product_ids = self._get_folders_products_ids(folder_ids)
        return self.get_products(product_ids)

    def get_tasks_versions(
        self, task_ids: set[str]
    ) -> list[dict[str, Any]]:
        folder_ids = {
            task["folderId"]
            for task in self.get_tasks(task_ids)
        }
        product_ids = self._get_folders_products_ids(folder_ids)
        output = []
        for version in self.get_products_versions(product_ids):
            task_id = version["taskId"]
            if task_id in task_ids:
                output.append(version)
        return output

    def get_products_versions(
        self, product_ids: set[str]
    ) -> list[dict[str, Any]]:
        version_ids = self._fill_parent_children_ids(
            product_ids,
            "productId",
            "product_ids",
            self._version_ids_by_product_id,
            ayon_api.get_versions,
        )
        return self.get_versions(version_ids)

    def get_versions_representations(
        self, version_ids: set[str]
    ) -> list[dict[str, Any]]:
        repre_ids = self._fill_parent_children_ids(
            version_ids,
            "versionId",
            "version_ids",
            self._representation_ids_by_version_id,
            ayon_api.get_representations,
        )
        return self.get_representations(repre_ids)

    def get_tasks_folders(self, task_ids: set[str]) -> list[dict[str, Any]]:
        folder_ids = {
            task["folderId"]
            for task in self.get_tasks(task_ids)
        }
        return self.get_folders(folder_ids)

    def get_products_folders(
        self, product_ids: set[str]
    ) -> list[dict[str, Any]]:
        folder_ids = {
            product["folderId"]
            for product in self.get_products(product_ids)
        }
        return self.get_folders(folder_ids)

    def get_versions_products(
        self, version_ids: set[str]
    ) -> list[dict[str, Any]]:
        product_ids = {
            version["productId"]
            for version in self.get_versions(version_ids)
        }
        return self.get_products(product_ids)

    def get_versions_tasks(
        self, version_ids: set[str]
    ) -> list[dict[str, Any]]:
        task_ids = {
            version["taskId"]
            for version in self.get_versions(version_ids)
            if version["taskId"]
        }
        return self.get_tasks(task_ids)

    def get_representations_versions(
        self, representation_ids: set[str]
    ) -> list[dict[str, Any]]:
        version_ids = {
            repre["versionId"]
            for repre in self.get_representations(representation_ids)
        }
        return self.get_versions(version_ids)

    def _get_folders_products_ids(self, folder_ids: set[str]) -> set[str]:
        return self._fill_parent_children_ids(
            folder_ids,
            "folderId",
            "folder_ids",
            self._product_ids_by_folder_id,
            ayon_api.get_products,
        )

    def _fill_parent_children_ids(
        self,
        entity_ids: set[str],
        parent_key: str,
        filter_attr: str,
        parent_mapping: dict[str, set[str]],
        getter: Callable,
    ) -> set[str]:
        if not entity_ids:
            return set()
        children_ids = set()
        missing_ids = set()
        for entity_id in entity_ids:
            _children_ids = parent_mapping.get(entity_id)
            if _children_ids is None:
                missing_ids.add(entity_id)
            else:
                children_ids.update(_children_ids)
        if missing_ids:
            entities_by_parent_id = collections.defaultdict(set)
            for entity in getter(
                self._project_name,
                fields={"id", parent_key},
                **{filter_attr: missing_ids},
            ):
                child_id = entity["id"]
                children_ids.add(child_id)
                entities_by_parent_id[entity[parent_key]].add(child_id)

            for entity_id in missing_ids:
                parent_mapping[entity_id] = entities_by_parent_id[entity_id]

        return children_ids

    def _get_entities(
        self,
        entity_ids: set[str],
        cache_var: dict[str, Any],
        filter_arg: str,
        getter: Callable,
    ) -> list[dict[str, Any]]:
        if not entity_ids:
            return []

        output = []
        missing_ids: set[str] = set()
        for entity_id in entity_ids:
            entity = cache_var.get(entity_id)
            if entity_id not in cache_var:
                missing_ids.add(entity_id)
                cache_var[entity_id] = None
            elif entity:
                output.append(entity)

        if missing_ids:
            for entity in getter(
                self._project_name,
                **{filter_arg: missing_ids}
            ):
                output.append(entity)
                cache_var[entity["id"]] = entity
        return output

get_project()

Get project entity

Source code in client/ayon_core/pipeline/actions/loader.py
140
141
142
143
144
def get_project(self) -> dict[str, Any]:
    """Get project entity"""
    if self._project_entity is None:
        self._project_entity = ayon_api.get_project(self._project_name)
    return copy.deepcopy(self._project_entity)

webaction_fields_to_attribute_defs(fields)

Helper function to convert fields definition from webactions form.

Convert form fields to attribute definitions to be able to display them using attribute definitions.

Parameters:

Name Type Description Default
fields list[dict[str, Any]]

Fields from webaction form.

required

Returns:

Type Description
list[AbstractAttrDef]

list[AbstractAttrDef]: Converted attribute definitions.

Source code in client/ayon_core/pipeline/actions/utils.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
def webaction_fields_to_attribute_defs(
    fields: list[dict[str, Any]]
) -> list[AbstractAttrDef]:
    """Helper function to convert fields definition from webactions form.

    Convert form fields to attribute definitions to be able to display them
        using attribute definitions.

    Args:
        fields (list[dict[str, Any]]): Fields from webaction form.

    Returns:
        list[AbstractAttrDef]: Converted attribute definitions.

    """
    attr_defs = []
    for field in fields:
        field_type = field["type"]
        attr_def = None
        if field_type == "label":
            label = field.get("value")
            if label is None:
                label = field.get("text")
            attr_def = UILabelDef(
                label, key=uuid.uuid4().hex
            )
        elif field_type == "boolean":
            value = field["value"]
            if isinstance(value, str):
                value = value.lower() == "true"

            attr_def = BoolDef(
                field["name"],
                default=value,
                label=field.get("label"),
            )
        elif field_type == "text":
            attr_def = TextDef(
                field["name"],
                default=field.get("value"),
                label=field.get("label"),
                placeholder=field.get("placeholder"),
                multiline=field.get("multiline", False),
                regex=field.get("regex"),
                # syntax=field["syntax"],
            )
        elif field_type in ("integer", "float"):
            value = field.get("value")
            if isinstance(value, str):
                if field_type == "integer":
                    value = int(value)
                else:
                    value = float(value)
            attr_def = NumberDef(
                field["name"],
                default=value,
                label=field.get("label"),
                decimals=0 if field_type == "integer" else 5,
                # placeholder=field.get("placeholder"),
                minimum=field.get("min"),
                maximum=field.get("max"),
            )
        elif field_type in ("select", "multiselect"):
            attr_def = EnumDef(
                field["name"],
                items=field["options"],
                default=field.get("value"),
                label=field.get("label"),
                multiselection=field_type == "multiselect",
            )
        elif field_type == "hidden":
            attr_def = HiddenDef(
                field["name"],
                default=field.get("value"),
            )

        if attr_def is None:
            print(f"Unknown config field type: {field_type}")
            attr_def = UILabelDef(
                f"Unknown field type '{field_type}",
                key=uuid.uuid4().hex
            )
        attr_defs.append(attr_def)
    return attr_defs