Once you get familiarized with MEL scripting, you will inevitably want to traverse the complex nodes structure that Maya sets up for each object. Just to quickly summarize the node system, all primitives have a ‘transform,’ ‘shape,’ ‘make,’ material node, and possibly some other nodes. When you call for the name of an object, you are actually only accessing the base ‘transform’ object. If you want more information or attributes, you’ll need to traverse the node system to access the others. I go over this more in depth in my book YSYT somewhere in chapter 7 or 8 (I think), and also in 12.
To query the name of a Shape or Make node, use a combination of the commands listHistory, listConnections, and/or listRelatives from the transform node name string. Use backticks to encapsulate the commands to return the connected names, and you may need to go a few levels down. A good example of this is my function for getting an existing material on an object. (note, getting a material, moves passed the Make and Shape nodes, but it’s still a good example.)
string $Name = "nurbsSphere1";
string $FF[] = `listRelatives $Name`;
string $GG[] = `listConnections $FF[0]`;
string $HH[] = `listConnections $GG[0]`;
The zeroth member of each $FF and $GG array is the lead string for that level. So you may need to print the contents of these arrays and you’ll find the pattern leading to the Make or Shape node. In most cases it will be the first (second index) from the listed Relatives, or listed Connections.
Some things to remember: Every release of Maya is different, so test your indexes prior to hard-coding. You may need to shift some index numbers, but the listRelatives and listConnections should be in the right configuration. To get the material shader, you’ll need to make a distinction between objects with the initial material and objects with a substituted material. Then it will be stored in the final array ($HH in the example above). Maya 5 through 6.5 is the third index, whereas newer versions have it stored at the 4 or 5 spot. If you want to make a robust function, you can always use the “version” command set up a conditional case programming structure.
Hmmmm interesting…. in terms of shape nodes basically that controls aspects that define geometry? So manipulation of the shape nodes attributes can blend shapes effectively?
Yeah, and no.
Shape nodes are the representation of the core geometry. I.e. the Nurbs and Polygon characteristics of the geometry. Think of this as the “nurbs-ness” or the “poly-ness” of the geometry.
As for blending, it depends on how you define blending. If you are thinking of the term “Blendshape,” then no. This won’t affect the “Blendshape” per se, but it will allow the creation and manipulation of nurbs to have the same UV count, which is imperative for all “Blendshape” preparation. However, Shape Node manipulation doesn’t always guarantee a “blendshape” match. It’s best to make all geometry with the desired UV count first, then modify the geometry to the new shape–then run the blendshape utility. Or, you can rebuild, but this might modify the geometry into a slightly altered shape from the original, and it removes the Make Node properties.