// =========================================================================== // 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 platonic 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 polyPlatonicPrimitive`) { optionVar -intValue polyPlatonicPrimitive 4; } if ($forceFactorySettings || !`optionVar -exists polyPlatonicSubdivisionMode`) { optionVar -intValue polyPlatonicSubdivisionMode 0; } if ($forceFactorySettings || !`optionVar -exists polyPlatonicSubdivisions`) { optionVar -intValue polyPlatonicSubdivisions 0; } if ($forceFactorySettings || !`optionVar -exists polyPlatonicRadius`) { optionVar -floatValue polyPlatonicRadius 1.0; } if ($forceFactorySettings || !`optionVar -exists polyPlatonicSphericalInflation`) { optionVar -floatValue polyPlatonicSphericalInflation 1; } } // // Procedure Name: // polyPlatonicSetup // // 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 polyPlatonicSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls. optionMenuGrp -edit -select (`optionVar -q polyPlatonicPrimitive` + 1) polyPlatonicPrimitive; optionMenuGrp -edit -select (`optionVar -q polyPlatonicSubdivisionMode` + 1) polyPlatonicSubdivisionMode; intSliderGrp -edit -value `optionVar -q polyPlatonicSubdivisions` polyPlatonicSubdivisions; floatSliderGrp -edit -value `optionVar -q polyPlatonicRadius` polyPlatonicRadius; floatSliderGrp -edit -value `optionVar -q polyPlatonicSphericalInflation` polyPlatonicSphericalInflation; } // // Procedure Name: // polyPlatonicCallback // // 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 polyPlatonicCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then // perform the command. optionVar -intValue polyPlatonicPrimitive (`optionMenuGrp -q -select polyPlatonicPrimitive` - 1); optionVar -intValue polyPlatonicSubdivisionMode (`optionMenuGrp -q -select polyPlatonicSubdivisionMode` - 1); optionVar -intValue polyPlatonicSubdivisions `intSliderGrp -q -value polyPlatonicSubdivisions`; optionVar -floatValue polyPlatonicRadius `floatSliderGrp -q -value polyPlatonicRadius`; optionVar -floatValue polyPlatonicSphericalInflation `floatSliderGrp -q -value polyPlatonicSphericalInflation`; if ($doIt) { performPolyPlatonic 0; addToRecentCommandQueue "performPolyPlatonic 0" "Polygon Platonic"; } } // // Procedure Name: // polyPlatonicOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc polyPlatonicOptions() { // Name of the command for this option box. // string $commandName = "polyPlatonic"; // Build the option box actions. // string $callback = "polyPlatonicCallback"; string $setup = "polyPlatonicSetup"; // 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`; optionMenuGrp -label (getPluginResource("modelingToolkit", "kPlatonicPrimitive")) polyPlatonicPrimitive; menuItem -label (getPluginResource("modelingToolkit", "kPlatonicPrimitiveTetrahedron")); menuItem -label (getPluginResource("modelingToolkit", "kPlatonicPrimitiveCube")); menuItem -label (getPluginResource("modelingToolkit", "kPlatonicPrimitiveOctahedron")); menuItem -label (getPluginResource("modelingToolkit", "kPlatonicPrimitiveDodecahedron")); menuItem -label (getPluginResource("modelingToolkit", "kPlatonicPrimitiveIcosahedron")); setParent -menu ..; optionMenuGrp -edit -select 5 polyPlatonicPrimitive; optionMenuGrp -label (getPluginResource("modelingToolkit", "kPlatonicSubdivisionMode")) polyPlatonicSubdivisionMode; menuItem -label (getPluginResource("modelingToolkit", "kPlatonicSubdivisionModeQuads")); menuItem -label (getPluginResource("modelingToolkit", "kPlatonicSubdivisionModeTriangles")); menuItem -label (getPluginResource("modelingToolkit", "kPlatonicSubdivisionModePie")); menuItem -label (getPluginResource("modelingToolkit", "kPlatonicSubdivisionModeCaps")); setParent -menu ..; optionMenuGrp -edit -select 1 polyPlatonicSubdivisionMode; intSliderGrp -label (getPluginResource("modelingToolkit", "kPlatonicSubdivisions")) -min 1 -max 40 -fieldMinValue 1 polyPlatonicSubdivisions; floatSliderGrp -label (getPluginResource("modelingToolkit", "kPlatonicRadius")) -min 0.001 -max 100 -fieldMinValue 0.001 polyPlatonicRadius; floatSliderGrp -label (getPluginResource("modelingToolkit", "kPlatonicSphericalInflation")) -min 0 -max 1 -fieldMinValue 0 polyPlatonicSphericalInflation; // 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", "kPolygonPlatonicOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag("PolygonPlatonic"); // 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 = "polyPlatonic" + " -primitive " + string(`optionVar -q polyPlatonicPrimitive`) + " -subdivisionMode " + string(`optionVar -q polyPlatonicSubdivisionMode`) + " -subdivisions " + string(`optionVar -q polyPlatonicSubdivisions`) + " -radius " + string(`optionVar -q polyPlatonicRadius`) + " -sphericalInflation " + string(`optionVar -q polyPlatonicSphericalInflation`) + ";"; return $cmd; } // // Procedure Name: // performPolyPlatonic // // Description: // Perform the polyPlatonic 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 performPolyPlatonic(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: polyPlatonicOptions(); break; // Return the command string. // case 2: // Get the command. // $cmd = assembleCmd(); break; } return $cmd; }