// =========================================================================== // 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: 28 April 1997 // // Description: // Initialize the option values for offset surface menu item. // // Input Arguments: // int action // 0 - just execute the offset surface operation // 1 - show the option box dialog // 2 - drag to shelf // // Return Value: // None. // proc setOptionVars(int $forceFactorySettings) { // Offset method. // if ($forceFactorySettings || !`optionVar -exists offsetSurfaceMethod`) { optionVar -intValue offsetSurfaceMethod 0; } // Offset distance. // if ($forceFactorySettings || !`optionVar -exists offsetSurfaceDistance`) { optionVar -floatValue offsetSurfaceDistance 1.0; } } // // Procedure Name: // offsetSurfaceSetup // // Description: // Update the state of the option box UI to reflect the offsetSurface // 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 offsetSurfaceSetup( string $parent, int $forceFactorySettings, string $goToTool ) { // Retrieve the option settings // setOptionVars($forceFactorySettings); offsetSurfaceToolSetup( $forceFactorySettings, $goToTool ); setParent $parent; // Query the optionVar's and set the values into the controls. // method int $method = `optionVar -q offsetSurfaceMethod`+1 ; radioButtonGrp -edit -select $method offsetSurfaceMethodRadioButtonGrp ; // Distance floatSliderGrp -edit -value `optionVar -q offsetSurfaceDistance` offsetSurfaceDistanceFloatSliderGrp; if( "" != $goToTool ) { checkBoxGrp -e -v1 `scriptCtx -q -euc $goToTool` scriptToolExtraWidget; checkBoxGrp -e -v2 `scriptCtx -q -lac $goToTool` scriptToolExtraWidget; } } // // Procedure Name: // offsetSurfaceCallback // // 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. // global proc offsetSurfaceCallback( string $parent, int $doIt, string $goToTool ) { if( "" != $goToTool ) { optionVar -iv offsetSurfaceEuc `scriptCtx -q -euc $goToTool`; optionVar -iv offsetSurfaceLac `scriptCtx -q -lac $goToTool`; } setParent $parent; // Set the optionVar's from the control values, and then // perform the command. // method int $dir = `radioButtonGrp -q -select offsetSurfaceMethodRadioButtonGrp` - 1 ; optionVar -intValue offsetSurfaceMethod $dir ; // distance optionVar -floatValue offsetSurfaceDistance `floatSliderGrp -q -value offsetSurfaceDistanceFloatSliderGrp`; if( 1 == $doIt ) { performOffsetSurface( 0, $goToTool ); string $tmpCmd = "performOffsetSurface(0, \"" + $goToTool + "\")"; addToRecentCommandQueue $tmpCmd "Offset Surface"; } else if( $doIt ) { setToolTo $goToTool; } } // // Procedure Name: // createOffsetSurfaceUI // // Description: // Fill the contents of the option box for offsetSurface command. // // Input Arguments: // The name of the parent layout. // // Return Value: // None. // proc createOffsetSurfaceUI(string $parent, int $inTheTool, string $goToTool) { setParent $parent; string $surfaceFit = (uiRes("m_performOffsetSurface.kCSurfaceFit")); radioButtonGrp -nrb 2 -select 1 -label (uiRes("m_performOffsetSurface.kMethod")) -label1 $surfaceFit -label2 (uiRes("m_performOffsetSurface.kCVFit")) offsetSurfaceMethodRadioButtonGrp; floatSliderGrp -field on -fmn -10000. -fmx 10000. -ss 1.0 -min -10. -max 10. -label (uiRes("m_performOffsetSurface.kOffsetDistance")) offsetSurfaceDistanceFloatSliderGrp; if( $inTheTool ) { separator; checkBoxGrp -ncb 2 -label (uiRes("m_performOffsetSurface.kToolBehavior")) -label1 (uiRes("m_performOffsetSurface.kExit")) -v1 off -on1 ("scriptCtx -e -euc true " + $goToTool) -of1 ("scriptCtx -e -euc false " + $goToTool) -label2 (uiRes("m_performOffsetSurface.kAuto")) -v2 on -on2 ("scriptCtx -e -lac true " + $goToTool) -of2 ("scriptCtx -e -lac false " + $goToTool) scriptToolExtraWidget; } } // // Procedure Name: // offsetSurfaceOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc offsetSurfaceOptions( int $inTheTool, string $goToTool ) { // Name of the command for this option box. // string $commandName = "offsetSurface"; string $optionBoxTitle; if( $inTheTool ) { $optionBoxTitle = (uiRes("m_performOffsetSurface.kSurfaceToolTitle")); } else { $optionBoxTitle = (uiRes("m_performOffsetSurface.kSurfaceTitle")); } // Build the option box actions. // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); global string $gOptionBoxActionToolItem; $gOptionBoxActionToolItem = "modelWithToolOffsetSurface"; global string $gOptionBoxActionToolItemCB; $gOptionBoxActionToolItemCB = "offsetSurfaceToolScript 3"; // 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; // Pass the command name to the option box. // // Any default option box behavior based on the command name is set // up with this call. // setOptionBoxCommandName($commandName); // 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; // 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`; // Create the UI for the tab that is initially visible. // createOffsetSurfaceUI($parent, $inTheTool, $goToTool); // Turn off the wait cursor. // waitCursor -state 0; // Deactivate the default UI template. // setUITemplate -popTemplate; // 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. // 'OffsetSurface' button. // string $applyBtn = getOptionBoxApplyBtn(); if( $inTheTool ) { button -edit -label (uiRes("m_performOffsetSurface.kOffsetTool")) -command ($callback + " " + $parent + " 3 \"" + $goToTool + "\"") $applyBtn; } else { button -edit -label (uiRes("m_performOffsetSurface.kOffset")) -command ($callback + " " + $parent + " 1 \"" + $goToTool + "\"") $applyBtn; } // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $parent + " 0 \"" + $goToTool + "\"; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $parent + " 1 \"" + $goToTool + "\"") $resetBtn; // Set the option box title. // setOptionBoxTitle($optionBoxTitle); // Customize the 'Help' menu item text. // setOptionBoxHelpTag( "OffsetSurfaces" ); // Set the current values of the option box. // eval ($setup + " " + $parent + " 0 \"" + $goToTool + "\""); // Show the option box. // showOptionBox(); } // // Procedure Name: // offsetSurfaceHelp // // Description: // Returns a short description about the offsetSurface command. // // Input Arguments: // None. // // Return Value: // string. // proc string offsetSurfaceHelp() { return " Command: OffsetSurface - create a offset surface from a given surface.\n" + "Select at least one surface to offset."; } // // Procedure Name: // assembleCmd // // Description: // Construct the offsetSurface command that will apply the option box // values. // // Input Arguments: // None. // // Return Value: // The offsetSurface command string. // proc string assembleCmd() { setOptionVars(false); string $cmd = "offsetSurfacePreset"; $cmd = $cmd + "(" ; // get the global history flag value int $doHistory = `constructionHistory -q -tgl`; $cmd = $cmd + $doHistory + ","; int $method = `optionVar -q offsetSurfaceMethod`; $cmd = $cmd + $method + ","; float $distance = `optionVar -q offsetSurfaceDistance`; $cmd = $cmd + $distance; $cmd = $cmd + ")"; return $cmd; } // // Procedure Name: // performOffsetSurface // // Description: // Perform the offsetSurface 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 offsetSurface command with the current // option box values. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command to drag to shelf. // // Return Value: // The offsetSurface command string. // global proc string performOffsetSurface(int $action, string $goToTool) { int $inTheTool = false; if( 3 == $action ) { $action = 1; $inTheTool = true; } string $cmd = ""; switch ($action) { case 0: setOptionVars(false); $cmd = `assembleCmd`; eval($cmd); break; case 1: offsetSurfaceOptions( $inTheTool, $goToTool ); break; case 2: default: setOptionVars(false); $cmd = `assembleCmd`; break; } return $cmd; }