// =========================================================================== // 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: 11 April 1997 // // Description: // Initialize the option values for attach menu item. // // Input Arguments: // int action // 0 - just execute the attach operation // 1 - show the option box dialog // 2 - drag to shelf // // Return Value: // None. // proc setOptionVars(int $forceFactorySettings) { // Keep multiple knots (on-1 or off-0 to be used if attach is on). // if ($forceFactorySettings || !`optionVar -exists attachKeepMultKnots`) { optionVar -intValue attachKeepMultKnots 1; } // keep original (for in place operations is on-1 or off-0). // if ($forceFactorySettings || !`optionVar -exists attachKeepOriginal`) { optionVar -intValue attachKeepOriginal 1; } // blend method // if ($forceFactorySettings || !`optionVar -exists attachSrfMethod`) { optionVar -intValue attachSrfMethod 1; } // insert knots for blend // if ($forceFactorySettings || !`optionVar -exists attachSrfBlendInsert`) { optionVar -intValue attachSrfBlendInsert 0; } // blend bias // if ($forceFactorySettings || !`optionVar -exists attachSrfBlendBias`) { optionVar -floatValue attachSrfBlendBias 0.5; } // blend insert // if ($forceFactorySettings || !`optionVar -exists attachSrfBlendParameter`) { optionVar -floatValue attachSrfBlendParameter 0.1; } } global proc attachSrfVisibility( string $parent, int $method, int $insert ) { if( $method < 0 ) { $method = `radioButtonGrp -q -sl attachSrfMethodWidget` - 1; } if( $insert < 0 ) { $insert = `checkBoxGrp -q -v1 attachSrfBlendInsertWidget`; } switch( $method ) { case 0: default: floatSliderGrp -e -en false attachSrfBlendBiasWidget; checkBoxGrp -e -en1 false attachSrfBlendInsertWidget; floatSliderGrp -e -en false attachSrfBlendParameterWidget; radioButtonGrp -e -en true attachMultKnotBtn; break; case 1: floatSliderGrp -e -en true attachSrfBlendBiasWidget; checkBoxGrp -e -en1 true attachSrfBlendInsertWidget; floatSliderGrp -e -en $insert attachSrfBlendParameterWidget; radioButtonGrp -e -en false attachMultKnotBtn; break; } } // // Procedure Name: // attachSrfSetup // // Description: // Update the state of the option box UI to reflect the attach // 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 attachSrfSetup( string $parent, int $forceFactorySettings, string $goToTool ) { // Retrieve the option settings // setOptionVars($forceFactorySettings); attachSrfToolSetup( $forceFactorySettings, $goToTool ); setParent $parent; // Query the optionVar's and set the values into the controls. int $method = `optionVar -query attachSrfMethod`; float $bias = `optionVar -query attachSrfBlendBias`; int $insert = `optionVar -query attachSrfBlendInsert`; float $parameter = `optionVar -query attachSrfBlendParameter`; int $keep = `optionVar -query attachKeepMultKnots`; int $keepOrig = `optionVar -query attachKeepOriginal`; radioButtonGrp -e -select ($method+1) attachSrfMethodWidget; floatSliderGrp -e -v $bias attachSrfBlendBiasWidget; checkBoxGrp -e -v1 $insert attachSrfBlendInsertWidget; floatSliderGrp -e -v $parameter attachSrfBlendParameterWidget; radioButtonGrp -edit -select (2 - $keep) attachMultKnotBtn; checkBoxGrp -edit -value1 $keepOrig attachKeepOriginalBox; if( "" != $goToTool ) { checkBoxGrp -e -v1 `scriptCtx -q -exitUponCompletion $goToTool` scriptToolExtraWidget; checkBoxGrp -e -v2 `scriptCtx -q -lac $goToTool` scriptToolExtraWidget; } attachSrfVisibility $parent -1 -1; } // // Procedure Name: // attachSrfCallback // // 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 attachSrfCallback(string $parent, int $doIt, string $goToTool) { if( "" != $goToTool ) { optionVar -iv attachSurfaceEuc `scriptCtx -q -euc $goToTool`; optionVar -iv attachSurfaceLac `scriptCtx -q -lac $goToTool`; } setParent $parent; // Set the optionVar's from the control values, and then // perform the command. int $method = `radioButtonGrp -q -select attachSrfMethodWidget` - 1; float $bias = `floatSliderGrp -q -v attachSrfBlendBiasWidget`; int $insert = `checkBoxGrp -q -v1 attachSrfBlendInsertWidget`; float $parameter = `floatSliderGrp -q -v attachSrfBlendParameterWidget`; int $keep = 2 - `radioButtonGrp -query -select attachMultKnotBtn`; int $keepOrig = `checkBoxGrp -query -value1 attachKeepOriginalBox`; optionVar -intValue attachSrfMethod $method; optionVar -floatValue attachSrfBlendBias $bias; optionVar -intValue attachSrfBlendInsert $insert; optionVar -floatValue attachSrfBlendParameter $parameter; optionVar -intValue attachKeepMultKnots $keep; optionVar -intValue attachKeepOriginal $keepOrig; if( 1 == $doIt ) { performAttachSrf( 0, $goToTool ); string $tmpCmd = "performAttachSrf( 0, \"" + $goToTool + "\")"; addToRecentCommandQueue $tmpCmd "Attach Surfaces"; } else if( $doIt ) { setToolTo $goToTool; } } // // Procedure Name: // createAttachSrfUI // // Description: // Fill the contents of the option box for attach command. // // Input Arguments: // The name of the parent layout. // // Return Value: // None. // proc createAttachSrfUI(string $parent, string $goToTool) { setParent $parent; radioButtonGrp -label (uiRes("m_performAttachSrf.kAttachMethod")) -nrb 2 -label1 (uiRes("m_performAttachSrf.kConnect")) -label2 (uiRes("m_performAttachSrf.kBlend")) -on1 ("attachSrfVisibility " + $parent + " 0 -1" ) -on2 ("attachSrfVisibility " + $parent + " 1 -1" ) attachSrfMethodWidget; radioButtonGrp -label (uiRes("m_performAttachSrf.kMultipleKnots")) -numberOfRadioButtons 2 -label1 (uiRes("m_performAttachSrf.kKeep")) -label2 (uiRes("m_performAttachSrf.kRemove")) attachMultKnotBtn; floatSliderGrp -label (uiRes("m_performAttachSrf.kBlendBias")) -min 0.0 -max 1.0 attachSrfBlendBiasWidget; checkBoxGrp -ncb 1 -label1 (uiRes("m_performAttachSrf.kInsertKnot")) -on1 ("attachSrfVisibility " + $parent + " -1 1" ) -of1 ("attachSrfVisibility " + $parent + " -1 0" ) attachSrfBlendInsertWidget; floatSliderGrp -label (uiRes("m_performAttachSrf.kInsertParameter")) -min 0.0 -max 1.0 attachSrfBlendParameterWidget; checkBoxGrp -numberOfCheckBoxes 1 -label1 (uiRes("m_performAttachSrf.kKeepOriginals")) attachKeepOriginalBox; if( "" != $goToTool ) { separator; checkBoxGrp -ncb 2 -label (uiRes("m_performAttachSrf.kToolBehavior")) -label1 (uiRes("m_performAttachSrf.kExit")) -v1 on -on1 ("scriptCtx -e -euc true " + $goToTool) -of1 ("scriptCtx -e -euc false " + $goToTool) -label2 (uiRes("m_performAttachSrf.kAuto")) -v2 on -on2 ("scriptCtx -e -lac true " + $goToTool) -of2 ("scriptCtx -e -lac false " + $goToTool) scriptToolExtraWidget; } } // // Procedure Name: // attachOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc attachOptions( string $inTheTool, string $goToTool ) { // Name of the command for this option box. // string $commandName = "attach"; // Build the option box actions. // string $callback = ($commandName + "SrfCallback"); string $setup = ($commandName + "SrfSetup"); // The value returned is the name of the layout to be used as // the parent for the option box UI. // global string $gOptionBoxActionToolItem; $gOptionBoxActionToolItem = "modelWithToolAttachSurface"; global string $gOptionBoxActionToolItemCB; $gOptionBoxActionToolItemCB = "attachSrfToolScript 3"; 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+"Surface"); // 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. // createAttachSrfUI($parent, $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. // 'Attach' button. // string $applyBtn = getOptionBoxApplyBtn(); if( $inTheTool ) { button -edit -label (uiRes("m_performAttachSrf.kAttachTool")) -command ($callback + " " + $parent + " 3 \"" + $goToTool + "\"" ) $applyBtn; } else { button -edit -label (uiRes("m_performAttachSrf.kAttach")) -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. // if( $inTheTool ) { setOptionBoxTitle (uiRes("m_performAttachSrf.kSurfacesToolTitle")); } else { setOptionBoxTitle (uiRes("m_performAttachSrf.kSurfacesTitle")); } // Customize the 'Help' menu item text. // setOptionBoxHelpTag( "AttachSurfaces" ); // Set the current values of the option box. // eval ($setup + " " + $parent + " 0 \"" + $goToTool + "\""); // Show the option box. // showOptionBox(); } // // Procedure Name: // attachHelp // // Description: // Returns a short description about the attach command. // // Input Arguments: // None. // // Return Value: // string. // proc string attachHelp() { return " Command: Attach - joins two surfaces together\n" + "Selection: two surfaces or an isoparm on two surfaces."; } // // Procedure Name: // assembleCmd // // Description: // Construct the attach command that will apply the option box values. // // Input Arguments: // None. // // Return Value: // The attach command string. // proc string assembleCmd() { setOptionVars(false); // get the global history flag value int $doHistory = `constructionHistory -q -tgl`; // is replace original on/off int $replaceOriginal = !`optionVar -q attachKeepOriginal`; // attach related values int $keepMultKnots = `optionVar -query attachKeepMultKnots`; int $method = `optionVar -query attachSrfMethod`; float $bias = `optionVar -query attachSrfBlendBias`; int $insert = `optionVar -query attachSrfBlendInsert`; float $parameter = `optionVar -query attachSrfBlendParameter`; // set up string for preset function call string $cmd = "doAttachSurfaceArgList 2 { "; $cmd = $cmd + "\"" + $doHistory + "\", "; $cmd = $cmd + "\"" + $replaceOriginal + "\", "; $cmd = $cmd + "\"" + $keepMultKnots + "\", "; $cmd = $cmd + "\"" + $method + "\", "; $cmd = $cmd + "\"" + $bias + "\", "; $cmd = $cmd + "\"" + $insert + "\", "; $cmd = $cmd + "\"" + $parameter + "\" }"; return $cmd; } // // Procedure Name: // performAttachSrf // // Description: // Perform the attach 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 attach command with the current // option box values. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // 3 - Show the tool option box dialog. // // Return Value: // The attach command string. // global proc string performAttachSrf(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: attachOptions( $inTheTool, $goToTool ); break; case 2: setOptionVars(false); $cmd = `assembleCmd`; break; } return $cmd; }