// =========================================================================== // 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: // setOptionVars // // Description: // Initialize the option values. // // Input Arguments: // Whether to set the options to default values. // // Return Value: // None. // proc setOptionVars(int $forceFactorySettings) { // ********* There should be one optionVar variable per option // ********* setting in your option box. In this proc, // ********* for each of your optionVars, replace the following // ********* optionBoxExample1XXX with the name of your optionVar. // ********* Note: optionVars should, by convention, be prefixed by // ********* the name of your command to avoid name clashes in optionVars. // Envelope. // if ($forceFactorySettings || !`optionVar -exists dropoffLocatorEnvelope`) { optionVar -floatValue dropoffLocatorEnvelope 1; } // Percent. if ($forceFactorySettings || !`optionVar -exists dropoffLocatorPercent`) { optionVar -floatValue dropoffLocatorPercent 1; } } // // Procedure Name: // dropoffLocatorSetup // // 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. // // ********* Change 'dropoffLocator' in this proc to be the name of your command global proc dropoffLocatorSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls. // Wire // //textFieldGrp -edit //-text `optionVar -query dropoffLocatorWire` //dropoffLocatorWire; // Envelope // floatSliderGrp -edit -v `optionVar -query dropoffLocatorEnvelope` dropoffLocatorEnvelope; // Percent // floatSliderGrp -edit -v `optionVar -query dropoffLocatorPercent` dropoffLocatorPercent; textFieldGrp -e -tx "" dropoffLocatorWire; } // // Procedure Name: // dropoffLocatorCallback // // 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. // // ********* Change 'dropoffLocator' in this proc to be the name of your command global proc dropoffLocatorCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then // perform the command. // Envelope // optionVar -floatValue dropoffLocatorEnvelope `floatSliderGrp -query -v dropoffLocatorEnvelope`; // Percent // optionVar -floatValue dropoffLocatorPercent `floatSliderGrp -query -v dropoffLocatorPercent`; if ($doIt) { performDropoffLocator 0; addToRecentCommandQueue "performDropoffLocator 0" "DropoffLocator"; } } // // Procedure Name: // dropoffLocatorOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // // ********* Change 'dropoffLocator' in this proc to be the name of your command proc dropoffLocatorOptions() { // Name of the command for this option box. // string $commandName = "dropoffLocator"; // 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: 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 3: Create option box contents. // =================================== // // This, of course, will vary from option box to option box. // Turn on the wait cursor. // waitCursor -state 1; // RECOMMENDATION: Place the UI in a scroll layout. If the // option box window is ever resized such that it's entire // contents is not visible then the scroll bars provided by the // scroll layout will allow the user to access the hidden UI. // tabLayout -scr true -tv false; string $parent = `columnLayout -adjustableColumn 1`; // RECOMMENDATION: Use the 'Grp' commands where possible because // they obey the formatting specified in the default template. // This will result in a more consistent look throughout the // application. // textFieldGrp -label (uiRes("m_performDropoffLocator.kWireNode")) -tx "" dropoffLocatorWire; // Create an option menu listing existing wires // optionMenuGrp -label (uiRes("m_performDropoffLocator.kExistingWireNodes")) -cc "textFieldGrp -e -tx `optionMenuGrp -q -v dropoffLocatorList` dropoffLocatorWire" dropoffLocatorList; // add all the wires to the menu // int $pp; string $wireArray[]; $wireArray = `ls -type wire`; int $wireCount = size($wireArray); if ($wireCount > 0) { for ($pp = 0; $pp < $wireCount; $pp++) { menuItem -label $wireArray[$pp]; } } else { menuItem -label (uiRes("m_performDropoffLocator.kNoWiresSelected")) ; } separator; floatSliderGrp -label (uiRes("m_performDropoffLocator.kEnvelope")) -min 0 -max 2 -v 1 dropoffLocatorEnvelope; floatSliderGrp -label (uiRes("m_performDropoffLocator.kPercent")) -min 0 -max 2 -v 1 dropoffLocatorPercent; // Turn off the wait cursor. // waitCursor -state 0; // Step 4: Deactivate the default UI template. // =========================================== // setUITemplate -popTemplate; // Step 5: 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 -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 6: Set the option box title. // ================================= // setOptionBoxTitle (uiRes("m_performDropoffLocator.kWireDropoffLocatorOptions")); // Step 7: Set the 'Help' menu item text. // ====================================== // // Get the help menu item and set its label to reflect the option box // command. Also, attach an action to invoke help for the command. // setOptionBoxCommandName($commandName); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "WireDropoffLocator" ); // Step 9: Set the current values of the option box. // ================================================= // eval (($setup + " " + $parent + " " + 0)); // Step 10: Show the option box. // ================================= // showOptionBox(); } // // Procedure Name: // dropoffLocatorHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // // ********* Change 'dropoffLocator' in this proc to be the name of your command proc string dropoffLocatorHelp() { return "Select a param point on a wire curve\n"; } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // // Return Value: // None. // proc string assembleCmd() { string $cmd = "createDropoffLocator "; setOptionVars(false); float $env = `optionVar -query dropoffLocatorEnvelope`; float $perc = `optionVar -query dropoffLocatorPercent`; string $wire=""; if (`textFieldGrp -exists dropoffLocatorWire`) $wire=`textFieldGrp -query -tx dropoffLocatorWire`; $cmd += ( $env + " " + $perc); if ($wire=="") { $cmd+= " \"\""; } else { $cmd+= (" " + $wire); } return $cmd; } // // Procedure Name: // performDropoffLocator // // Description: // Perform the dropoffLocator 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 dropoffLocator 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. // // ********* Change 'dropoffLocator' in this proc to be the name of your command global proc string performDropoffLocator(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. // // NOTE: This following evaluation will fail because // this entire file exists only to serve as an example // for using option boxes. There is no command called // 'dropoffLocator'. // eval($cmd); break; // Show the option box. // case 1: dropoffLocatorOptions; break; // Return the command string. // case 2: // Retrieve the option settings. // setOptionVars (false); // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }