// =========================================================================== // 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: Setember 11, 2002 // // // 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 parentConstraintWeight`) { optionVar -floatValue parentConstraintWeight 1.0; } // maintain existing offset // if ($forceFactorySettings || !`optionVar -exists parConstMaintainOffset`) { optionVar -intValue parConstMaintainOffset 1; } // rotation decomposition target to maintain existing rotation offset // if ($forceFactorySettings || !`optionVar -exists parConstRotationDecompTarget`) { optionVar -intValue parConstRotationDecompTarget 0; } // constraint axes // // ConstraintAxisTranslate if ($forceFactorySettings || !`optionVar -exists parentConstraintAxisTranslateX`) { optionVar -intValue parentConstraintAxisTranslateX true; } if ($forceFactorySettings || !`optionVar -exists parentConstraintAxisTranslateY`) { optionVar -intValue parentConstraintAxisTranslateY true; } if ($forceFactorySettings || !`optionVar -exists parentConstraintAxisTranslateZ`) { optionVar -intValue parentConstraintAxisTranslateZ true; } // ConstraintAxisRotate if ($forceFactorySettings || !`optionVar -exists parentConstraintAxisRotateX`) { optionVar -intValue parentConstraintAxisRotateX true; } if ($forceFactorySettings || !`optionVar -exists parentConstraintAxisRotateY`) { optionVar -intValue parentConstraintAxisRotateY true; } if ($forceFactorySettings || !`optionVar -exists parentConstraintAxisRotateZ`) { optionVar -intValue parentConstraintAxisRotateZ true; } // AnimLayer if ($forceFactorySettings || !`optionVar -exists constraintAnimLayer`) { optionVar -stringValue constraintAnimLayer ""; } if ($forceFactorySettings || !`optionVar -exists parentConstraintAnimLayerToOverride`) { optionVar -intValue parentConstraintAnimLayerToOverride true; } } // // Procedure Name: // parentConstraintSetup // // 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 parentConstraintSetup(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 parentConstraintWeight` parentConstraintWeight; // Query the state of the MaintainOffsetField, and set the initial // offsets accordingly // // Offset values // // MaintainOffset if (`optionVar -query parConstMaintainOffset`) { checkBoxGrp -edit -value1 1 parentConstraintMaintainWidget; } else { checkBoxGrp -edit -value1 0 parentConstraintMaintainWidget; } // rotation decomposition target values if (`optionVar -query parConstRotationDecompTarget`) { checkBoxGrp -edit -value1 1 parentConstraintDecompWidget; } else { checkBoxGrp -edit -value1 0 parentConstraintDecompWidget; } // AnimLayer string $animLayer = `optionVar -query constraintAnimLayer`; optionMenuGrp -edit -select 1 parentConstraintAnimLayerWidget; if( size( $animLayer ) > 0 ) { if( size( `ls $animLayer` ) > 0 ) { if( `objectType $animLayer` == "animLayer" ) { optionMenuGrp -edit -value $animLayer parentConstraintAnimLayerWidget; } } } int $overrideAnimLayer = `optionVar -query parentConstraintAnimLayerToOverride`; checkBoxGrp -edit -value1 $overrideAnimLayer parentConstraintOverrideAnimLayer; // Axis values // // ConstraintAxisTranslate int $axisTranslateX = `optionVar -query parentConstraintAxisTranslateX`; int $axisTranslateY = `optionVar -query parentConstraintAxisTranslateY`; int $axisTranslateZ = `optionVar -query parentConstraintAxisTranslateZ`; // if all axes are on, select the all box and dim the individual axes if ($axisTranslateX && $axisTranslateY && $axisTranslateZ) { checkBoxGrp -edit -value1 true axesTranslateAll; checkBoxGrp -edit -value1 false -value2 false -value3 false axesTranslateXYZ; } // otherwise just select those boxes corresponding to 'on' axes else { checkBoxGrp -edit -value1 false axesTranslateAll; checkBoxGrp -edit -value1 $axisTranslateX -value2 $axisTranslateY -value3 $axisTranslateZ axesTranslateXYZ; } // ConstraintAxisRotate int $axisRotateX = `optionVar -query parentConstraintAxisRotateX`; int $axisRotateY = `optionVar -query parentConstraintAxisRotateY`; int $axisRotateZ = `optionVar -query parentConstraintAxisRotateZ`; // if all axes are on, select the all box and dim the individual axes if ($axisRotateX && $axisRotateY && $axisRotateZ) { checkBoxGrp -edit -value1 true axesRotateAll; checkBoxGrp -edit -value1 false -value2 false -value3 false axesRotateXYZ; } // otherwise just select those boxes corresponding to 'on' axes else{ checkBoxGrp -edit -value1 false axesRotateAll; checkBoxGrp -edit -value1 $axisRotateX -value2 $axisRotateY -value3 $axisRotateZ axesRotateXYZ; } } // // Procedure Name: // parentConstraintCallback // // 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 parentConstraintCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then // perform the command. // weight // optionVar -floatValue parentConstraintWeight `floatSliderGrp -query -value parentConstraintWeight`; // maintain offset // // MaintainOffset optionVar -intValue parConstMaintainOffset `checkBoxGrp -query -value1 parentConstraintMaintainWidget`; // rotation decomposition optionVar -intValue parConstRotationDecompTarget `checkBoxGrp -query -value1 parentConstraintDecompWidget`; // AnimLayer if( `optionMenuGrp -query -select parentConstraintAnimLayerWidget` > 1 ) { optionVar -stringValue constraintAnimLayer `optionMenuGrp -query -value parentConstraintAnimLayerWidget`; } else { // First Item Selected, None // Save an empty field in the fconfig file optionVar -stringValue constraintAnimLayer ""; } optionVar -intValue parentConstraintAnimLayerToOverride `checkBoxGrp -q -value1 parentConstraintOverrideAnimLayer`; // Axis values // // ConstraintAxisTranslate // Either the 'All' box is checked (and so all axes are on) ... if ( `checkBoxGrp -query -value1 axesTranslateAll` ) { optionVar -intValue parentConstraintAxisTranslateX true; optionVar -intValue parentConstraintAxisTranslateY true; optionVar -intValue parentConstraintAxisTranslateZ true; } else { // ... Or only those axes specifically selected are on optionVar -intValue parentConstraintAxisTranslateX `checkBoxGrp -query -value1 axesTranslateXYZ`; optionVar -intValue parentConstraintAxisTranslateY `checkBoxGrp -query -value2 axesTranslateXYZ`; optionVar -intValue parentConstraintAxisTranslateZ `checkBoxGrp -query -value3 axesTranslateXYZ`; } // ConstraintAxisRotate // Either the 'All' box is checked (and so all axes are on) ... if ( `checkBoxGrp -query -value1 axesRotateAll` ) { optionVar -intValue parentConstraintAxisRotateX true; optionVar -intValue parentConstraintAxisRotateY true; optionVar -intValue parentConstraintAxisRotateZ true; } else { // ... Or only those axes specifically selected are on optionVar -intValue parentConstraintAxisRotateX `checkBoxGrp -query -value1 axesRotateXYZ`; optionVar -intValue parentConstraintAxisRotateY `checkBoxGrp -query -value2 axesRotateXYZ`; optionVar -intValue parentConstraintAxisRotateZ `checkBoxGrp -query -value3 axesRotateXYZ`; } if ($doIt) { performParentConstraint 0; addToRecentCommandQueue "performParentConstraint 0" "ParentConstraint"; } } // // Procedure Name: // parentConstraintOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc parentConstraintOptions() { // Name of the command for this option box. // string $commandName = "parentConstraint"; // 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`; //frameLayout -label "Offset" -collapsable false -collapse false; //columnLayout; checkBoxGrp -label (uiRes("m_performParentConstraint.kMaintainOffset")) -label1 " " -annotation (uiRes("m_performParentConstraint.kMaintainOffsetAnnot")) -numberOfCheckBoxes 1 parentConstraintMaintainWidget; //setParent ..; //setParent ..; checkBoxGrp -label (uiRes("m_performParentConstraint.kDecompRotationToChild")) -label1 " " -annotation (uiRes("m_performParentConstraint.kDecompRotationToChildAnnot")) -numberOfCheckBoxes 1 parentConstraintDecompWidget; // AnimLayer field string $lLayers[] = `ls -type animLayer`; optionMenuGrp -label (uiRes("m_performParentConstraint.kAnimLayer")) parentConstraintAnimLayerWidget; menuItem -label (uiRes("m_performParentConstraint.kNone")); for ($layer in $lLayers) { menuItem -label $layer; } checkBoxGrp -label (uiRes("m_performParentConstraint.kParentConstraintAnimLayerToOverride")) -annotation (uiRes("m_performParentConstraint.kParentConstraintAnimLayerToOverrideAnnot")) -numberOfCheckBoxes 1 parentConstraintOverrideAnimLayer; 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. // axesTranslate frameLayout -label (uiRes("m_performParentConstraint.kConstraintAxes")) -collapsable false -collapse false; columnLayout; string $allOption = (uiRes("m_performParentConstraint.kAll")); checkBoxGrp -numberOfCheckBoxes 1 -label (uiRes("m_performParentConstraint.kTranslate")) -label1 $allOption -onCommand ("checkBoxGrp -edit " + "-value1 false " + "-value2 false " + "-value3 false " + "axesTranslateXYZ") axesTranslateAll; string $x = (uiRes("m_performParentConstraint.kX")); string $y = (uiRes("m_performParentConstraint.kY")); string $z = (uiRes("m_performParentConstraint.kZ")); checkBoxGrp -numberOfCheckBoxes 3 -label1 $x -label2 $y -label3 $z -onCommand ("checkBoxGrp -edit " + "-value1 false " + "axesTranslateAll;") axesTranslateXYZ; // axesRotate checkBoxGrp -numberOfCheckBoxes 1 -label (uiRes("m_performParentConstraint.kRotate")) -label1 $allOption -onCommand ("checkBoxGrp -edit " + "-value1 false " + "-value2 false " + "-value3 false " + "axesRotateXYZ") axesRotateAll; checkBoxGrp -numberOfCheckBoxes 3 -label1 $x -label2 $y -label3 $z -onCommand ("checkBoxGrp -edit " + "-value1 false " + "axesRotateAll;") axesRotateXYZ; setParent ..; setParent ..; floatSliderGrp -label (uiRes("m_performParentConstraint.kWeight")) -field true -min 0.0 -max 1.0 parentConstraintWeight; // 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_performParentConstraint.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_performParentConstraint.kParentConstraintOptions")); // Customize the 'Help' menu item text. // setOptionBoxHelpTag( "ParentConstraint" ); // Set the current values of the option box. // eval (($setup + " " + $parent + " " + 0)); // Show the option box. // showOptionBox(); } // // Procedure Name: // parentConstraintHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string parentConstraintHelp() { // ******** Example // " Command: Extrude - create a surface using extrusion.\n" + // "Selection: curves and isoparms." return " Command: parentConstraint - \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 parConstMaintainOffset`; int $rotateDecomp = `optionVar -query parConstRotationDecompTarget`; string $animLayer = `optionVar -query constraintAnimLayer`; int $overrideMode = `optionVar -query parentConstraintAnimLayerToOverride`; // Axis values // // AxisTranslate // The axis values are inverted so that they represent // which axes to *skip* as opposed to which axes are on. int $axisTranslateX = !`optionVar -query parentConstraintAxisTranslateX`; int $axisTranslateY = !`optionVar -query parentConstraintAxisTranslateY`; int $axisTranslateZ = !`optionVar -query parentConstraintAxisTranslateZ`; // Axis Rotate // The axis values are inverted so that they represent // which axes to *skip* as opposed to which axes are on. int $axisRotateX = !`optionVar -query parentConstraintAxisRotateX`; int $axisRotateY = !`optionVar -query parentConstraintAxisRotateY`; int $axisRotateZ = !`optionVar -query parentConstraintAxisRotateZ`; float $weight = `optionVar -query parentConstraintWeight`; $cmd = "doCreateParentConstraintArgList 1 { " + "\"" + $maintainOffset + "\"" + ",\"" + $rotateDecomp + "\"" + ",\"" + $axisTranslateX + "\"" + ",\"" + $axisTranslateY + "\"" + ",\"" + $axisTranslateZ + "\"" + ",\"" + $axisRotateX + "\"" + ",\"" + $axisRotateY + "\"" + ",\"" + $axisRotateZ + "\"" + ",\"" + $weight + "\"" + ",\"" + $animLayer + "\"" + ",\"" + $overrideMode + "\"" + " };"; return $cmd; } // // Procedure Name: // performParentConstraint // // Description: // Perform the parentConstraint 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 parentConstraint 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 performParentConstraint(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: parentConstraintOptions; break; // Return the command string. // case 2: // Retrieve the option settings. // setOptionVars (false); // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }