I think the Python API 2.0 is already in effect (since Maya 2013<http://docs.autodesk.com/MAYAUL/2013/ENU/Maya-API-Documentation/index.html?url=files/GUID-AC9B3C66-90FE-493F-A7B2-44ABBA77CED2.htm,topicNumber=d30e29422>or so) but only applies to the API. maya.cmds on the other hand is a wrapper around MEL independent of the underlying API and so wasn't affected by that change, PyMEL is then a another wrapper on-top of that wrapper, but I think PyMEL uses some of the Python API for some of its more esoteric features; possibly to distinguish between nodes, I'm not sure.
To fully understand why Maya doesn't deal in "absolute paths" you'll first need to understand what a graph is. In short, the concept of paths in Maya is a mere convenience to users; nodes exist in a type of graph known as a Directed Acyclic Graph (or DAG) which is rooted in a family of graphs, each with its own strengths and weaknesses, and in such a graph there can be multiple paths to any given node. This also makes the term "absolute" also a convenience. There is an interesting wiki page<http://en.wikipedia.org/wiki/Graph_theory>about it but the topic extends quite far and is ultimately grounded in a branch of mathematics known as discrete mathematics<http://en.wikipedia.org/wiki/Discrete_mathematics> . In Maya, whenever you create a node without specifying a name, Maya goes ahead and gives that node a unique name based on the currently existing names in your scene. This is also for convenience, as we've already seen, names can co-exist. With a unique name, Maya is able to provide you with this mythical "absolute path" and allow you to work with nodes similar to how you would work with files and folders; as though they existed within a hierarchy. Its familiar and easy, unlike graphs which is ultimately a network and not a hierarchy. (Think about how you would go about finding the absolute path to a person on Facebook or Linkedin; its not possible as there would be many paths depending on where you start looking from and which route you are looking to take; think also Google Maps and addresses) So, in short), when you force a name onto your new nodes, Maya will have no way of providing you with an absolute path as the name you provide may likely exist elsewhere which will give Maya no other option than to provide you will all alternatives to the node you are looking for. A more consistent way would be to let Maya assign this unique name, by simply not providing one, and then go about renaming it. Before renaming it, cmds.ls(long=True) would then give you only one result that you could rely on. What happens when you rename it however is a different matter and keeping track of it would be up to you. If you truly needed a sustainable, persistent "absolute path" to the nodes you create, you could do what I suspect Maya does internally; which is to assign a unique identifier (UUID, GUID or similar) to an attribute within your node. You could then use this attribute to distinguish nodes from each other, even though they may have the same name. # Psuedo-code, bear with me. # Step 1. Create node with unique identifier group = cmds.createNode('transform') # Will produce a unique name cmds.addAttr(group, 'uid', 'my_unique_identifier', dt='string') cmds.rename(group, 'myCommonName') # Absolute path is lost into oblivion.. # Step 2. Find node by unique identifier exact_result = None multiple_results = cmds.ls('myCommonName', long=True) # May return multiple nodes for result in multiple_results: uid = cmds.getAttr(result + ".uid") if uid == my_special_id: exact_result = result On 22 March 2014 07:09, Joe Weidenbach <[email protected]> wrote: > Actually, even after all of my years (12+) working with Maya, I've got a > question on this one too--has anyone found a reliable way to get around > maya creating a group with a name which returns only the short path (not > even the shortest unique path)? Is the only way to rename the group after > the creation? Or, is there an API function that I'm missing that will > return the actual long group name? My current workaround is running a > cmds.ls on any nodes I create with long=true, but with a group that > returns a list of possible nodes; like so: > > node = cmds.ls(cmds.group(empty=True, name="testGRP"), long=True) > > if I have a group such as "|test|testGRP", node will equal > [u'|test|testGRP', u'|testGRP'] > > Of course, the intention is that node would equal [u'|testGrp'] so that I > could use node[0] to reference it, versus arbitrarily guessing which is the > correct node. This is one of those cases where I miss using PyMEL > currently :) > > My current solution is to use something more like this: > > node = cmds.group(empty=True, world=True, name="testGRP") > foundNode = cmds.ls("|{0}".format(node), long=True) > > But for obvious reasons, that feels fairly silly and highly unpythonic :) > > Also, as an update, I talked to Steven Roselle at GDC, and he said that > Python API 2.0 is still very high on their list of priorities, but has no > updates in 2015 :( > > Joe > > > On 3/19/2014 10:56 AM, Marcus Ottosson wrote: > > I see. It's generally a good approach to work with full-paths throughout, > and if you do, you should encounter little difficulty in paths across > packages. Even duplicate names across hierarchies are unique given a full > path. > > > On 19 March 2014 17:44, Eric Thivierge <[email protected]> wrote: > >> Thanks Marcus, >> >> The problem I'm facing currently is that I need to write data to a json >> file that can be read in and interperated by both Softimage and Maya. So I >> have to store object names consistently when exporting from Softimage or >> Maya. I'm probably more in favor of mimicking the Maya format at this point >> since, well you know why. >> >> Thanks, >> Eric T. >> >> >> On Wednesday, March 19, 2014 1:12:25 PM, Marcus Ottosson wrote: >> >>> In Maya, the hierarchy is included in a node's path but gets discarded >>> most of the time and instead the artist is trusted to keep his names >>> unique. The reason this is the case is because in Maya, there is no >>> "hierarchy". Maya is inherently node-based; Softimage on the other >>> hand does have the notion of a hierarchy. >>> >>> Thus, a full path of a pCube1 may be resolve >>> into'|a_group|another_group|pCube1', the | being the separator. >>> >>> You can ask for full paths via cmds.ls <http://cmds.ls>(long=True), >>> >>> other commands have similar flags, such as >>> cmds.listRelatives(fullPath=True) that ultimately do the same thing; >>> concatenate the depth-first path of a node within a graph. >>> >>> Additionally, Maya has the notion of namespaces, which encapsulates >>> nodes similar to how Models encapsulates nodes in Softimage, however I >>> would suggest sticking with hungarian notation at first as namespaces >>> are tricky to understand at first. >>> >>> Best, >>> Marcus >>> >>> >>> On 19 March 2014 15:00, Eric Thivierge <[email protected] >>> <mailto:[email protected]>> wrote: >>> >>> Hah. Well, yeah... thanks. >>> >>> On Wednesday, March 19, 2014 10:59:10 AM, damon shelton wrote: >>> >>> cmds.ls <http://cmds.ls> <http://cmds.ls> ('*pCube1', >>> long=True) >>> >>> >>> >>> On Mar 19, 2014 7:54 AM, "Eric Thivierge" >>> <[email protected] <mailto:[email protected]> >>> <mailto:[email protected] >>> >>> <mailto:[email protected]>__>> wrote: >>> >>> Hello all, >>> >>> This may seem like a simple question but my Googling >>> didn't return >>> any useful results. >>> >>> I have a name of an object 'pCube1'. I need to find it in >>> the Maya >>> scene. Problem is, I may have multiple objects in the >>> scene that >>> are named the same thing. Even in the same hierarchy >>> (Crazy that >>> Maya lets you do this btw). Is there a way to get a list >>> of all >>> objects that are named 'pCube1'? Once I get that list I >>> need to >>> find the top most parent in the scene. From there I can >>> find the >>> one I need. >>> >>> When I try to listRelatives, it throws an error saying >>> there is >>> more than one node int he scene that is name 'pCube1'. >>> >>> # PyMel >>> print pm.objExists('pCube1') >>> >>> parents = pm.listRelatives('pCube1', allParents=True) >>> for eachItem in parents: >>> print eachItem.name() >>> >>> Thanks, >>> Eric T. >>> >>> -- >>> You received this message because you are subscribed to >>> the Google >>> Groups "Python Programming for Autodesk Maya" group. >>> To unsubscribe from this group and stop receiving emails >>> from it, >>> send an email to >>> [email protected] >>> <mailto:python_inside_maya%[email protected]> >>> >>> <mailto:python_inside_maya%[email protected] >>> <mailto:python_inside_maya%[email protected]>__>. >>> >>> >>> >>> To view this discussion on the web visit >>> >>> https://groups.google.com/d/____msgid/python_inside_maya/____5329AFAD.5080403%40hybride.com >>> < >>> https://groups.google.com/d/__msgid/python_inside_maya/__5329AFAD.5080403%40hybride.com >>> > >>> >>> < >>> https://groups.google.com/d/__msgid/python_inside_maya/__5329AFAD.5080403%40hybride.com >>> < >>> https://groups.google.com/d/msgid/python_inside_maya/5329AFAD.5080403%40hybride.com >>> >__>__. >>> For more options, visit >>> https://groups.google.com/d/____optout >>> <https://groups.google.com/d/__optout> >>> >>> <https://groups.google.com/d/__optout >>> <https://groups.google.com/d/optout>>. >>> >>> >>> -- >>> You received this message because you are subscribed to the >>> Google >>> Groups "Python Programming for Autodesk Maya" group. >>> To unsubscribe from this group and stop receiving emails from >>> it, send >>> an email to [email protected] >>> <mailto:python_inside_maya%[email protected]> >>> <mailto:[email protected] >>> >>> <mailto:python_inside_maya%[email protected]>>. >>> >>> To view this discussion on the web visit >>> >>> https://groups.google.com/d/__msgid/python_inside_maya/__CAM9RXoLb37cQR4QB8R6eshN1PmT95__n3uGY9qJicLtHFoEhQjLw%40mail.__gmail.com >>> < >>> https://groups.google.com/d/msgid/python_inside_maya/CAM9RXoLb37cQR4QB8R6eshN1PmT95n3uGY9qJicLtHFoEhQjLw%40mail.gmail.com >>> > >>> < >>> https://groups.google.com/d/__msgid/python_inside_maya/__CAM9RXoLb37cQR4QB8R6eshN1PmT95__n3uGY9qJicLtHFoEhQjLw%40mail.__gmail.com?utm_medium=email&__utm_source=footer >>> < >>> https://groups.google.com/d/msgid/python_inside_maya/CAM9RXoLb37cQR4QB8R6eshN1PmT95n3uGY9qJicLtHFoEhQjLw%40mail.gmail.com?utm_medium=email&utm_source=footer >>> >>. >>> >>> For more options, visit https://groups.google.com/d/__optout >>> <https://groups.google.com/d/optout>. >>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Python Programming for Autodesk Maya" group. >>> To unsubscribe from this group and stop receiving emails from it, >>> send an email to [email protected] >>> <mailto:python_inside_maya%[email protected]>. >>> To view this discussion on the web visit >>> >>> https://groups.google.com/d/__msgid/python_inside_maya/__5329B11D.4040200%40hybride.com >>> < >>> https://groups.google.com/d/msgid/python_inside_maya/5329B11D.4040200%40hybride.com>__. >>> >>> >>> >>> For more options, visit https://groups.google.com/d/__optout >>> <https://groups.google.com/d/optout>. >>> >>> >>> >>> >>> -- >>> *Marcus Ottosson* >>> [email protected] <mailto:[email protected]> >>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Python Programming for Autodesk Maya" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected] >>> <mailto:[email protected]>. >>> To view this discussion on the web visit >>> >>> https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCB%2BTeeUmXjjM2eBYbnFLDELt%2BZB-gBfH8L2L1QChnE-w%40mail.gmail.com >>> < >>> https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCB%2BTeeUmXjjM2eBYbnFLDELt%2BZB-gBfH8L2L1QChnE-w%40mail.gmail.com?utm_medium=email&utm_source=footer>. >>> >>> >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> > > > -- > *Marcus Ottosson* > [email protected] > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODcD4zs%3DKJhAYr2e4DKcvhtZ%2BQMXwYRbKPz2M2zP7rXSg%40mail.gmail.com<https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODcD4zs%3DKJhAYr2e4DKcvhtZ%2BQMXwYRbKPz2M2zP7rXSg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > > > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/532D3739.7010301%40gmail.com<https://groups.google.com/d/msgid/python_inside_maya/532D3739.7010301%40gmail.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- *Marcus Ottosson* [email protected] -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODzpL3_XLs29OaxrTuwmG8pKcLfKadOtE3bgKGJE%3D%2BWVw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
