Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyMel error when calling .root() on top level transform in Maya 2020 #433

Open
windxu88 opened this issue Oct 21, 2020 · 2 comments
Open

Comments

@windxu88
Copy link

Run the following script in Maya 2020

import pymel.core as pm
py_node = pm.PyNode("persp")
root_node = py_node.root()
print(root_node)

Result: One error as below is returned:
# Error: MayaNodeError: file /Applications/Autodesk/maya2020/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.7/site-packages/pymel/core/nodetypes.py line 1323: Maya Node does not exist (or is not unique):: u'None' #

In Maya 2019, it returns persp.

@FUJonathan
Copy link

I know this is an old issue, but I just ran into it and can confirm that it still happens in Maya 2022.

@FUJonathan
Copy link

As a workaround, I'm using this function, which splits the long name of the node by the pipe character and then makes a new PyNode from the first non-empty item in the list. Not sure if it'll work in all situations but it's sufficient for my needs.

import pymel.core as pm

def get_root(node):
    # longName is of the format '|root|parent|child', starting with an initial pipe
    long_name = node.longName()
    parent_names = long_name.split(u'|')
    return (None 
            if len(parent_names) <= 1
            else pm.PyNode(u'|{}'.format(parent_names[1])))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants