// =========================================================================== // 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 disc 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 polyDiscSides`) { optionVar -intValue polyDiscSides 3; } if ($forceFactorySettings || !`optionVar -exists polyDiscSubdivisionMode`) { optionVar -intValue polyDiscSubdivisionMode 4; } if ($forceFactorySettings || !`optionVar -exists polyDiscSubdivisions`) { optionVar -intValue polyDiscSubdivisions 3; } if ($forceFactorySettings || !`optionVar -exists polyDiscRadius`) { optionVar -floatValue polyDiscRadius 1.0; } } // // Procedure Name: // polyDiscSetup // // 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 polyDiscSetup(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 polyDiscSides` polyDiscSides; optionMenuGrp -edit -select (`optionVar -q polyDiscSubdivisionMode` + 1) polyDiscSubdivisionMode; intSliderGrp -edit -value `optionVar -q polyDiscSubdivisions` polyDiscSubdivisions; floatSliderGrp -edit -value `optionVar -q polyDiscRadius` polyDiscRadius; } // // Procedure Name: // polyDiscCallback // // 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 polyDiscCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then // perform the command. optionVar -intValue polyDiscSides `intSliderGrp -q -value polyDiscSides`; optionVar -intValue polyDiscSubdivisionMode (`optionMenuGrp -q -select polyDiscSubdivisionMode` - 1); optionVar -intValue polyDiscSubdivisions `intSliderGrp -q -value polyDiscSubdivisions`; optionVar -floatValue polyDiscRadius `floatSliderGrp -q -value polyDiscRadius`; if ($doIt) { performPolyDisc 0; addToRecentCommandQueue "performPolyDisc 0" "Polygon Disc"; } } // // Procedure Name: // polyDiscOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc polyDiscOptions() { // Name of the command for this option box. // string $commandName = "polyDisc"; // Build the option box actions. // string $callback = "polyDiscCallback"; string $setup = "polyDiscSetup"; // 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", "kDiscSides")) -min 3 -max 20 -fieldMinValue 3 polyDiscSides; optionMenuGrp -label (getPluginResource("modelingToolkit", "kDiscSubdivisionMode")) polyDiscSubdivisionMode; menuItem -label (getPluginResource("modelingToolkit", "kDiscSubdivisionModeQuads")); menuItem -label (getPluginResource("modelingToolkit", "kDiscSubdivisionModeTriangles")); menuItem -label (getPluginResource("modelingToolkit", "kDiscSubdivisionModePie")); menuItem -label (getPluginResource("modelingToolkit", "kDiscSubdivisionModeCaps")); menuItem -label (getPluginResource("modelingToolkit", "kDiscSubdivisionModeCircle")); setParent -menu ..; optionMenuGrp -edit -select 5 polyDiscSubdivisionMode; intSliderGrp -label (getPluginResource("modelingToolkit", "kDiscSubdivisions")) -min 1 -max 40 -fieldMinValue 1 polyDiscSubdivisions; floatSliderGrp -label (getPluginResource("modelingToolkit", "kDiscRadius")) -min 0.001 -max 100 -fieldMinValue 0.001 polyDiscRadius; // 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", "kPolygonDiscOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag("PolygonDisc"); // 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 = "polyDisc" + " -sides " + string(`optionVar -q polyDiscSides`) + " -subdivisionMode " + string(`optionVar -q polyDiscSubdivisionMode`) + " -subdivisions " + string(`optionVar -q polyDiscSubdivisions`) + " -radius " + string(`optionVar -q polyDiscRadius`) + ";"; return $cmd; } // // Procedure Name: // performPolyDisc // // Description: // Perform the polyDisc 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 performPolyDisc(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: polyDiscOptions(); break; // Return the command string. // case 2: // Get the command. // $cmd = assembleCmd(); break; } return $cmd; }