|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import Any |
| 4 | + |
| 5 | +from maya import cmds |
| 6 | + |
| 7 | +from ayon_core.pipeline import InventoryAction |
| 8 | + |
| 9 | + |
| 10 | +class LockVersions(InventoryAction): |
| 11 | + label = "Lock versions" |
| 12 | + icon = "lock" |
| 13 | + color = "#ffffff" |
| 14 | + order = -1 |
| 15 | + |
| 16 | + @staticmethod |
| 17 | + def is_compatible(container: dict[str, Any]) -> bool: |
| 18 | + return container.get("version_locked") is not True |
| 19 | + |
| 20 | + def process(self, containers: list[dict[str, Any]]) -> bool: |
| 21 | + for container in containers: |
| 22 | + if container.get("version_locked") is True: |
| 23 | + continue |
| 24 | + node = container["objectName"] |
| 25 | + key = "version_locked" |
| 26 | + if cmds.attributeQuery(key, node=node, exists=True): |
| 27 | + cmds.deleteAttr(f"{node}.{key}") |
| 28 | + cmds.addAttr(node, longName=key, attributeType=bool) |
| 29 | + cmds.setAttr( |
| 30 | + f"{node}.{key}", True, keyable=False, channelBox=True |
| 31 | + ) |
| 32 | + return True |
| 33 | + |
| 34 | + |
| 35 | +class UnlockVersions(InventoryAction): |
| 36 | + label = "Unlock versions" |
| 37 | + icon = "lock-open" |
| 38 | + color = "#ffffff" |
| 39 | + order = -1 |
| 40 | + |
| 41 | + @staticmethod |
| 42 | + def is_compatible(container: dict[str, Any]) -> bool: |
| 43 | + return container.get("version_locked") is True |
| 44 | + |
| 45 | + def process(self, containers: list[dict[str, Any]]) -> bool: |
| 46 | + for container in containers: |
| 47 | + if container.get("version_locked") is not True: |
| 48 | + continue |
| 49 | + node = container["objectName"] |
| 50 | + key = "version_locked" |
| 51 | + if cmds.attributeQuery(key, node=node, exists=True): |
| 52 | + cmds.deleteAttr(f"{node}.{key}") |
| 53 | + return True |
0 commit comments