// =========================================================================== // 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: 24 April 1997 // // Description: // This script provides an option box dialog for the orientConstraint command. // // Input Arguments: // boolean showOptionBox true - show the option box dialog // false - just execute the command // // // Procedure Name: // setOptionVars // // Description: // Initialize the option values. // // Input Arguments: // Whether to set the options to default values. // // Return Value: // None. // proc setOptionVars(int $forceFactorySettings) { // weight // if ($forceFactorySettings || !`optionVar -exists orientConstraintWeight`) { optionVar -floatValue orientConstraintWeight 1.0; } // offset values // if ($forceFactorySettings || !`optionVar -exists orientConstOffsetX`) { optionVar -floatValue orientConstOffsetX 0.0; } if ($forceFactorySettings || !`optionVar -exists orientConstOffsetY`) { optionVar -floatValue orientConstOffsetY 0.0; } if ($forceFactorySettings || !`optionVar -exists orientConstOffsetZ`) { optionVar -floatValue orientConstOffsetZ 0.0; } // maintain existing offset // if ($forceFactorySettings || !`optionVar -exists orientConstMaintainOffset`) { optionVar -intValue orientConstMaintainOffset 0; } // Constraint Axes // if ($forceFactorySettings || !`optionVar -exists orientConstraintAxisX`) { optionVar -intValue orientConstraintAxisX true; } if ($forceFactorySettings || !`optionVar -exists orientConstraintAxisY`) { optionVar -intValue orientConstraintAxisY true; } if ($forceFactorySettings || !`optionVar -exists orientConstraintAxisZ`) { optionVar -intValue orientConstraintAxisZ true; } // AnimLayer if ($forceFactorySettings || !`optionVar -exists constraintAnimLayer`) { optionVar -stringValue constraintAnimLayer ""; } if ($forceFactorySettings || !`optionVar -exists orientConstraintAnimLayerToOverride`) { optionVar -intValue orientConstraintAnimLayerToOverride true; } } // // Procedure Name: // orientConstraintSetup // // 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 orientConstraintSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls. // weight // floatSliderGrp -edit -value `optionVar -query orientConstraintWeight` orientConstraintWeight; float $rx = `optionVar -query orientConstOffsetX`; float $ry = `optionVar -query orientConstOffsetY`; float $rz = `optionVar -query orientConstOffsetZ`; if (`optionVar -query orientConstMaintainOffset`) { checkBoxGrp -edit -value1 1 orientConstraintMaintainWidget; floatFieldGrp -edit -enable 0 offsetField; } else { checkBoxGrp -edit -value1 0 orientConstraintMaintainWidget; floatFieldGrp -edit -enable 1 offsetField; } floatFieldGrp -e -v1 $rx -v2 $ry -v3 $rz offsetField; // AnimLayer string $animLayer = `optionVar -query constraintAnimLayer`; optionMenuGrp -edit -select 1 orientConstraintAnimLayerWidget; if( size( $animLayer ) > 0 ) { if( size( `ls $animLayer` ) > 0 ) { if( `objectType $animLayer` == "animLayer" ) { optionMenuGrp -edit -value $animLayer orientConstraintAnimLayerWidget; } } } int $overrideAnimLayer = `optionVar -query orientConstraintAnimLayerToOverride`; checkBoxGrp -edit -value1 $overrideAnimLayer orientConstraintOverrideAnimLayer; // Axis values // int $axisX = `optionVar -query orientConstraintAxisX`; int $axisY = `optionVar -query orientConstraintAxisY`; int $axisZ = `optionVar -query orientConstraintAxisZ`; // if all axes are on, select the all box and dim the individual axes if ($axisX && $axisY && $axisZ) { checkBoxGrp -edit -value1 true axesAll; checkBoxGrp -edit -value1 false -value2 false -value3 false axesXYZ; } // otherwise just select those boxes corresponding to 'on' axes else { checkBoxGrp -edit -value1 false axesAll; checkBoxGrp -edit -value1 $axisX -value2 $axisY -value3 $axisZ axesXYZ; } } // // Procedure Name: // orientConstraintCallback // // 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 orientConstraintCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then // perform the command. // weight // optionVar -floatValue orientConstraintWeight `floatSliderGrp -query -value orientConstraintWeight`; // maintain offset // optionVar -intValue orientConstMaintainOffset `checkBoxGrp -query -value1 orientConstraintMaintainWidget`; // Offset values // optionVar -floatValue orientConstOffsetX `floatFieldGrp -query -v1 offsetField`; optionVar -floatValue orientConstOffsetY `floatFieldGrp -query -v2 offsetField`; optionVar -floatValue orientConstOffsetZ `floatFieldGrp -query -v3 offsetField`; // AnimLayer if( `optionMenuGrp -query -select orientConstraintAnimLayerWidget` > 1 ) { optionVar -stringValue constraintAnimLayer `optionMenuGrp -query -value orientConstraintAnimLayerWidget`; } else { // First Item Selected, None // Save an empty field in the fconfig file optionVar -stringValue constraintAnimLayer ""; } optionVar -intValue orientConstraintAnimLayerToOverride `checkBoxGrp -q -value1 orientConstraintOverrideAnimLayer`; // Axis values // // Either the 'All' box is checked (and so all axes are on) ... if ( `checkBoxGrp -query -value1 axesAll` ) { optionVar -intValue orientConstraintAxisX true; optionVar -intValue orientConstraintAxisY true; optionVar -intValue orientConstraintAxisZ true; } else { // ... Or only those axes specifically selected are on optionVar -intValue orientConstraintAxisX `checkBoxGrp -query -value1 axesXYZ`; optionVar -intValue orientConstraintAxisY `checkBoxGrp -query -value2 axesXYZ`; optionVar -intValue orientConstraintAxisZ `checkBoxGrp -query -value3 axesXYZ`; } if ($doIt) { performOrientConstraint 0; addToRecentCommandQueue "performOrientConstraint 0" "OrientConstraint"; } } // // Procedure Name: // orientConstraintOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc orientConstraintOptions() { // Name of the command for this option box. // string $commandName = "orientConstraint"; // Build the option box actions. // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); // Get the option box. // string $layout = getOptionBox(); setParent $layout; // Pass the command name to the option box. // setOptionBoxCommandName($commandName); // Activate the default UI template. // setUITemplate -pushTemplate DefaultTemplate; // Turn on the wait cursor. // waitCursor -state 1; tabLayout -scr true -tv false; string $parent = `columnLayout -adjustableColumn 1`; checkBoxGrp -label (uiRes("m_performOrientConstraint.kMaintainOffset")) -label1 " " -annotation (uiRes("m_performOrientConstraint.kMaintainOffsetAnnot")) -numberOfCheckBoxes 1 -cc ("floatFieldGrp -edit -enable (! #1) offsetField;") orientConstraintMaintainWidget; floatFieldGrp -label (uiRes("m_performOrientConstraint.kOffset")) -numberOfFields 3 offsetField; // AnimLayer field string $lLayers[] = `ls -type animLayer`; optionMenuGrp -label (uiRes("m_performOrientConstraint.kAnimLayer")) orientConstraintAnimLayerWidget; menuItem -label (uiRes("m_performOrientConstraint.kNone")); for ($layer in $lLayers) { menuItem -label $layer; } checkBoxGrp -label (uiRes("m_performOrientConstraint.kOrientConstraintAnimLayerToOverride")) -annotation (uiRes("m_performOrientConstraint.kOrientConstraintAnimLayerToOverrideAnnot")) -numberOfCheckBoxes 1 orientConstraintOverrideAnimLayer; separator; // Constraint Axes Selection Boxes // // The 'axesAll' checkBoxGrp and the 'axesXYZ' checkBoxGrp are linked // such that when 'axesAll' is selected, all the 'axesXYZ' boxes are // unselected. And when any 'axesXYZ' box is selected the 'axesAll' // box is deselected. checkBoxGrp -numberOfCheckBoxes 1 -label (uiRes("m_performOrientConstraint.kConstraintAxes")) -label1 (uiRes("m_performOrientConstraint.kAll")) -onCommand ("checkBoxGrp -edit " + "-value1 false " + "-value2 false " + "-value3 false " + "axesXYZ") axesAll; checkBoxGrp -numberOfCheckBoxes 3 -label1 (uiRes("m_performOrientConstraint.kX")) -label2 (uiRes("m_performOrientConstraint.kY")) -label3 (uiRes("m_performOrientConstraint.kZ")) -onCommand ("checkBoxGrp -edit " + "-value1 false " + "axesAll;") axesXYZ; separator; floatSliderGrp -label (uiRes("m_performOrientConstraint.kWeight")) -field true -min 0.0 -max 1.0 orientConstraintWeight; // Turn off the wait cursor. // waitCursor -state 0; // Deactivate the default UI template. // setUITemplate -popTemplate; // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performOrientConstraint.kAddButton")) -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; // Set the option box title. // setOptionBoxTitle (uiRes("m_performOrientConstraint.kOrientConstraintOptions")); // Customize the 'Help' menu item text. // setOptionBoxHelpTag( "Orient" ); // Set the current values of the option box. // eval (($setup + " " + $parent + " " + 0)); // Show the option box. // showOptionBox(); } // // Procedure Name: // orientConstraintHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string orientConstraintHelp() { // ******** Example // " Command: Extrude - create a surface using extrusion.\n" + // "Selection: curves and isoparms." return " Command: orientConstraint - \n" + "Selection: "; } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // // Return Value: // None. // proc string assembleCmd() { string $cmd; setOptionVars(false); int $maintainOffset = `optionVar -query orientConstMaintainOffset`; float $rx = `optionVar -query orientConstOffsetX`; float $ry = `optionVar -query orientConstOffsetY`; float $rz = `optionVar -query orientConstOffsetZ`; // AnimLayer string $animLayer = `optionVar -query constraintAnimLayer`; int $overrideAnimLayer = `optionVar -query orientConstraintAnimLayerToOverride`; // Axis values // // The axis values are inverted so that they represent // which axes to *skip* as opposed to which axes are on. int $axisX = !`optionVar -query orientConstraintAxisX`; int $axisY = !`optionVar -query orientConstraintAxisY`; int $axisZ = !`optionVar -query orientConstraintAxisZ`; float $weight = `optionVar -query orientConstraintWeight`; $cmd = "doCreateOrientConstraintArgList 1 { " + "\"" + $maintainOffset + "\"" + ",\"" + $rx + "\"" + ",\"" + $ry + "\"" + ",\"" + $rz + "\"" + ",\"" + $axisX + "\"" + ",\"" + $axisY + "\"" + ",\"" + $axisZ + "\"" + ",\"" + $weight + "\"" + ",\"" + $animLayer + "\"" + ",\"" + $overrideAnimLayer + "\"" + " };"; return $cmd; } // // Procedure Name: // performOrientConstraint // // Description: // Perform the orientConstraint 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 orientConstraint 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 performOrientConstraint(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: // Retrieve the option settings // setOptionVars(false); // Get the command. // $cmd = `assembleCmd`; // Execute the command with the option settings. // evalEcho($cmd); break; // Show the option box. // case 1: orientConstraintOptions; break; // Return the command string. // case 2: // Retrieve the option settings. // setOptionVars (false); // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }