PDA

View Full Version : if, else question


rusted_nut
07-22-2003, 03:40 PM
I'm trying to write a line in a MEL script that will first check to see if a layer named “controllers” exists - if so, it does not create another controllers layer - if not, it will create a controllers layer.

Any help is appreciated.

klod
07-22-2003, 04:21 PM
hi,


this should works:

// Check if the "controllers" layer exists
string $controllers_layer[] = `ls -type "displayLayer" "controllers"`;
if (!size($controllers_layer))
{
// Check if an another object has the name "controllers" in the scene
if (!`objExists "controllers"`)
createDisplayLayer -name "controllers" -empty;
else
{
error ("a controllers object already exists in the scene. No layer created.");
}
}


in fact, there are 2 test to do: check if the display layer exists, and also check if there isn't an node named "controllers" in the scene. If you don't do this second check, and if such a node exists in the scene, the createDisplayLayer command would create a display layer named "controllers1".

Klod

rusted_nut
07-22-2003, 04:37 PM
thank you for your help kold!

CGTalk Moderation
01-15-2006, 04:00 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.