PDA

View Full Version : How to implement foreach command in mel


flaeticia
02-27-2008, 09:19 AM
Hello :) simple question as you can see in the title, i want to know how it is possible to implement foreach command in mel.

considering that, i like to do something like that :

foreach(object o in CurrentScene.SelectAll(PolygonalObject))
{
o.color = Color.Black;
}

...
the fact is, this code is more c# like, but i want to implement something like this :)

is this possible, and could you give me some element to start ?
thanks in advance,

kind regards :)

greatPumpkin
02-27-2008, 10:03 AM
something like this would work, though meshes have no such color attribute, so depending on what you want to do you'd need a couple of more lines inside the loop:

string $meshes[] = `ls -type "mesh"`;
for($obj in $meshes)
{
setAttr ($obj + ".color") 0 0 0;
}

Omita
02-27-2008, 08:10 PM
is this possible, and could you give me some element to start ?
thanks in advance,


Someone already gave you the answer, but hit "F1" and run through the Mel help tab. It will save you some woes. The answer to your question is also in the Maya docs.

http://boards.omita.com/getMelHelp.png

-h

ewerybody
02-28-2008, 10:30 AM
or the other way around: objects are colored through materials. You could traverse all materials and set the color to black

for ($material in `ls -materials`)
{
setAttr ($material + ".color") 0 0 0;
}

problem is: there might be already something plugged into the color-attribute on the shader. You'd have that problem eitherway. But of course you can turn the textures colorgain itself as well:

for ($material in `ls -materials`)
{
if (`connectionInfo -isDestination ($material + ".color")`)
for ($fileNode in `listConnections -type file $material`)
setAttr ($fileNode + ".colorGain") 0 0 0;
else
setAttr ($material + ".color") 0 0 0;
}

flaeticia
11-13-2008, 01:52 PM
hey !!
great :)
thanks a lot for your answers

sorry for the late, but i was really really busy :)

CGTalk Moderation
11-13-2008, 01:52 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.