View Full Version : newb basic MEL question
cgbeige 07-20-2009, 07:55 PM I have a project with a lot of repetitive tasks performed on different object so I'm looking to make a script to simplify the work. What I want is to take the selected object and have it replace the variable in a bunch of different scripts I'll write (I'm good at checking the Echo Commands feedback and copying it for scripts). So here are two examples - I have something selected, and I want it to replace "pPlane1" in this command to hide it from Mental Ray:
setAttr "pPlane1.miHide" 1;
|
|
goleafsgo
07-20-2009, 08:24 PM
string $selection[] = `ls -sl`; // gets a list of everything that is selected
for ($item in $selection)
{
setAttr ($item + ".miHide") 1;
}
That should get you started.
GrogMcGee
07-20-2009, 08:26 PM
ninja'd
first you need to store the thing you have selected into a variable:
selections are strings in maya so you'll need a variable that's a string
string $mySelection[] = `ls -sl`; // the variable $mySelection is initialized with the shortname of the what is selected currently
// now we need to perform the operation on the selection
setAttr ($mySelection + ".miHide" ) 1; // the brackets say treat what follows as one thing, the + allows us to concate the value of mySelection with the (string) name of the attribute.
Now this isn't really that great since you're going to have to select each object individual and run the script... that balls annoying. Wouldn't it be great if you could select all the objects and iterate through them and with a single script execution?
Well you can by using a for loop:
string $mySelection[] = `ls -sl`;
for($each in $mySelection) { // each is a new variable that is made equal to one of the array of selected objects.
setAttr setAttr ($each + ".miHide" ) 1; //
}
I don't know that attribute so I'm assuming it's correct
cgbeige
07-20-2009, 09:28 PM
ninja'd
Well you can by using a for loop:
string $mySelection[] = `ls -sl`;
for($each in $mySelection) { // each is a new variable that is made equal to one of the array of selected objects.
setAttr setAttr ($each + ".miHide" ) 1; //
}
awesome - thanks. This is perfect but I had to change it to take out one setAttr and then realized that it was missing something so I have this now working fine:
string $mySelection[] = `ls -sl`;
for($each in $mySelection) { // each is a new variable that is made equal to one of the array of selected objects.
setAttr ($each + ".miDeriveFromMaya") 0;
setAttr ($each + ".miHide" ) 1;
}
I understand the syntax so this is a big help for the future. cheers
GrogMcGee
07-20-2009, 11:04 PM
and that typo is why you should never copy and paste code ever ;)
CGTalk Moderation
07-20-2009, 11:04 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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.