// =========================================================================== // 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. // =========================================================================== // // // Creation Date: Aug 15 1996 // // Description: // This script initializes the Shelf. Initialization involves // determining the initial Shelf preferences, creating the UI and // setting the initial visibility. // { // Check Shelf tab preferences. // int $i, $j, $k, $nShelves; int $usePrefs = false; int $buildShelvesFromDisk = false; string $name, $proc; string $shelfDir, $sysReturn, $tmp; string $unsortedFiles[]; string $diskFiles[]; // Will hold the list of files in the shelves directory string $names[]; // // get a list of files in the shelves directory // string $shelfDirs = `internalVar -userShelfDir`; string $shelfArray[]; string $PATH_SEPARATOR = `about -win`? ";" : ":"; tokenize($shelfDirs, $PATH_SEPARATOR, $shelfArray); for( $i = 0; $i < size($shelfArray); $i++ ) { $shelfDir = $shelfArray[$i]; string $shelfDirFiles[] = `getFileList -folder $shelfDir -fs "shelf_*.mel"`; int $nth = size($unsortedFiles); for($j = 0; $j < size($shelfDirFiles); $j++) { if ($shelfDirFiles[$j] == "shelf_Cloth.mel") { continue; } // Drop this file if the same name already appears earlier int $foundMatch = 0; for($k = 0; $k < size($unsortedFiles); $k++) { if( $unsortedFiles[$k] == $shelfDirFiles[$j] ) { $foundMatch = 1; break; } } if( !$foundMatch ) { $unsortedFiles[$nth] = $shelfDirFiles[$j]; $nth++; } } } $diskFiles = sort ($unsortedFiles); $nShelves = size($diskFiles); // Fix shelf items that have obsolete or incorrect commands // associated with them. Once the shelves have been fixed, // turn on a variable so that they are not processed again // in this version. string $nowVer = `about -v`; string $lastVer = ""; if( `optionVar -exists shelvesLastUpdated` ) { $lastVer = `optionVar -q shelvesLastUpdated`; } if (0 == $nShelves) { // No existing shelves, so use the default shelf setup. createDefaultShelves(); } else { // // Check that shelves were built at some point, if not create default shelves. if ("" == $lastVer) { createDefaultShelves(); } // // Compare existing prefs with what's in the directory. // It is preferable to use prefs as they contain order info also. // int $nArr = `optionVar -q numShelves`; string $prefFiles[]; // Will hold list of shelf files in userPrefs.mel string $combinedFiles[]; // Will hold list of all shelf files in userPrefs.mel and shelves directory string $aligns[]; // Shelf alignment from prefs // build array of files from the previous shelf // for ($i = 0; $i < $nArr; $i++) { $prefFiles[$i] = (`optionVar -q ("shelfFile"+($i+1))` + ".mel"); $combinedFiles[$i] = $prefFiles[$i]; $aligns[$i] = "left"; if ( `optionVar -ex ("shelfAlign"+($i+1))` ) $aligns[$i] = `optionVar -q ("shelfAlign"+($i+1))`; } // build array of files that combines the files from the previous // shelf with any new files added to the prefs // for ($i = 0; $i < $nShelves; $i++) { if (0 == stringArrayContains($diskFiles[$i], $prefFiles)) { int $index = size($combinedFiles); appendStringArray($combinedFiles, stringToStringArray($diskFiles[$i], " "), 1); $aligns[$index] = "left"; } } int $nCombined = size($combinedFiles); // Check that all the shelves in $combinedFiles exist // $usePrefs = true; for($i = 0; $i < $nCombined; $i++) { // Search in shelves folder // If not found, search in default shelf scripts if(0 == stringArrayContains($combinedFiles[$i], $diskFiles)) { // If not found or has been loaded but is not longer in prefs folder, remove shelf from the list if( (!`exists $combinedFiles[$i]`) || (`optionVar -q ("shelfLoad"+($i+1))`) ) { // Don't break on Custom shelf if($combinedFiles[$i] == "shelf_Custom.mel") { continue; } // Remove shelf from $combinedFiles for($j = $i+1; $j < $nCombined; $j++) { string $tempName = $combinedFiles[$j]; int $tempLoad = `optionVar -q ("shelfLoad"+($j+1))`; $combinedFiles[$j-1] = $tempName; optionVar -intValue ("shelfLoad"+$j) $tempLoad; } // A shelf has been removed, adjust variables accordingly stringArrayRemoveAtIndex( ($nCombined - 1), $aligns ); stringArrayRemoveAtIndex( ($nCombined - 1), $combinedFiles ); optionVar -remove ("shelfLoad"+$nCombined) -remove ("shelfName"+$nCombined) -remove ("shelfAlign"+$nCombined) -remove ("shelfFile"+$nCombined); $nCombined--; $i--; // If no shelves exist, don't use prefs if($nCombined < 1) { $usePrefs = false; break; } } } } // // Check if there are any default shelves saved in the prefs folder, if not build the shelf straight from $diskFiles. // This allows users to overwrite all of our default shelves. // First make sure shelves exist and that default shelves were built at some point if ( ($nCombined > 0) && `optionVar -exists shelvesLastUpdated` ) { $buildShelvesFromDisk = true; string $startupDir = ( getenv("MAYA_LOCATION") + "/scripts/shelves/" ); string $defShelfFiles[] = `getFileList -folder $startupDir -fs "shelf_*.mel"`; for ($i = 0; $i < $nShelves; $i++) { if ( stringArrayContains($diskFiles[$i], $defShelfFiles) || ($diskFiles[$i] == "shelf_Custom.mel") ) { // A default shelf has been found $buildShelvesFromDisk = false; break; } } } if ($buildShelvesFromDisk) { // Create shelves from shelves directory // The double backslash is to prevent the '.' from being // used as a wildcard. // for ($i = 1; $i <= $nShelves; $i++) { $tmp = $diskFiles[$i-1]; $proc = `substitute "\\.mel" $tmp ""`; $name = `substitute "shelf_" $proc ""`; optionVar -stringValue ("shelfName"+$i) $name -stringValue ("shelfFile"+$i) $proc -stringValue ("shelfAlign"+$i) "left" -intValue ("shelfLoad"+$i) true; } optionVar -intValue numShelves $nShelves; } else { if ($usePrefs) { for($i = 1; $i <= $nCombined; $i++) { // Since the files exist, create the shelves. // The double backslash is to prevent the '.' from being // used as a wildcard. // $tmp = $combinedFiles[$i-1]; $proc = `substitute "\\.mel" $tmp ""`; $name = `substitute "shelf_" $proc ""`; string $align = $aligns[$i-1]; optionVar -stringValue ("shelfName"+$i) $name -stringValue ("shelfAlign"+$i) $align -stringValue ("shelfFile"+$i) $proc; // The shelfLoad optionVar is only true for shelves being loaded from $diskFiles if ( 0 == stringArrayContains($combinedFiles[$i-1], $diskFiles) ) { optionVar -intValue ("shelfLoad"+$i) false; } else { optionVar -intValue ("shelfLoad"+$i) true; } } //All the shelves in $combinedFiles have been created so reset numShelves optionVar -intValue numShelves $nCombined; } else { // Create the default shelves createDefaultShelves(); } } if( $nowVer != $lastVer ) { if ( 0 == stringArrayContains("shelf_Sculpting.mel", $combinedFiles) ) { int $nbSh = `optionVar -q numShelves`; $nbSh++; optionVar -iv numShelves $nbSh; optionVar -stringValue ("shelfName"+$nbSh) "Sculpting" -stringValue ("shelfFile"+$nbSh) "shelf_Sculpting" -stringValue ("shelfAlign"+$nbSh) "left" -intValue ("shelfLoad"+$nbSh) false; } } } // Create the Shelf. // if (`exists shelf`) { eval "source shelf"; } // Attach a callback so we know when the Shelf is made visible or // invisible. // setUIComponentStateCallback("Shelf", "shelfVisibilityStateChange"); // Set the initial height of the Shelf in the main window. // string $shelfWorkspaceControl = getUIComponentToolBar("Shelf", false); if (`workspaceControl -q -horizontal $shelfWorkspaceControl`) { workspaceControl -e -heightProperty "fixed" -initCallback "shelfInitCallback" $shelfWorkspaceControl; } else { workspaceControl -e -widthProperty "fixed" -initCallback "shelfInitCallback" $shelfWorkspaceControl; } updateShelfInitialSize($shelfWorkspaceControl); // Set the Shelf's initial visibility. // int $shelfIsVisible = `optionVar -q isShelfVisible`; setShelfVisible($shelfIsVisible); // If the Shelf is hidden, build shelves anyway (since // they won't be built on startup if not shown) global int $gShelfCreated = false; if(!$shelfIsVisible && !$gShelfCreated) { buildShelves(); $gShelfCreated = true; } if( $nowVer != $lastVer ) { optionVar -sv shelvesLastUpdated $nowVer; source updateShelves.mel; } } global proc int getShelfInitialWidth() { if (`optionVar -q shelfTabsVisible`) { return 64; } else { return 64 - 18; } } global proc int getShelfInitialHeight() { if (`optionVar -q shelfTabsVisible`) { return 64; } else { return 64 - 18; } } global proc updateShelfInitialSize(string $shelfWorkspaceControl) { if (`workspaceControl -q -exists $shelfWorkspaceControl`) { if (`workspaceControl -q -horizontal $shelfWorkspaceControl`) { updateShelfInitialHeight($shelfWorkspaceControl); } else { updateShelfInitialWidth($shelfWorkspaceControl); } } } global proc updateShelfInitialWidth(string $shelfWorkspaceControl) { if (`workspaceControl -q -exists $shelfWorkspaceControl`) { int $shelfWidth = getShelfInitialWidth(); workspaceControl -e -initialWidth $shelfWidth $shelfWorkspaceControl; } } global proc updateShelfInitialHeight(string $shelfWorkspaceControl) { if (`workspaceControl -q -exists $shelfWorkspaceControl`) { int $shelfHeight = getShelfInitialHeight(); workspaceControl -e -initialHeight $shelfHeight $shelfWorkspaceControl; } } global proc shelfInitCallback(string $shelfWorkspaceControl) { evalDeferred("updateShelfInitialSize(\"" + $shelfWorkspaceControl + "\")"); } global proc int shelfVisibilityStateChange( int $newState, string $layout) // // Description: // This procedure is called whenever the visibility state of the // Shelf is changed. // // Create the contents of the Shelf when it is shown for the first // time. // // Arguments: // newState - The new visibile state of the Shelf. // // layout - The parent layout for the Shelf. // // Returns: // true - If the change of state is to be allowed. // // false - If the state change is rejected. // { global int $gShelfCreated = false; int $result = true; if ($newState) { // Load the contents of the Shelf right before it becomes visible // for the very first time. // if (!$gShelfCreated) { buildShelves(); $gShelfCreated = true; } } else { } // Defer these commands because this proc is called when the visibility // state is about to change. This proc must return true to accept // the state change. After this proc returns then restore the // panel focus and update the pref menu. // evalDeferred("restoreLastPanelWithFocus(); updatePrefsMenu();"); return $result; } proc makeShelfOptionVar (string $name, int $shelf, string $version) { // Construct shelf optionVars like // // optionVar // -stringValue shelfName1 "Polygons" // -stringValue shelfVersion1 "2010" // -stringValue shelfFile1 "shelf_Polygons" // -stringValue shelfAlign1 "left" // -intValue shelfLoad1 false // string $shelfName = "shelfName" + $shelf; string $shelfVersion = "shelfVersion" + $shelf; string $shelfFile = "shelfFile" + $shelf; string $shelfLoad = "shelfLoad" + $shelf; string $shelfAlign = "shelfAlign" + $shelf; string $fileName = $name; if ($name == "Custom") { $fileName = "Shelf1"; } optionVar -stringValue $shelfName $name -stringValue $shelfVersion $version -stringValue $shelfFile ("shelf_" + $fileName) -stringValue $shelfAlign "left" -intValue $shelfLoad false ; } global proc createDefaultShelves() { int $nShelves = 0; // // No existing shelves, so use the default shelf setup. // // // Create a new set of default shelves // // The following table defines the order of shelves // available for each version of Maya. // // All Versions Maya LT // ------------------------------------------------------------------------ // General (1) // Curves/Surfaces (1) Curves/Surfaces (2) // Polygons (2) Polygons (3) // Sculpting (3) Sculpting (4) // #ifdef MAYA_WANT_MUDBOX // Rigging (4) Rigging (5) // Animation (5) Animation (6) // Rendering (6) Shading (7) // FX (7) // FXCaching (8) // Custom (9) // // XGen (10) // #ifdef MAYA_WANT_XGEN // MASH (11) // #ifdef MAYA_WANT_MASH // Motion Graphics (12) // #ifdef MAYA_WANT_MASH // // All shelf names MUST be capitalized so they can be matched with their L10N tags // // Note that each shelf may have individual items available // only in certain versions. See each shelf script for these // items. // // In UI label = "Curves / Surfaces" -> see shelfLabel.mel makeShelfOptionVar ("CurvesSurfaces", ++$nShelves, "2010"); makeShelfOptionVar ("Polygons", ++$nShelves, "2010"); makeShelfOptionVar ("Sculpting", ++$nShelves, "2016"); // // --- Complete --- // // Create the Deformation, Animation, // and Rendering / Shading shelves. // makeShelfOptionVar ("Rigging", ++$nShelves, "2016"); makeShelfOptionVar ("Animation", ++$nShelves, "2010"); makeShelfOptionVar ("Rendering", ++$nShelves, "2010"); // Fluid edit license check will be in shelf_FX.mel makeShelfOptionVar ("FX", ++$nShelves, "2010"); // // Add the unlimited shelves: FX Caching // makeShelfOptionVar ("FXCaching", ++$nShelves, "2010"); // Add empty shelf. // makeShelfOptionVar ("Custom", ++$nShelves, "2010"); optionVar -stringValue shelfItemSize "Small" -stringValue shelfItemStyle "iconOnly" -intValue isShelfVisible true -intValue isShelfLoad true -intValue numShelves $nShelves; // When the default shelves are loaded then we must rename // the option var for some shelves // to match the corresponding shelf labels. // // If the file and label don't match then the shelves won't load // from preferences and retain the user's order (they'll // come back in alphabetical order). // $nShelves = `optionVar -q numShelves`; optionVar -stringValue ("shelfFile" + $nShelves) "shelf_Custom"; }