View Full Version : MEL noob question

10 October 2010, 12:33 PM
Hi Guys, i've started getting into MEL and have following question.
Let's say I have a sphere and want to translate it 5 units into X. I'll type
"setAttr pSphere1.translateX 5;"

But what do I type instead of "pSphere1", if I would like to translate all geometry
in my scene i.e. i've 3 spheres. Is there something like a placeholder for polygon object
or something like that?

Thx in advance.

and sorry for that noobish question, but i've never been into programming at all :(

10 October 2010, 12:47 PM
Thanks for the fast answer :)
Gonna try it out right away

10 October 2010, 12:49 PM
there are no "object placeholders" or anything like that in MEL, other than "variables". There are generally two basic methods for this, either apply the command to a list of objects, or make a loop over a list of objects and apply the command. the former method is usually much more efficient, but in the case of setAttr you can't give it a list to work on.

The most complex thing you usually need to figure out is how to make your list? making a list is done using the `ls` command (and listRelatives, listConnections, listHistory, etc...), but what do you want a list of? an understanding of nodes is really required to do this properly. Lets say you just wanted a list of everything in your scene that started with: "pSphere" you could do:

string $myObjects[] = `ls "pSphere*"`;maybe you don't want things based on names? maybe you wanted all polygon mesh objects? you would do:
string $myObjects[] = `ls -type "mesh"`;and so on... what you want a list of can be very complex and depends on what you are trying to do with the objects you want in a list.

once you have this variable array (list) you can do stuff with it:

for ($item in $myObjects)
setAttr ($item + ".translateX") 5;
however, if you just want to move stuff, there is a move command, and you can give that a full list in one go:
move -a 5 0 0 $myObjects;which is kinda better.

This is the fundamentals of many programming languages, not least MEL, and you won't be able to do any MEL programming until you get this. There is too much to do it with a single forum post, so I suggest you go and read this:

Maya > Help (F1) > User Guide > MEL and Expressions > Values and Variables
(and then work through the rest of MEL and Expressions!)

CGTalk Moderation
10 October 2010, 12:49 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.