Skip to content

Conversation

@iLLiCiTiT
Copy link
Member

Changelog Description

Implement inventory actions to be able to lock/unlock version of a container.

Additional review information

The PR is related to ynput/ayon-core#1447 which adds the option to lock and unload version of a container.

Added 2 actions to lock and unlock the version by settings "version_locked" on the object.

Testing notes:

  1. Make sure to use both PRs (if not merged yet).
  2. Launch Maya.
  3. Load something to scene that is not from latest version.
  4. Open scene manager.
  5. Select the container and run Actions > Lock version on the container.
  6. Validation of outdated containers (e.g. during publishing) should not raise an error.

@iLLiCiTiT iLLiCiTiT self-assigned this Sep 23, 2025
@iLLiCiTiT iLLiCiTiT added the type: enhancement Improvement of existing functionality or minor addition label Sep 23, 2025
Co-authored-by: Roy Nieterau <roy_nieterau@hotmail.com>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a nitpick - we could add type hints here 👻

Copy link
Member Author

@iLLiCiTiT iLLiCiTiT Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean to add dict[str, Any]? Can we just approve it please if it works. Or add suggestions please. Because the typehints for the whole inventory actions are honestly unmanagable, and I have no intention in changing it at this moment.

@moonyuet
Copy link
Member

Receive this when performing unlock version:

# Warning: Reference file path remapped from 'D:/sh_boss_proj/interior_lenny/lib/publish/model/modelTest/v003/il_lib_modelTest_v003.abc' to 'D:/sh_boss_proj/interior_lenny/lib/publish/model/modelTest/v003/il_lib_modelTest_v003.abc'.
# File read in  0.012 seconds.
# Warning: Name 'version_locked' of new attribute clashes with an existing attribute of node 'lib_modelTest_01__modelTest_CON'.
# Traceback (most recent call last):
#   File "D:\ayon-core\client\ayon_core\tools\sceneinventory\view.py", line 626, in _process_custom_action
#     result = action.process(list(containers_by_id.values()))
#              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "D:\ayon-addon_template\ayon-maya\client\ayon_maya\plugins\inventory\lock_version.py", line 39, in process
#     imprint(node, {"version_locked": False})
#   File "D:\ayon-addon_template\ayon-maya\client\ayon_maya\api\lib.py", line 720, in imprint
#     cmds.addAttr(node, longName=key, **add_type)
# RuntimeError: Found no valid items to add the attribute to.
# 
# Warning: Name 'version_locked' of new attribute clashes with an existing attribute of node 'lib_modelTest_01__modelTest_CON'.
# Traceback (most recent call last):
#   File "D:\ayon-core\client\ayon_core\tools\sceneinventory\view.py", line 626, in _process_custom_action
#     result = action.process(list(containers_by_id.values()))
#              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "D:\ayon-addon_template\ayon-maya\client\ayon_maya\plugins\inventory\lock_version.py", line 39, in process
#     imprint(node, {"version_locked": False})
#   File "D:\ayon-addon_template\ayon-maya\client\ayon_maya\api\lib.py", line 720, in imprint
#     cmds.addAttr(node, longName=key, **add_type)
# RuntimeError: Found no valid items to add the attribute to.

@iLLiCiTiT
Copy link
Member Author

Receive this when performing unlock version:

@BigRoy I need help with this.

@moonyuet
Copy link
Member

moonyuet commented Sep 26, 2025

Receive this when performing unlock version:

@BigRoy I need help with this.

In the imprint function

def imprint(node, data):
"""Write `data` to `node` as userDefined attributes
Arguments:
node (str): Long name of node
data (dict): Dictionary of key/value pairs
Example:
>>> from maya import cmds
>>> def compute():
... return 6
...
>>> cube, generator = cmds.polyCube()
>>> imprint(cube, {
... "regularString": "myFamily",
... "computedValue": lambda: compute()
... })
...
>>> cmds.getAttr(cube + ".computedValue")
6
"""
for key, value in data.items():
if callable(value):
# Support values evaluated at imprint
value = value()
if isinstance(value, bool):
add_type = {"attributeType": "bool"}
set_type = {"keyable": False, "channelBox": True}
elif isinstance(value, str):
add_type = {"dataType": "string"}
set_type = {"type": "string"}
elif isinstance(value, int):
add_type = {"attributeType": "long"}
set_type = {"keyable": False, "channelBox": True}
elif isinstance(value, float):
add_type = {"attributeType": "double"}
set_type = {"keyable": False, "channelBox": True}
elif isinstance(value, (list, tuple)):
add_type = {"attributeType": "enum", "enumName": ":".join(value)}
set_type = {"keyable": False, "channelBox": True}
value = 0 # enum default
else:
raise TypeError("Unsupported type: %r" % type(value))
cmds.addAttr(node, longName=key, **add_type)
cmds.setAttr(node + "." + key, value, **set_type)

we need to make some adjustment (line 719-721) for checking if the attribute already exists.

{the code...}

        if not cmds.attributeQuery(key, node=node, exists=True):
            cmds.addAttr(node, longName=key, **add_type)
        cmds.setAttr(node + "." + key, value, **set_type)

Once it was added, the action can be performed.

@BigRoy
Copy link
Contributor

BigRoy commented Sep 26, 2025

we need to make some adjustment (line 719-721) for checking if the attribute already exists.

Yup, that's roughly the issue - but I'm not entirely confident whether we should allow this long-standing function to allow "ignoring" existing attributes...

I think we may for now be better of doing what the Creator plug-in also does, and that is explicitly removing the attribute if it does happen to pre-exist: https://github.com/ynput/ayon-maya/blob/394a83cae1efcb99580d3b27454f39cb0a9316d8/client/ayon_maya/api/plugin.py#L237-L242

This at least ensures that the created attribute is of the correct type. Not saying it's the nicest way to do this either. But I'm afraid we're somehow mixing the functionality here.

Having said that - at the same time the amount of calls directly to imprint() seems relatively limited in ayon-maya. So perhaps adjusting it to suit our needs might work out fine too. I'm just worried that by just passing it if it happens to exist that we might not catch invalid attribute types correctly.

Copy link
Contributor

@BigRoy BigRoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (didn't test)

@iLLiCiTiT iLLiCiTiT added the sponsored This is directly sponsored by a client or community member label Sep 30, 2025
@iLLiCiTiT iLLiCiTiT merged commit e9db845 into develop Sep 30, 2025
2 checks passed
@iLLiCiTiT iLLiCiTiT deleted the enhancement/l1446-version-pinning branch September 30, 2025 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sponsored This is directly sponsored by a client or community member type: enhancement Improvement of existing functionality or minor addition

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants