// =========================================================================== // 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. // =========================================================================== // // Procedure Name: // performReplaceObjects // // Description: // // // Input Arguments: // $option : Whether to set the options to default values. // Return Value: // None // proc setOptionVars (int $forceFactorySettings) { if ($forceFactorySettings || !`optionVar -exists "replaceObjRotate"`) optionVar -intValue "replaceObjRotate" 1; if ($forceFactorySettings || !`optionVar -exists "replaceObjScale"`) optionVar -intValue "replaceObjScale" 1; if ($forceFactorySettings || !`optionVar -exists "replaceObjCopy"`) optionVar -intValue "replaceObjCopy" 1; if ($forceFactorySettings || !`optionVar -exists "replaceObjKeepOriginal"`) optionVar -intValue "replaceObjKeepOriginal" 1; } global proc replaceObjectsSetup (string $parent, int $forceFactorySettings) { setOptionVars($forceFactorySettings); setParent $parent; checkBoxGrp -edit -v1 `optionVar -q replaceObjRotate` replaceObjRotate; checkBoxGrp -edit -v1 `optionVar -q replaceObjScale` replaceObjScale; radioButtonGrp -edit -select `optionVar -q replaceObjCopy` replaceObjCopy; checkBoxGrp -edit -v1 `optionVar -q replaceObjKeepOriginal` replaceObjKeepOriginal; } global proc replaceObjectsCallback (string $parent, int $doIt) { setParent $parent; optionVar -intValue "replaceObjRotate" `checkBoxGrp -query -v1 replaceObjRotate` ; optionVar -intValue "replaceObjScale" `checkBoxGrp -query -v1 replaceObjScale` ; optionVar -intValue "replaceObjCopy" `radioButtonGrp -query -select replaceObjCopy` ; optionVar -intValue "replaceObjKeepOriginal" `checkBoxGrp -query -v1 replaceObjKeepOriginal` ; if ($doIt) { performReplaceObjects 0; string $tmpCmd = "performReplaceObjects 0 "; addToRecentCommandQueue $tmpCmd "Replace Objects"; } } proc createCmdOptionsUI () { // Global template variables for form spacing global int $gOptionBoxTemplateDescriptionMarginWidth; global int $gOptionBoxTemplateFrameSpacing; string $commandName = "replaceObjects"; string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); // STEP 1: Get the option box. // ============================ // string $layout = getOptionBox(); setParent $layout; // STEP 2: Pass the command name to the option box. // ================================================= // setOptionBoxCommandName($commandName); // STEP 3: Activate the default UI template. // ========================================== // setUITemplate -pushTemplate OptionBoxTemplate; // STEP 4: Create option box contents. // =================================== // waitCursor -state 1; // Form layout string $parent = `formLayout replaceObjectsOptions`; // Description frame string $descriptionFrame = `frameLayout -label (uiRes("m_performReplaceObjects.kDescriptionFrame")) -mw $gOptionBoxTemplateDescriptionMarginWidth`; text (uiRes("m_performReplaceObjects.kDescription")); setParent $parent; // Settings frame string $settingsFrame = `frameLayout -label (uiRes("m_performReplaceObjects.kSettingsFrame"))`; columnLayout; checkBoxGrp -numberOfCheckBoxes 1 -label1 (uiRes("m_performReplaceObjects.kReplaceRotate")) -label (uiRes("m_performReplaceObjects.kReplaceAttributes")) replaceObjRotate; checkBoxGrp -numberOfCheckBoxes 1 -label1 (uiRes("m_performReplaceObjects.kReplaceScale")) replaceObjScale; radioButtonGrp -numberOfRadioButtons 3 -label (uiRes("m_performReplaceObjects.kTypeOfCopy")) -label1 (uiRes("m_performReplaceObjects.kReplaceCopy")) -label2 (uiRes("m_performReplaceObjects.kReplaceInstance")) -label3 (uiRes("m_performReplaceObjects.kReplaceReference")) -cw 2 60 -cw 3 93 -cw 4 93 replaceObjCopy; checkBoxGrp -numberOfCheckBoxes 1 -label1 (uiRes("m_performReplaceObjects.kReplaceKeepOriginal")) replaceObjKeepOriginal; setParent ..; setParent ..; // Attach Description/Settings frames to form layout formLayout -e -af $descriptionFrame "top" $gOptionBoxTemplateFrameSpacing -af $descriptionFrame "left" $gOptionBoxTemplateFrameSpacing -af $descriptionFrame "right" $gOptionBoxTemplateFrameSpacing -an $descriptionFrame "bottom" -ac $settingsFrame "top" $gOptionBoxTemplateFrameSpacing $descriptionFrame -af $settingsFrame "left" $gOptionBoxTemplateFrameSpacing -af $settingsFrame "right" $gOptionBoxTemplateFrameSpacing -an $settingsFrame "bottom" $parent; waitCursor -state 0; // Step 5: Deactivate the default UI template. // =========================================== // setUITemplate -popTemplate; // Step 6: Customize the buttons. // ============================== // string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performReplaceObjects.kApply")) -command ($callback + " " + $parent + " " + 1) $applyBtn; string $applyAndCloseBtn = getOptionBoxApplyAndCloseBtn(); button -edit -label (uiRes("m_performReplaceObjects.kReplaceObjects")) $applyAndCloseBtn; string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $parent + " " + 0 + " " +"; hideOptionBox") $saveBtn; string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $parent + " " + 1) $resetBtn; // Step 7: Set the option box title. // ================================= // setOptionBoxTitle((uiRes("m_performReplaceObjects.kReplaceObjectsOptions"))); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag("ReplaceObjects"); // Step 9: Set the current values of the option box. // ================================================= // eval (($setup + " " + $parent + " " + 0)); } proc replaceObjectsOptions () { createCmdOptionsUI(); showOptionBox(); } proc string assembleCmd() { setOptionVars (false); //int $doHistory = `constructionHistory -q -toggle`; string $cmd = "replaceObjects "; $cmd += `optionVar -query "replaceObjRotate"`; $cmd += " "; $cmd += `optionVar -query "replaceObjScale"`; $cmd += " "; $cmd += `optionVar -query "replaceObjCopy"`; $cmd += " "; $cmd += `optionVar -query "replaceObjKeepOriginal"`; return $cmd; } global proc string performReplaceObjects (int $option) { string $cmd=""; switch ($option) { case 0: $cmd = `assembleCmd`; eval($cmd); break; case 1: replaceObjectsOptions; break; case 2: $cmd = `assembleCmd`; break; } return $cmd; }