// =========================================================================== // 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 curve menu item. // // Input Arguments: // int action // 0 - just execute the offset curve operation // 1 - show the option box dialog // 2 - drag to shelf // // Return Value: // None. // proc setOptionVars(int $forceFactorySettings) { // Connect breaks (0=off 1=circular 2=linear). // if ($forceFactorySettings || !`optionVar -exists offsetCurveConnectBreaks`){ optionVar -intValue offsetCurveConnectBreaks 2; } // Stitch (on-1 or off-0). // if ($forceFactorySettings || !`optionVar -exists offsetCurveStitch`) { optionVar -intValue offsetCurveStitch 1; } // Global or local tolerance: if( $forceFactorySettings || !`optionVar -exists offsetCurveUseGlobalTol` ){ optionVar -intValue offsetCurveUseGlobalTol false; } // Cut loops (on-1 or off-0). // if ($forceFactorySettings || !`optionVar -exists offsetCurveLoopCutting`) { optionVar -intValue offsetCurveLoopCutting 1; } // Radius (used if cut loops is on). // if ($forceFactorySettings || !`optionVar -exists offsetCurveCutRadius`) { optionVar -floatValue offsetCurveCutRadius 0.0; } // Offset distance. // if ($forceFactorySettings || !`optionVar -exists offsetCurveDistance`) { optionVar -floatValue offsetCurveDistance 1.0; } // Tolerance control (on-1 or off-0 used for depth and bias). // if ($forceFactorySettings || !`optionVar -exists offsetCurveTolerance`) { optionVar -floatValue offsetCurveTolerance 0.01; } // Subdivision density // if ($forceFactorySettings || !`optionVar -exists offsetCurveSubdivDensity`){ optionVar -intValue offsetCurveSubdivDensity 5; } // Normal direction (plane or geometry average??). // if ($forceFactorySettings || !`optionVar -exists offsetCurveNormalDirection`) { optionVar -intValue offsetCurveNormalDirection 1; } // curve range if ($forceFactorySettings || !`optionVar -exists offsetCurveRangePartial`){ optionVar -intValue offsetCurveRangePartial 0; } } // // Procedure Name: // offsetCurveSetup // // Description: // Update the state of the option box UI to reflect the offsetCurve // 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 offsetCurveSetup( string $parent, int $forceFactorySettings, string $goToTool ) { // Retrieve the option settings // setOptionVars($forceFactorySettings); offsetCurveToolSetup( $forceFactorySettings, $goToTool ); setParent $parent; // Query the optionVar's and set the values into the controls. // normal direction int $dir = `optionVar -q offsetCurveNormalDirection`+1 ; radioButtonGrp -edit -select $dir offsetCurveNormalRadioButtonGrp ; // Distance // floatSliderGrp -edit -value `optionVar -q offsetCurveDistance` offsetCurveDistanceFloatSliderGrp; // Connect breaks. // int $doConnectBreaks = `optionVar -q offsetCurveConnectBreaks`; if( 0 == $doConnectBreaks ) $doConnectBreaks = 3; radioButtonGrp -edit -select $doConnectBreaks offsetCurveConnectBreaksRadioButtonGrp; // Global vs. local tolerance int $useGlobalTol = `optionVar -q offsetCurveUseGlobalTol`; radioButtonGrp -e -select (2 - $useGlobalTol) useGlobalTol; // Loop cutting. // int $doLoopCutting = `optionVar -q offsetCurveLoopCutting`; radioButtonGrp -edit -select (2 - $doLoopCutting) offsetCurveLoopCuttingRadioButtonGrp; // Cut radius // floatSliderGrp -edit -value `optionVar -q offsetCurveCutRadius` -enable $doLoopCutting offsetCurveCutRadiusFloatSliderGrp; // Subdivision density // intSliderGrp -edit -value `optionVar -q offsetCurveSubdivDensity` offsetCurveSubdivDensityIntSliderGrp; // Tolerance // floatSliderGrp -edit -v `optionVar -q offsetCurveTolerance` offsetCurveTolerance; // curve range on inputs. // int $offsetCurveRangePartial = `optionVar -q offsetCurveRangePartial`+1 ; radioButtonGrp -edit -select $offsetCurveRangePartial offsetCurveRangeRadioButtonGrp ; // loop cut tab on/off if( $doLoopCutting ) { tabLayout -e -selectTab offsetCurveLoopCut_C offsetCurveLoopCutOptions_Tabs; } else { tabLayout -e -selectTab offsetCurveNoLoopCut_C offsetCurveLoopCutOptions_Tabs; } if( $useGlobalTol ) { tabLayout -e -selectTab noSlider useGlobalTolTab; } else { tabLayout -e -selectTab slider useGlobalTolTab; } if( "" != $goToTool ) { checkBoxGrp -e -v1 `scriptCtx -q -euc $goToTool` scriptToolExtraWidget; checkBoxGrp -e -v2 `scriptCtx -q -lac $goToTool` scriptToolExtraWidget; } } // // Procedure Name: // offsetCurveCallback // // 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 offsetCurveCallback(string $parent, int $doIt, string $goToTool) { if( "" != $goToTool ) { optionVar -iv offsetCurveEuc `scriptCtx -q -euc $goToTool`; optionVar -iv offsetCurveLac `scriptCtx -q -lac $goToTool`; } setParent $parent; // Set the optionVar's from the control values, and then // perform the command. // normal direction. int $dir = `radioButtonGrp -q -select offsetCurveNormalRadioButtonGrp` - 1 ; optionVar -intValue offsetCurveNormalDirection $dir ; // distance optionVar -floatValue offsetCurveDistance `floatSliderGrp -q -value offsetCurveDistanceFloatSliderGrp`; // connect breaks, setting correct option value int $breaks = `radioButtonGrp -q -select offsetCurveConnectBreaksRadioButtonGrp`; if( 3 == $breaks ) $breaks = 0; optionVar -intValue offsetCurveConnectBreaks $breaks; // global vs. local: int $useGlobalTol = 2 - `radioButtonGrp -q -select useGlobalTol`; optionVar -intValue offsetCurveUseGlobalTol $useGlobalTol; // loop cutting, setting correct option value int $lc = 2 - `radioButtonGrp -q -select offsetCurveLoopCuttingRadioButtonGrp`; optionVar -intValue offsetCurveLoopCutting $lc; // cut radius optionVar -floatValue offsetCurveCutRadius `floatSliderGrp -q -value offsetCurveCutRadiusFloatSliderGrp`; // subdivision density optionVar -intValue offsetCurveSubdivDensity `intSliderGrp -q -value offsetCurveSubdivDensityIntSliderGrp`; // tolerance optionVar -floatValue offsetCurveTolerance `floatSliderGrp -q -v offsetCurveTolerance`; // curve range int $offsetCurveRangePartial = `radioButtonGrp -q -select offsetCurveRangeRadioButtonGrp` - 1 ; optionVar -intValue offsetCurveRangePartial $offsetCurveRangePartial; if( 1 == $doIt ) { performOffsetCurve( 0, $goToTool ); string $tmpCmd = "performOffsetCurve( 0, \"" + $goToTool + "\")"; addToRecentCommandQueue $tmpCmd "Offset Curve"; } else if ($doIt) { setToolTo $goToTool; } } // // Procedure Name: // createOffsetCurveUI // // Description: // Fill the contents of the option box for offsetCurve command. // // Input Arguments: // The name of the parent layout. // // Return Value: // None. // proc createOffsetCurveUI(string $parent, int $inTheTool, string $goToTool) { setParent $parent; radioButtonGrp -nrb 2 -select 1 -label (uiRes("m_performOffsetCurve.kNormalDirection")) -label1 (uiRes("m_performOffsetCurve.kActiveView")) -label2 (uiRes("m_performOffsetCurve.kGeometryAverage")) offsetCurveNormalRadioButtonGrp; floatSliderGrp -field on -fmn -1000. -fmx 1000. -min -10. -max 10. -label (uiRes("m_performOffsetCurve.kOffsetDistance")) offsetCurveDistanceFloatSliderGrp; radioButtonGrp -nrb 3 -select 1 -label (uiRes("m_performOffsetCurve.kConnectBreaks")) -label1 (uiRes("m_performOffsetCurve.kCircular")) -label2 (uiRes("m_performOffsetCurve.kLinear")) -label3 (uiRes("m_performOffsetCurve.kConnectBreaksOff")) offsetCurveConnectBreaksRadioButtonGrp; string $tabLayoutName = (`setParent -q` + "|offsetCurveLoopCutOptions_Tabs"); radioButtonGrp -nrb 2 -select 1 -label (uiRes("m_performOffsetCurve.kLoopCutting")) -label1 (uiRes("m_performOffsetCurve.kOn")) -label2 (uiRes("m_performOffsetCurve.kOff")) -on1 ("tabLayout -e -selectTab offsetCurveLoopCut_C " + "\"" + $tabLayoutName + "\"" + ";") -on2 ("tabLayout -e -selectTab offsetCurveNoLoopCut_C " + "\"" + $tabLayoutName + "\"" + ";") offsetCurveLoopCuttingRadioButtonGrp; tabLayout -tabsVisible false offsetCurveLoopCutOptions_Tabs; columnLayout offsetCurveLoopCut_C; floatSliderGrp -field on -fmn 0. -fmx 1000. -min 0. -max 1. -label (uiRes("m_performOffsetCurve.kCuttingRadius")) offsetCurveCutRadiusFloatSliderGrp; setParent ..; columnLayout offsetCurveNoLoopCut_C; setParent ..; setParent ..; intSliderGrp -field on -min 0 -max 10 -fmn 0 -fmx 100 -label (uiRes("m_performOffsetCurve.kMaxSubdivisionDensity")) offsetCurveSubdivDensityIntSliderGrp; radioButtonGrp -nrb 2 -label (uiRes("m_performOffsetCurve.kUseTolerance")) -label1 (uiRes("m_performOffsetCurve.kGlobal")) -label2 (uiRes("m_performOffsetCurve.kLocal")) -on1 "tabLayout -e -selectTab noSlider useGlobalTolTab" -on2 "tabLayout -e -selectTab slider useGlobalTolTab" useGlobalTol; tabLayout -tabsVisible false useGlobalTolTab; columnLayout slider; floatSliderGrp -label (uiRes("m_performOffsetCurve.kTolerance")) -min 0.001 -max 1.0 -fmn 0.00001 -fmx 10.0 offsetCurveTolerance; setParent ..; columnLayout noSlider; setParent ..; setParent ..; separator; // layout for add curve range, create as polygons. // radioButtonGrp -nrb 2 -label (uiRes("m_performOffsetCurve.kCurveRange")) -label1 (uiRes("m_performOffsetCurve.kComplete")) -label2 (uiRes("m_performOffsetCurve.kPartial")) -select 1 offsetCurveRangeRadioButtonGrp; if( $inTheTool ) { separator; checkBoxGrp -ncb 2 -label (uiRes("m_performOffsetCurve.kToolBehavior")) -label1 (uiRes("m_performOffsetCurve.kExitOnCompletion")) -v1 off -on1 ("scriptCtx -e -euc true " + $goToTool) -of1 ("scriptCtx -e -euc false " + $goToTool) -label2 (uiRes("m_performOffsetCurve.kAutoCompletion")) -v2 on -on2 ("scriptCtx -e -lac true " + $goToTool) -of2 ("scriptCtx -e -lac false " + $goToTool) scriptToolExtraWidget; } } // // Procedure Name: // offsetCurveOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc offsetCurveOptions( int $inTheTool, string $goToTool ) { // Name of the command for this option box. // string $commandName = "offsetCurve"; string $optionBoxTitle; if( $inTheTool ) { $optionBoxTitle = (uiRes("m_performOffsetCurve.kOffsetCurveToolOptions")); } else { $optionBoxTitle = (uiRes("m_performOffsetCurve.kOffsetCurveOptions")); } // Build the option box actions. // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); global string $gOptionBoxActionToolItem; $gOptionBoxActionToolItem = "modelWithToolOffsetCurve"; global string $gOptionBoxActionToolItemCB; $gOptionBoxActionToolItemCB = "offsetCurveToolScript 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. // createOffsetCurveUI($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. // 'OffsetCurve' button. // string $applyBtn = getOptionBoxApplyBtn(); if( $inTheTool ) { button -edit -label (uiRes("m_performOffsetCurve.kOffsetTool")) -command ($callback + " " + $parent + " 3 \"" + $goToTool + "\"") $applyBtn; } else { button -edit -label (uiRes("m_performOffsetCurve.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( "OffsetCurve" ); // Set the current values of the option box. // eval ($setup + " " + $parent + " 0 \"" + $goToTool + "\""); // Show the option box. // showOptionBox(); } // // Procedure Name: // offsetCurveHelp // // Description: // Returns a short description about the offsetCurve command. // // Input Arguments: // None. // // Return Value: // string. // proc string offsetCurveHelp() { return " Command: OffsetCurve - create a offset 3d curve from a 2d or 3d curve.\n" + "Select at least one curve to offset."; } // // Procedure Name: // assembleCmd // // Description: // Construct the offsetCurve command that will apply the option box // values. // // Input Arguments: // None. // // Return Value: // The offsetCurve command string. // proc string assembleCmd() { setOptionVars(false); string $cmd = "offsetCurvePreset"; $cmd = $cmd + "(" ; // get the global history flag value int $doHistory = `constructionHistory -q -tgl`; $cmd = $cmd + $doHistory + ","; int $curveRangePartial = `optionVar -q offsetCurveRangePartial`; $cmd = $cmd + $curveRangePartial + "," ; int $connectBreaks = `optionVar -q offsetCurveConnectBreaks`; $cmd = $cmd + $connectBreaks + ","; int $stitch = `optionVar -q offsetCurveStitch`; $cmd = $cmd + $stitch + ","; int $cutLoop = `optionVar -q offsetCurveLoopCutting`; $cmd = $cmd + $cutLoop + ","; float $cutRadius = `optionVar -q offsetCurveCutRadius`; $cmd = $cmd + $cutRadius + ","; float $distance = `optionVar -q offsetCurveDistance`; $cmd = $cmd + $distance + ","; float $tolerance = `optionVar -q offsetCurveTolerance`; if( `optionVar -q offsetCurveUseGlobalTol` ) { $tolerance = `optionVar -q positionalTolerance`; } $cmd = $cmd + $tolerance + ","; int $subdivDensity = `optionVar -q offsetCurveSubdivDensity`; $cmd = $cmd + $subdivDensity + ","; int $normalDir = `optionVar -q offsetCurveNormalDirection`; $cmd = $cmd + $normalDir; $cmd = $cmd + ")"; return $cmd; } // // Procedure Name: // performOffsetCurve // // Description: // Perform the offsetCurve 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 offsetCurve 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 offsetCurve command string. // global proc string performOffsetCurve( 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: offsetCurveOptions( $inTheTool, $goToTool ); break; case 2: default: setOptionVars(false); $cmd = `assembleCmd`; break; } return $cmd; }