View Full Version : Quick MEL question...

03 March 2009, 04:20 PM
Is there an easy way to loop through a selection in MEL? In MAXscript you can easily do it like this:

For object in selection do
object.pos.x = 10

and it would set all of the objects' x position to 10. How would I do the same thing in MEL?

03 March 2009, 04:36 PM
$arrayVariable = {"One","Two","Three","Four","Five"};
for ($i in $arrayVariable)
print $i;

03 March 2009, 04:40 PM
And for selected items into the array use:

$arrayVariable = `ls -sl`;

03 March 2009, 04:41 PM
ah thanks TroyC missed that :)

03 March 2009, 04:58 PM

And just to be 100 percent clear, the way to use the variable to set the value is:

setAttr ($i + ".tx") 10;


03 March 2009, 05:37 PM
Indeed and for further info there is some good docs on the basics under MayaHelp:UsingMaya:General:Mel and Expressions. The Controling the flow of your script section should go over the different types of loops you can use.

03 March 2009, 06:10 PM
Thanks guys! That worked great. I was pretty adept in maxscript before I switched to maya so now I just have to learn all of the syntax and tricks in mel.

CGTalk Moderation
03 March 2009, 06:10 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.