getting descendants by name in pymel

1,216 views
Skip to first unread message

meeotch

unread,
Oct 1, 2014, 9:15:26 PM10/1/14
to python_in...@googlegroups.com
In writing a script to duplicate and add variation to a model a bunch of times, I found myself wondering about "best practices" for getting descendants of a given node by name.  For instance, if I've got the top node of my model copy, and I want to grab the feet to make them bigger.  I know that I can do it in a MEL/maya.cmds/procedural way with ls(), or by writing a function to recursively search using getChildren().  But the pymel docs make a point about how always having to use strings instead of nodes is one of the problems pymel is meant to solve.  So given that "under this hierarchy, find me node X" is such a common operation, I thought there must be a pythonic/pymelic way of doing it.

Related:  how come the General Pymel google group (and the pymel docs, for that matter) don't seem to have seen much activity since 2010?  Is Pymel no longer actively developed?

Chad Dombrova

unread,
Oct 1, 2014, 9:58:16 PM10/1/14
to Maya Python Group
Hi,
Pymel is still very much under active development, as you can see here: https://github.com/LumaPictures/pymel/commits/master

We make a new release of pymel with each major release of Maya -- including updated docs -- and we deliver the bundle to Autodesk.  So the latest docs should be on their 2015 docs site.

The Pymel Google group is just totally redundant with this one, and should just be retired.  This list is capable of answering some very deep pymel questions and the developers of pymel are all here (hi!).

As for your question, I would do something like this:

    result = [x for x in myNode.getChildren(allDescendents=True, type='transform') if x.name().startswith('group')]

nodes have names. names are strings.  so at some point you're going to need to use strings to identify nodes.  

what pymel saves you from, among many other things, is needing to worry about whether that node's name changes, or whether your string represents a long, shortest-unique, or short name of a node, or whether two attributes are equal even though one is a shortname and one is a longname.  All of that stuff is just tedious for developers to deal with.  Since pymel has both a string and a lower-level representation of objects, it can be smarter about those things under the hood, so you don't have to micro-manage your code.

chad.



On Wed, Oct 1, 2014 at 6:15 PM, meeotch <mee...@gmail.com> wrote:
In writing a script to duplicate and add variation to a model a bunch of times, I found myself wondering about "best practices" for getting descendants of a given node by name.  For instance, if I've got the top node of my model copy, and I want to grab the feet to make them bigger.  I know that I can do it in a MEL/maya.cmds/procedural way with ls(), or by writing a function to recursively search using getChildren().  But the pymel docs make a point about how always having to use strings instead of nodes is one of the problems pymel is meant to solve.  So given that "under this hierarchy, find me node X" is such a common operation, I thought there must be a pythonic/pymelic way of doing it.

Related:  how come the General Pymel google group (and the pymel docs, for that matter) don't seem to have seen much activity since 2010?  Is Pymel no longer actively developed?

--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9978db97-529e-4a0a-896f-dbb256426801%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

meeotch

unread,
Oct 1, 2014, 11:17:58 PM10/1/14
to python_in...@googlegroups.com
Thanks - the list comprehension you gave certainly is pythonic.

w.r.t. docs - the thing that prompted my question was:  the 2015 Maya docs link to pymel 1.0.5 docs, the Installation section of which says:

Supported Platforms

Our goal is to support the 3 latest versions of Maya. At the time of this writing, that means 2008, 2009, and 2010.

That, and the google code page (third hit for "pymel" in google, after the maya docs) has a number of dead links on it, including all the luma pictures ones.  So the web-facing presence of pymel seems to have suffered significant bit-rot.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Chad Dombrova

unread,
Oct 2, 2014, 1:13:15 PM10/2/14
to Maya Python Group
whoops. yeah, definitely out of date.  we'll address that.  

chad.


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/f122e606-d457-4489-844a-0d52c0e52a89%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages