PDA

View Full Version : Quick MEL question...


mshemons
03-06-2009, 03: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?

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

TroyC
03-06-2009, 03:40 PM
And for selected items into the array use:

$arrayVariable = `ls -sl`;

siproductions
03-06-2009, 03:41 PM
ah thanks TroyC missed that :)

TroyC
03-06-2009, 03:58 PM
Yep.

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

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

:thumbsup:

siproductions
03-06-2009, 04: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.

mshemons
03-06-2009, 05: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-06-2009, 05: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.