// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== //merge visible/selected layers // reorderLayers.mel // this script reorders all layers in the layerEditor // alphabetically or chronologically // // int $alphaOrder == 1 sort alphabetically // int $alphaOrder == 0 sort chronologically // global proc reorderLayers( int $alphaOrder ){ // set up the variables // string $type = "Render"; if (`tabLayout -query -selectTab DisplayLayerUITabLayout` == "DisplayLayerTab"){ $type = "Display"; } $gridLayout = ("LayerEditor" + $type + "LayerLayout"); string $orderArray[] = `gridLayout -query -gridOrder $gridLayout`; // order alphabetically // if ($alphaOrder){ // reorder the layers alphabetically $orderArray = `sort $orderArray`; // loop through the layers int $index = 1; for ($layer in $orderArray){ // there may be null layers if a layer was deleted as the // other layers' connections to the layerManager are not updated if ($layer != "(null)"){ // change the position of the layer in the layerEditor gridLayout -edit -position $layer $index $gridLayout; $index++; } } // order chronologically } else { // Render layer editor has default (master layer) displayed in the list, // so indeces start at 0. We have to compensate for Display layer editor, // because its indeces start at 1. int $count = size($orderArray) + ("Display" == $type); for ($layer in $orderArray){ // there may be null layers if a layer was deleted as the // other layers' connections to the layerManager are not updated if ($layer != "(null)"){ // the displayOrder attr states the order layers were created in int $index = $count - `getAttr ($layer + ".displayOrder")`; // change the position of the layer in the layerEditor gridLayout -edit -position $layer $index $gridLayout; } } } }