Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Maya: namespaced context go back to original namespace when started from inside a namespace #2531

Merged
merged 1 commit into from
Jan 21, 2022

Conversation

BigRoy
Copy link
Collaborator

@BigRoy BigRoy commented Jan 14, 2022

Brief description

Small fix for where openpype.hosts.maya.api.lib.namespaced context manager wouldn't go back to original state when started from inside a namespace.

Test case

To reproduce

cmds.file(new=True, force=True) # clear scene

# Create some namespaces
cmds.namespace(add=":aap")
cmds.namespace(add=":aap:foo")

# Start in a namespace :aap
cmds.namespace(set=":aap")
before = cmds.namespaceInfo(currentNamespace=True, absoluteName=True)
print("Before -> %s" % before)

# Go into namespace :aap:foo
with lib.namespaced(":aap:foo", new=False):
    during = cmds.namespaceInfo(currentNamespace=True, absoluteName=True)
    print("During -> %s" % during)

# Now should have reverted back to :aap
after = cmds.namespaceInfo(currentNamespace=True, absoluteName=True)
print("After  -> %s" % after)

assert before == after

That should work fine and print out:

Before -> :aap
During -> :aap:foo
After  -> :aap

But before this PR it would fail to go back to the namespace it had before and would error with:

# Error: No namespace matches name: 'aap'.
# Traceback (most recent call last):
#   File "<maya console>", line 14, in <module>
#   File "C:\Program Files\Autodesk\Maya2022\Python37\lib\contextlib.py", line 119, in __exit__
#     next(self.gen)
#   File "S:\openpype\OpenPype\openpype\hosts\maya\api\lib.py", line 745, in namespaced
#     cmds.namespace(set=original)
# RuntimeError: No namespace matches name: 'aap'. # 

Copy link
Member

@antirotor antirotor left a comment

Choose a reason for hiding this comment

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

Works, thanks!

@antirotor antirotor merged commit 9a8d8db into ynput:develop Jan 21, 2022
@mkolar mkolar added the type: bug Something isn't working label Jan 24, 2022
@BigRoy BigRoy deleted the fix_maya_api_lib_namespaced branch March 20, 2024 15:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
host: Maya type: bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants