string $sSel[] = `ls -sl -dag -typ mesh`; // Notice the use of -dag and -typ switches. // Normally you're only selecting transform nodes in the Maya view ports. // The -dag is used to list all the shape nodes (among other things) as well. // We're only interested in mesh objects so with the -typ mesh we'll limit the // ls command to list meshes only in the selection int $iSize = size($sSel), $i; if($iSize > 0) { for($i = 0; $i < $iSize; $i++) { if($sSel[$i] == "myObjectShape") { // By looking in to the DG Node reference we know that the .dv attribute is a boolean. // However we define booleans as integers because there is no bool type in mel. int $bDv = `getAttr ($sSel[$i] + ".dv")`; // Now the $bDv variable contains the value of myObjectShape.dv // Let's find out if it's set if($bDv) { print("myObjectShape.dv is on\n"); // <Do other stuff what needs to be done if the attribute is set> } else { print("myObjectShape.dv is off\n"); // <Do other stuff what needs to be done if the attribute is not set> } } else warning("myObjectShape could not be found in the selection!\n"); } } else { warning("Nothing selected...\n"); }
string $sSel[] = `ls -sl -dag -typ mesh`; string $currSelection; for ($currSelection in $sSel) { if($currSelection == "myObjectShape") { int $bDv = `getAttr ($currSelection + ".dv")`; if($bDv) print("myObjectShape.dv is on\n"); else print("myObjectShape.dv is off\n"); } else warning("myObjectShape could not be found in the selection!\n"); } else warning("Nothing selected...\n");
foreach($foo in $bar) // blah blah else // blah blah