// =========================================================================== // 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: November 25, 1996 // // Description: // Ununparent option box script. // // Input Arguments: // bool if true show option box // if false perform command with current values // Return Value: // None. // proc setOptionVars (int $forceFactorySettings) { // Remove flag // if ($forceFactorySettings || !`optionVar -exists unparentRemove`) { optionVar -intValue unparentRemove false; } // Absolute flag // if ($forceFactorySettings || !`optionVar -exists unparentPreserve`) { optionVar -intValue unparentPreserve true; } } global proc unparentSetup (string $parent, int $forceFactorySettings) { int $boolToOption[] = { 1, 2 }; // Retrieve the option settings // setOptionVars ($forceFactorySettings); setParent $parent; // Remove flag // int $rem = `optionVar -q unparentRemove`; radioButtonGrp -e -select $boolToOption[$rem] unparentMethod; // Absolute flag // int $preserve = `optionVar -q unparentPreserve`; checkBoxGrp -e -en1 (!$rem) -v1 $preserve unparentCheck; } global proc unparentCallback (string $parent, int $doIt) { int $optionToBool[] = { 0, false, true }; setParent $parent; // Set the optionVar's from the control values, and then perform command // // Remove flag // int $i = `radioButtonGrp -q -select unparentMethod`; optionVar -intValue unparentRemove $optionToBool[$i]; // Preserve flag // optionVar -intValue unparentPreserve `checkBoxGrp -q -v1 unparentCheck`; if ($doIt) { performUnparent 0; addToRecentCommandQueue "performUnparent 0" "UnParent"; } } // // Procedure Name: // unparentOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc unparentOptions() { // Name of the command for this option box. // string $commandName = "unparent"; // Build the option box actions. // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); // STEP 1: Get the option box. // ============================ // // The value returned is the name of the layout to be used as // the parent for the option box UI. // string $layout = getOptionBox(); setParent $layout; // STEP 2: Pass the command name to the option box - see STEP 8. // ============================================================== // STEP 3: Activate the default UI template. // ========================================== // // Activate the default UI template so that the layout of this // option box is consistent with the layout of the rest of the // application. // setUITemplate -pushTemplate DefaultTemplate; // STEP 4: Create option box contents. // =================================== // // This, of course, will vary from option box to option box. // Turn on the wait cursor. // waitCursor -state 1; // tabLayout -tabsVisible 0 -scrollable 1; string $parent = `columnLayout -adjustableColumn 1`; string $onCmd = "checkBoxGrp -e -en1 true unparentCheck"; string $offCmd = "checkBoxGrp -e -en1 false unparentCheck"; radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_performUnparent.kUnparentMethod")) -label1 (uiRes("m_performUnparent.kParenttoWorld")) -label2 (uiRes("m_performUnparent.kRemoveInstance")) -on2 $offCmd -of2 $onCmd unparentMethod; checkBoxGrp -numberOfCheckBoxes 1 -label1 (uiRes("m_performUnparent.kPreservePosition")) unparentCheck; // Turn off the wait cursor. // waitCursor -state 0; // Step 5: Deactivate the default UI template. // =========================================== // setUITemplate -popTemplate; // Step 6: Customize the buttons. // ============================== // // Provide more descriptive labels for the buttons. This is not // necessary, but in some cases, for example, a button labelled // 'Create' may be more meaningful to the user than one labelled // 'Apply'. // // Disable those buttons that are not applicable to the option box. // // Attach actions to those buttons that are applicable to the option // box. Note that the 'Close' button has a default action attached // to it that will hide the window. If a a custom action is // attached to the 'Close' button then be sure to call the 'hide the // option box' procedure within the custom action so that the option // box is hidden properly. // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performUnparent.kUnparent")) -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; // Step 7: Set the option box title. // ================================= // setOptionBoxTitle (uiRes("m_performUnparent.kUnparentOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "Unparent" ); // Step 9: Set the current values of the option box. // ================================================= // eval (($setup + " " + $parent + " " + 0)); // Step 10: Show the option box. // ============================= // showOptionBox(); } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // proc string assembleCmd() { string $cmd = "unparent"; setOptionVars(false); $cmd = "parent"; int $rm = `optionVar -q unparentRemove`; int $preserve = `optionVar -q unparentPreserve`; if ($rm) $cmd += " -rm"; else $cmd += " -w"; if (!$preserve) $cmd += " -r"; return $cmd; } // // Procedure Name: // performOptionBoxExample1 // // Description: // Perform the unparent 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 optionBoxExample1 command with the current // option box values. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // global proc string performUnparent(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: // Get the command. // $cmd = `assembleCmd`; // Execute the command with the option settings. // evalEcho($cmd); break; // Show the option box. // case 1: unparentOptions; break; // Return the command string. // case 2: // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }