// MTScaleLockToggle.mel // Written by Markus Tessmann, Rock Farm Animation // ------------------------------------------------------- // // This script was written to make squash and stretch type scaling a bit easier // by locking one of scale channels of the current object. Make a shelf button calling // this script, and then click it again and again, to toggle through the locked state // on each of x, y, z and then back to nothing locked. // // I.E. to scale a cylinder into a disk, you want to scale in X and Z but not Y // so click on the MTScaleLockToggle button 2 times to lock Y. global proc MTScaleLockToggle() { vector $testLock; string $nodes[]; // load the string array with the list of currently selected items $nodes = `selectedNodes`; // load the test vector with the current state of the locked attribute int $LX = `getAttr -lock ($nodes[1] + ".sx")`; int $LY = `getAttr -lock ($nodes[1] + ".sy")`; int $LZ = `getAttr -lock ($nodes[1] + ".sz")`; $testLock = <<$LX, $LY, $LZ>>; // depending on what is locked, set the new locked state switch ($testLock) { case <<0, 0, 0>>: // nothing is locked, so lock sx for($item in $nodes) { string $aTtriBute = ($item + ".sx"); setAttr -lock 1 $aTtriBute; } break; case <<1, 0, 0>>: // sx is locked, so unlock it and lock sy for($item in $nodes) { string $aTtriBute = ($item + ".sx"); setAttr -lock 0 $aTtriBute; $aTtriBute = ($item + ".sy"); setAttr -lock 1 $aTtriBute; } break; case <<0, 1, 0>>: // sy is locked, so unlock it and lock sz for($item in $nodes) { string $aTtriBute = ($item + ".sy"); setAttr -lock 0 $aTtriBute; $aTtriBute = ($item + ".sz"); setAttr -lock 1 $aTtriBute; } break; case <<0, 0, 1>>: // sz is locked, so unlock it, leaving all unlocked for($item in $nodes) { string $aTtriBute = ($item + ".sz"); setAttr -lock 0 $aTtriBute; } break; default: // none of the above cases is true (i.e. more than one attribute is locked) // so set them all to unlocked for($item in $nodes) { string $aTtriBute = ($item + ".sx"); setAttr -lock 0 $aTtriBute; $aTtriBute = ($item + ".sy"); setAttr -lock 0 $aTtriBute; $aTtriBute = ($item + ".sz"); setAttr -lock 0 $aTtriBute; } break; } }