// =========================================================================== // 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: 20 March 2017 // // Description: // This script defines the option box for the Polygon Gear menu item. // // // Procedure Name: // setOptionVars // // Description: // Initialize the option values. // // Input Arguments: // forceFactorySettings Whether to set the options to default values // // Return Value: // None. // proc setOptionVars(int $forceFactorySettings) { if ($forceFactorySettings || !`optionVar -exists polyGearSides`) { optionVar -intValue polyGearSides 16; } if ($forceFactorySettings || !`optionVar -exists polyGearRadius`) { optionVar -floatValue polyGearRadius 1.0; } if ($forceFactorySettings || !`optionVar -exists polyGearInternalRadius`) { optionVar -floatValue polyGearInternalRadius 0.3; } if ($forceFactorySettings || !`optionVar -exists polyGearHeight`) { optionVar -floatValue polyGearHeight 1.0; } if ($forceFactorySettings || !`optionVar -exists polyGearHeightDivisions`) { optionVar -intValue polyGearHeightDivisions 10; } if ($forceFactorySettings || !`optionVar -exists polyGearGearSpacing`) { optionVar -floatValue polyGearGearSpacing 0.6; } if ($forceFactorySettings || !`optionVar -exists polyGearGearOffset`) { optionVar -floatValue polyGearGearOffset 0.2; } if ($forceFactorySettings || !`optionVar -exists polyGearGearTip`) { optionVar -floatValue polyGearGearTip 0.5; } if ($forceFactorySettings || !`optionVar -exists polyGearGearMiddle`) { optionVar -floatValue polyGearGearMiddle 1.2; } if ($forceFactorySettings || !`optionVar -exists polyGearTwist`) { optionVar -floatValue polyGearTwist 0; } if ($forceFactorySettings || !`optionVar -exists polyGearTaper`) { optionVar -floatValue polyGearTaper 1; } } // // Procedure Name: // polyGearSetup // // 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 polyGearSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls. intSliderGrp -edit -value `optionVar -q polyGearSides` polyGearSides; floatSliderGrp -edit -value `optionVar -q polyGearRadius` polyGearRadius; floatSliderGrp -edit -value `optionVar -q polyGearInternalRadius` polyGearInternalRadius; floatSliderGrp -edit -value `optionVar -q polyGearHeight` polyGearHeight; intSliderGrp -edit -value `optionVar -q polyGearHeightDivisions` polyGearHeightDivisions; floatSliderGrp -edit -value `optionVar -q polyGearGearSpacing` polyGearGearSpacing; floatSliderGrp -edit -value `optionVar -q polyGearGearOffset` polyGearGearOffset; floatSliderGrp -edit -value `optionVar -q polyGearGearTip` polyGearGearTip; floatSliderGrp -edit -value `optionVar -q polyGearGearMiddle` polyGearGearMiddle; floatSliderGrp -edit -value `optionVar -q polyGearTwist` polyGearTwist; floatSliderGrp -edit -value `optionVar -q polyGearTaper` polyGearTaper; } // // Procedure Name: // polyGearCallback // // 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. // // sdoIt - Whether the command should execute. // // Return Value: // None. // global proc polyGearCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then // perform the command. optionVar -intValue polyGearSides `intSliderGrp -q -value polyGearSides`; optionVar -floatValue polyGearRadius `floatSliderGrp -q -value polyGearRadius`; optionVar -floatValue polyGearInternalRadius `floatSliderGrp -q -value polyGearInternalRadius`; optionVar -floatValue polyGearHeight `floatSliderGrp -q -value polyGearHeight`; optionVar -intValue polyGearHeightDivisions `intSliderGrp -q -value polyGearHeightDivisions`; optionVar -floatValue polyGearGearSpacing `floatSliderGrp -q -value polyGearGearSpacing`; optionVar -floatValue polyGearGearOffset `floatSliderGrp -q -value polyGearGearOffset`; optionVar -floatValue polyGearGearTip `floatSliderGrp -q -value polyGearGearTip`; optionVar -floatValue polyGearGearMiddle `floatSliderGrp -q -value polyGearGearMiddle`; optionVar -floatValue polyGearTwist `floatSliderGrp -q -value polyGearTwist`; optionVar -floatValue polyGearTaper `floatSliderGrp -q -value polyGearTaper`; if ($doIt) { performPolyGear 0; addToRecentCommandQueue "performPolyGear 0" "Polygon Gear"; } } // // Procedure Name: // polyGearOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc polyGearOptions() { // Name of the command for this option box. // string $commandName = "polyGear"; // Build the option box actions. // string $callback = "polyGearCallback"; string $setup = "polyGearSetup"; // 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. // ================================================= // // Any default option box behaviour based on the command name is set // up with this call. For example, updating the 'Help' menu item with // the name of the command. // setOptionBoxCommandName($commandName); // 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; // Turn on the wait cursor. // waitCursor -state 1; // STEP 4: Create option box contents. // =================================== // string $parent = `columnLayout -adjustableColumn 1`; intSliderGrp -label (getPluginResource("modelingToolkit", "kGearSides")) -min 3 -max 20 -fieldMinValue 3 polyGearSides; floatSliderGrp -label (getPluginResource("modelingToolkit", "kGearRadius")) -min 0.001 -max 100 -fieldMinValue 0.001 polyGearRadius; floatSliderGrp -label (getPluginResource("modelingToolkit", "kGearInternalRadius")) -min 0.0 -max 50.0 -fieldMinValue 0.0 polyGearInternalRadius; floatSliderGrp -label (getPluginResource("modelingToolkit", "kGearHeight")) -min 0.001 -max 100 -fieldMinValue 0.001 polyGearHeight; intSliderGrp -label (getPluginResource("modelingToolkit", "kGearHeightDivisions")) -min 1 -max 40 -fieldMinValue 1 polyGearHeightDivisions; floatSliderGrp -label (getPluginResource("modelingToolkit", "kGearGearSpacing")) -min 0 -max 1 -fieldMinValue 0 polyGearGearSpacing; floatSliderGrp -label (getPluginResource("modelingToolkit", "kGearGearOffset")) -min 0 -max 20 -fieldMinValue 0 polyGearGearOffset; floatSliderGrp -label (getPluginResource("modelingToolkit", "kGearGearTip")) -min 0 -max 1 -fieldMinValue 0 polyGearGearTip; floatSliderGrp -label (getPluginResource("modelingToolkit", "kGearGearMiddle")) -min 0 -max 2 -fieldMinValue 0 polyGearGearMiddle; floatSliderGrp -label (getPluginResource("modelingToolkit", "kGearTwist")) -min 0 -max 1 -fieldMinValue 0 polyGearTwist; floatSliderGrp -label (getPluginResource("modelingToolkit", "kGearTaper")) -min 0.001 -max 1 -fieldMinValue 0.001 polyGearTaper; // 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. // Disable those buttons that are not applicable to the option box. // Attach actions to those buttons that are applicable to the option box. // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (getPluginResource("modelingToolkit", "kCreateButton")) -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 (getPluginResource("modelingToolkit", "kPolygonGearOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag("PolygonGear"); // Set the current values of the option box. // ========================================= // eval (($setup + " " + $parent + " " + 0)); // 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; setOptionVars(false); $cmd = "polyGear" + " -sides " + string(`optionVar -q polyGearSides`) + " -radius " + string(`optionVar -q polyGearRadius`) + " -internalRadius " + string(`optionVar -q polyGearInternalRadius`) + " -height " + string(`optionVar -q polyGearHeight`) + " -heightDivisions " + string(`optionVar -q polyGearHeightDivisions`) + " -gearSpacing " + string(`optionVar -q polyGearGearSpacing`) + " -gearOffset " + string(`optionVar -q polyGearGearOffset`) + " -gearTip " + string(`optionVar -q polyGearGearTip`) + " -gearMiddle " + string(`optionVar -q polyGearGearMiddle`) + " -twist " + string(`optionVar -q polyGearTwist`) + " -taper " + string(`optionVar -q polyGearTaper`) + ";"; return $cmd; } // // Procedure Name: // performPolyGear // // Description: // Perform the polyGear 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 sphere 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 performPolyGear(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: polyGearOptions(); break; // Return the command string. // case 2: // Get the command. // $cmd = assembleCmd(); break; } return $cmd; }