// Layer Grouper // Version 0.1 // by Doug Letterman // 2001-05-23 // This MEL script for Maya 3.0 allows you to show, hide, reference, or template groups // of display layers based on their color attribute. // ATTRIBUTES: This script adds two (2) attributes, proxyColor and hiResColor, to the layerManager. // COMMAND: layerGrouper [string mode] // ARGUMENTS: "proxy" - shows all layers with designated proxy colors, hides hiRes layers // "hiRes" - shows all layers with designated hiRes colors, hides proxy layers // "all" - shows both proxy and hiRes layers // "none" - hides both proxy and hiRes layers // default "window" - shows Layer Grouper Window global proc layerGrouper(string $mode) { switch ($mode) { case "proxy": toggleLayers(1,0); break; case "hiRes": toggleLayers(0,1); break; case "all": toggleLayers(1,1); break; case "none": toggleLayers(0,0); break; default: layerGrouperWindow; break; } } global proc int findLayerGroups() { if( `objExists layerManager.proxyColor` && `objExists layerManager.hiResColor`) { return 1; } else { return 0; } } global proc int makeLayerGroups() { if ( `objExists layerManager` ) { int $green = 23; // green is the default proxy color int $red = 12; // red is the default hiRes color addAttr -ln proxyColor -at short layerManager; setAttr layerManager.proxyColor $green; addAttr -ln hiResColor -at short layerManager; setAttr layerManager.hiResColor $red; return 1; } else { return 0; } } global proc toggleLayers( int $proxyVis, int $hiResVis ) { int $proxyColor = `getAttr layerManager.proxyColor`; int $hiResColor = `getAttr layerManager.hiResColor`; int $myColor; string $layers[] = `ls -typ displayLayer`; // print ("// proxyColor: " + $proxyColor + " hiResColor: " + $hiResColor + " //\n"); for ($node in $layers) // Process the layers { $myColor = `getAttr ($node+".c")`; // print ("// Layer: " + $node + " Color: " + $myColor + " //\n"); // If this layer is either a proxy color if ($myColor == $proxyColor) { // print ("// " + $node +" visibility should be " + $hiResVis + " //\n"); // Set the layer's visibility to the value specified setAttr ($node+".visibility") $proxyVis; } // If this layer is either a hiRes color else if ($myColor == $hiResColor) { // print ("// " + $node +" visibility should be " + $hiResVis + " //\n"); // Set the layer's visibility to the value specified setAttr ($node+".visibility") $hiResVis; } } // Now close the Layer Grouper if it's open if (`window -exists layerGrouperWindow`) deleteUI layerGrouperWindow; } global proc sliderColorReplace (string $layerColorAttr, string $slider) { int $color = getCurrentColor( $layerColorAttr ); colorIndexSliderGrp -e //-v $color -cc ("changeObjColor " + $layerColorAttr ) $slider; scriptJob -p $slider -rp -attributeChange $layerColorAttr ("updateColor "+$layerColorAttr + " " + $slider); updateColor $layerColorAttr $slider; } global proc updateColor (string $layerColorAttr, string $slider) { // check to set the correct initial settings int $color = getCurrentColor( $layerColorAttr ); colorIndexSliderGrp -e -v $color $slider; } proc int getCurrentColor( string $layerColorAttr ) { int $color = `getAttr $layerColorAttr`; if ( $color < 1 ) { $color = 0; // If out of range select the invisible color } else if ( $color > 31 ) { $color = 31; } return $color + 1; } proc changeColor ( string $layerColorAttr, string $slider ) { int $color = `colorIndexSliderGrp -q -v $slider` - 1; if( catch(`setAttr $layerColorAttr $color`) ) { int $oldColor = getCurrentColor( $layerColorAttr ); colorIndexSliderGrp -e -v $oldColor $slider; } } global proc layerGrouperWindow () { // First check and see if the UI window exists, if yes, then rebuild it. if (`window -exists layerGrouperWindow`) deleteUI layerGrouperWindow; // Next check and make sure the attributes for proxyColor and hiResColor have been defined. // If no, then create them using makeLayerGroups(). if ( findLayerGroups() != 1) { makeLayerGroups(); } $proxyColor = `getCurrentColor layerManager.proxyColor`; $hiResColor = `getCurrentColor layerManager.hiResColor`; window -title "Layer Grouper" -s 0 -w 350 -h 100 layerGrouperWindow; columnLayout -columnAttach "left" 5 -rowSpacing 10 -columnWidth 300; string $proxyButton = `button -label "View Proxy Layers" -align "left" -width 150`; string $proxySlider = `colorIndexSliderGrp -label "Color" -invisible 1 -min 2 -max 32 -cw 1 50 -cw 2 50 -cw 3 150`; separator -h 4 -w 282 -style "single"; string $hiResButton = `button -label "View HiRes Layers" -align "left" -width 150`; string $hiResSlider = `colorIndexSliderGrp -label "Color" -invisible 1 -min 2 -max 32 -cw 1 50 -cw 2 50 -cw 3 150`; // now add the functionality sliderColorReplace layerManager.proxyColor $proxySlider; sliderColorReplace layerManager.hiResColor $hiResSlider; colorIndexSliderGrp -e -v $proxyColor -cc ("changeColor layerManager.proxyColor " + $proxySlider ) $proxySlider; colorIndexSliderGrp -e -v $hiResColor -cc ("changeColor layerManager.hiResColor " + $hiResSlider ) $hiResSlider; string $proxyCommand = ("toggleLayers(1,0)"); string $hiResCommand = ("toggleLayers(0,1)"); button -edit -command $proxyCommand $proxyButton; button -edit -command $hiResCommand $hiResButton; showWindow layerGrouperWindow; }