PDA

View Full Version : help with visibility script (MEL noob)


ACamacho
05-03-2006, 12:55 PM
Hello,

I'm trying to force myself to learn MEL. So far so good (well for the most part since I am not too technical. :)) but I have been having some trouble getting a script to run correctly. I'm making a script that will turn off primary visibility to objects that I select. I know this can be done through the spreadsheet editor but I am just doing it for learning purposes.

Here's the code:



//Pick Geometry
string $geoSel[] = eval("ls -sl");
int $geoCount = size($geoSel);
if ($geoCount==0) {
error "No Geometry in the scene or one hasn't been selected";
}
//Set Primary Visibility
for ($geoObj in $geoSel) {
if (`attributeExists "primaryVisibility" $geoObj`) {
setAttr ($geoObj + ".primaryVisibility") 0;
}
print "Done!\n";



Is there a step I am missing or just the wrong way to go about it? Another issue I seem to have is trying to have the script sift through a group and select the geometry in it and not the group node. Any help or point to the right direction would be awesome.

-Angel

Stucky
05-03-2006, 01:50 PM
Hi dude. First of all, you need an extra bracket ( } ) at the end to close the for loop. And second, you can't change that primaryVisibility attribute in transforms. I has to be in shapes. So you have to get each of the objects shape name, and then change that attribute. With this said, you have to use another kind of for loop. I will post the changes I made to your script, and if you don't understand something, please tell me, and I will explain. I don't do that now for the sake of time.

here it goes:


string $geoSel[] = `ls -sl`;
int $geoCount = size($geoSel);
if ($geoCount==0) {
error "No Geometry in the scene or one hasn't been selected";
}

//Set Primary Visibility
int $i;
string $geoShape[] = `listRelatives -shapes $geoSel[$i]`;

for ($i=0; $i<size($geoSel); $i++) {

if (`attributeExists "primaryVisibility" $geoShape[$i]`)
setAttr ($geoShape[$i] + ".primaryVisibility") 0;

}
print "Done!\n";

Hope it helps...

-S

ACamacho
05-06-2006, 10:19 PM
I apologize for replying so late but thank you very much Stucky! It seems the changes were mostly a different loop and adding a "listRelatives". I get it for the most part and it works. :)

Mikademius
05-07-2006, 02:21 PM
I recently wrote a tutorial dealing with exactly that :)
Here it is :

http://www.final3.com/html/tutorials/mel_ShapeEditor_01.htm

CGTalk Moderation
05-07-2006, 02:21 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.