// =========================================================================== // 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: Nov, 2003 // // Description: // This script provides an option box dialog for the search replace naming operation. // // Input Arguments: // boolean showOptionBox true - show the option box dialog // false - just execute the command // // Procedure Name: // setOptionVars // // Description: // Initialize the option values. // // Input Arguments: // Whether to set the options to default values. // // Return Value: // None. // proc setOptionVars(int $forceFactorySettings) { if ($forceFactorySettings || !`optionVar -exists psrSearch`) { optionVar -stringValue psrSearch ""; } if ($forceFactorySettings || !`optionVar -exists psrReplace`) { optionVar -stringValue psrReplace ""; } if ($forceFactorySettings || !`optionVar -exists psrWhat`) { // hierarchy optionVar -intValue psrWhat 1; } } // // Procedure Name: // searchReplaceNamesSetup // // Description: // Update the state of the option box UI to reflect the option values. // // Input Arguments: // parent - Top level parent layout of the option box UI. // Required so that UI object names can be // successfully resolved. // // forceFactorySettings - Whether the option values should be set to // default values. // // Return Value: // None. // global proc searchReplaceNamesSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls. string $search = `optionVar -query psrSearch`; if (`textFieldGrp -exists searchReplaceSearchName`) { textFieldGrp -e -tx $search searchReplaceSearchName; } string $replace = `optionVar -query psrReplace`; if (`textFieldGrp -exists searchReplaceReplaceName`) { textFieldGrp -e -tx $replace searchReplaceReplaceName; } int $what = `optionVar -query psrWhat`; if (`radioButtonGrp -exists searchReplaceOnWhat`) { radioButtonGrp -e -select ($what) searchReplaceOnWhat; } } // // Procedure Name: // searchReplaceNamesCallback // // Description: // Update the option values with the current state of the option box UI. // // Input Arguments: // parent - Top level parent layout of the option box UI. Required so // that UI object names can be successfully resolved. // // doIt - Whether the command should execute. // // Return Value: // None. // global proc searchReplaceNamesCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then // perform the command. optionVar -stringValue psrSearch `textFieldGrp -query -tx searchReplaceSearchName`; optionVar -stringValue psrReplace `textFieldGrp -query -tx searchReplaceReplaceName`; optionVar -intValue psrWhat `radioButtonGrp -q -sl searchReplaceOnWhat`; if ($doIt) { performSearchReplaceNames 0; addToRecentCommandQueue "performSearchReplaceNames 0" "SearchReplaceNames"; } } // // Procedure Name: // searchReplaceNamesOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc searchReplaceNamesOptions() { // Name of the command for this option box. // string $commandName = "searchReplaceNames"; // Build the option box actions. // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); // Get the option box. // string $layout = getOptionBox(); setParent $layout; // Pass the command name to the option box. // setOptionBoxCommandName($commandName); // Activate the default UI template. // setUITemplate -pushTemplate DefaultTemplate; // Turn on the wait cursor. // waitCursor -state 1; tabLayout -scr true -tv false; string $parent = `columnLayout -adjustableColumn 1`; textFieldGrp -label (uiRes("m_performSearchReplaceNames.kSearchFor")) -tx "" searchReplaceSearchName; textFieldGrp -label (uiRes("m_performSearchReplaceNames.kReplaceWith")) -tx "" searchReplaceReplaceName; radioButtonGrp -numberOfRadioButtons 3 -cw4 170 100 100 100 -label "" -label1 (uiRes("m_performSearchReplaceNames.kHierarchy")) -label2 (uiRes("m_performSearchReplaceNames.kSelected")) -label3 (uiRes("m_performSearchReplaceNames.kAll")) -annotation (uiRes("m_performSearchReplaceNames.kSpecifySceneObjectAnnot")) searchReplaceOnWhat; // Turn off the wait cursor. // waitCursor -state 0; // Deactivate the default UI template. // setUITemplate -popTemplate; // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performSearchReplaceNames.kReplace")) -command ($callback + " " + $parent + " " + 1) $applyBtn; // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $parent + " " + 1) $resetBtn; // Set the option box title. // setOptionBoxTitle (uiRes("m_performSearchReplaceNames.kSearchReplaceOptions")); // Customize the 'Help' menu item. // setOptionBoxHelpTag( "searchReplaceNames" ); // Set the current values of the option box. // eval (($setup + " " + $parent + " " + 0)); // Show the option box. // showOptionBox(); } // // Procedure Name: // searchReplaceNamesHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string searchReplaceNamesHelp() { return " Command: searchReplaceNames - renames objects based on their current names.\n" + "Selection: none"; } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // // Return Value: // None. // proc string assembleCmd() { setOptionVars(false); string $search = `optionVar -query psrSearch`; string $replace = `optionVar -query psrReplace`; string $onWhat = "hierarchy"; int $what = `optionVar -query psrWhat`; if ($what == 2) { $onWhat = "selected"; } else if ($what == 3) { $onWhat = "all"; } if (size($search) > 0 && size($replace) > 0) { string $cmd = "searchReplaceNames"; $cmd += (" \""+$search+"\" \""+$replace+"\" \""+$onWhat+"\""); return $cmd; } else { error (uiRes("m_performSearchReplaceNames.kValidSearchError")); } return ""; } // // Procedure Name: // performSearchReplaceNames // // Description: // Perform the searchReplaceNames command using the corresponding // option values. This procedure will also show the option box // window if necessary as well as construct the command string // that will invoke the searchReplaceNames command with the current // option box values. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // // Return Value: // None. // global proc string performSearchReplaceNames(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: // Retrieve the option settings // setOptionVars(false); // Get the command. // $cmd = `assembleCmd`; // Execute the command with the option settings. // evalEcho($cmd); break; // Show the option box. // case 1: searchReplaceNamesOptions; break; // Return the command string. // case 2: // Retrieve the option settings. // setOptionVars (false); // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }