// =========================================================================== // 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: November 18, 1996 // // Description: // Duplicate special option box script. // // // 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) { // Rename Children flag // if ($forceFactorySettings || !`optionVar -exists duplicateSpecialRenameChildren`) { optionVar -intValue duplicateSpecialRenameChildren false; } // Smart transform flag // if ($forceFactorySettings || !`optionVar -exists duplicateSpecialSmart`) { optionVar -intValue duplicateSpecialSmart false; } // Number of duplicates // if ($forceFactorySettings || !`optionVar -exists duplicateSpecialCount`) { optionVar -intValue duplicateSpecialCount 1; } // Copy flag // if ($forceFactorySettings || !`optionVar -exists duplicateSpecialCopy`) { optionVar -intValue duplicateSpecialCopy true; } // Group flag // if ($forceFactorySettings || !`optionVar -exists duplicateSpecialGroup`) { optionVar -intValue duplicateSpecialGroup 1; } // Duplicate upstream nodes flag // if ($forceFactorySettings || !`optionVar -exists duplicateSpecialUpstream`) { optionVar -intValue duplicateSpecialUpstream false; } // Duplicate input Connections flag // if ($forceFactorySettings || !`optionVar -exists duplicateSpecialInputConn`) { optionVar -intValue duplicateSpecialInputConn false; } // Instance leaf shapes flag // if ($forceFactorySettings || !`optionVar -exists duplicateSpecialInstanceLeaf`) { optionVar -intValue duplicateSpecialInstanceLeaf false; } // Translate values // if ($forceFactorySettings || !`optionVar -exists duplicateSpecialTX`) { optionVar -floatValue duplicateSpecialTX 0.0; } if ($forceFactorySettings || !`optionVar -exists duplicateSpecialTY`) { optionVar -floatValue duplicateSpecialTY 0.0; } if ($forceFactorySettings || !`optionVar -exists duplicateSpecialTZ`) { optionVar -floatValue duplicateSpecialTZ 0.0; } // Rotate values // if ($forceFactorySettings || !`optionVar -exists duplicateSpecialRX`) { optionVar -floatValue duplicateSpecialRX 0.0; } if ($forceFactorySettings || !`optionVar -exists duplicateSpecialRY`) { optionVar -floatValue duplicateSpecialRY 0.0; } if ($forceFactorySettings || !`optionVar -exists duplicateSpecialRZ`) { optionVar -floatValue duplicateSpecialRZ 0.0; } // Scale values // if ($forceFactorySettings || !`optionVar -exists duplicateSpecialSX`) { optionVar -floatValue duplicateSpecialSX 1.0; } if ($forceFactorySettings || !`optionVar -exists duplicateSpecialSY`) { optionVar -floatValue duplicateSpecialSY 1.0; } if ($forceFactorySettings || !`optionVar -exists duplicateSpecialSZ`) { optionVar -floatValue duplicateSpecialSZ 1.0; } } // // Procedure Name: // duplicateSpecialSetup // // 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 duplicateSpecialSetup (string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars ($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls. // int $renameChildren = `optionVar -query duplicateSpecialRenameChildren`; int $numDuplicates = `optionVar -query duplicateSpecialCount`; int $smart = `optionVar -query duplicateSpecialSmart`; int $copy = `optionVar -query duplicateSpecialCopy`; int $group = `optionVar -query duplicateSpecialGroup`; if ($group == 0) $group = 1; // Earlier boolean false should now map to 1 int $upstream = `optionVar -query duplicateSpecialUpstream`; int $inputConn = `optionVar -query duplicateSpecialInputConn`; int $instanceLeaf = `optionVar -query duplicateSpecialInstanceLeaf`; // Rename Children flag // checkBoxGrp -edit -value1 $renameChildren renameChildrenField; // Number of duplicates // intSliderGrp -edit -value $numDuplicates numDuplicatesField; // Smart transform flag // checkBoxGrp -edit -value1 $smart smartCheck; // Copy flag // int $boolToOption[] = { 2, 1 }; radioButtonGrp -edit -select $boolToOption[$copy] geometryTypeGroup; // Group flag // radioButtonGrp -edit -select $group otherOptionsGroup; // Duplicate upstream nodes flag // checkBoxGrp -edit -value1 $upstream upstreamCheck; // Duplicate input Connections flag // checkBoxGrp -edit -value1 $inputConn inputConnCheck; // Instance leaf shapes flag // checkBoxGrp -edit -value1 $instanceLeaf instanceLeafCheck; // Translate values // float $tx = `optionVar -query duplicateSpecialTX`; float $ty = `optionVar -query duplicateSpecialTY`; float $tz = `optionVar -query duplicateSpecialTZ`; floatFieldGrp -edit -value1 $tx -value2 $ty -value3 $tz transField; // Rotate values // float $rx = `optionVar -query duplicateSpecialRX`; float $ry = `optionVar -query duplicateSpecialRY`; float $rz = `optionVar -query duplicateSpecialRZ`; floatFieldGrp -edit -value1 $rx -value2 $ry -value3 $rz rotateField; // Scale values // float $sx = `optionVar -query duplicateSpecialSX`; float $sy = `optionVar -query duplicateSpecialSY`; float $sz = `optionVar -query duplicateSpecialSZ`; floatFieldGrp -edit -value1 $sx -value2 $sy -value3 $sz scaleField; duplicateSpecialOptionsUpdateEnableState($parent); } global proc duplicateSpecialOptionsUpdateEnableState(string $parent) // // Description: // Update the enable state of all the option box controls. // // Call this whenever any of the control values changes. // { int $smartTransform; int $makeInstance; int $groupParent; int $simpleCopy; int $upstreamGraph; int $inputConnections; int $instanceLeaf; int $numberOfDuplicates; int $enableSmartTransform; int $enableTRSFields; setParent $parent; // Determine the number of duplicates. // $numberOfDuplicates = `intSliderGrp -query -value numDuplicatesField`; // Determine if smart transform is on. // $smartTransform = `checkBoxGrp -query -value1 smartCheck`; // Determine if copying geometry or making instance. // $copyGeometry = true; if (2 == `radioButtonGrp -query -select geometryTypeGroup`) { $copyGeometry = false; } // Determine if duplicate is to be under the parent. // $groupParent = false; if (1 == `radioButtonGrp -query -select otherOptionsGroup`) { $groupParent = true; } // Determine if settings describe a simple copy, ie. no duplication // of Upstream graph or Input connections, or instancing of leaf nodes. // $simpleCopy = true; $upstreamGraph = `checkBoxGrp -query -value1 upstreamCheck`; $inputConnections = `checkBoxGrp -query -value1 inputConnCheck`; $instanceLeaf = `checkBoxGrp -query -value1 instanceLeafCheck`; if ($upstreamGraph || $inputConnections) { $simpleCopy = false; } // Enable Smart Transform check box... // $enableSmartTransform = false; if (1 == $numberOfDuplicates && $groupParent && $simpleCopy) { $enableSmartTransform = true; } checkBoxGrp -edit -enable $enableSmartTransform smartCheck; // Enable Translate, rotate and scale fields... // $enableTRSFields = false; if (!$smartTransform && $simpleCopy) { $enableTRSFields = true; } floatFieldGrp -edit -enable $enableTRSFields transField; floatFieldGrp -edit -enable $enableTRSFields rotateField; floatFieldGrp -edit -enable $enableTRSFields scaleField; // Enable Upstream Graph and Input Connection check boxes... // checkBoxGrp -edit -enable ($copyGeometry && !$inputConnections) upstreamCheck; checkBoxGrp -edit -enable ($copyGeometry && !$upstreamGraph) inputConnCheck; // Enable Instance Leaf check box (only valid if copying geometry) // checkBoxGrp -edit -enable $copyGeometry instanceLeafCheck; // Enable Geometry Type radio button... // radioButtonGrp -edit -enable ($simpleCopy && !$instanceLeaf) geometryTypeGroup; } // // Procedure Name: // duplicateSpecialCallback // // 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 duplicateSpecialCallback (string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then // perform the command // Smart transform flag // optionVar -intValue duplicateSpecialSmart `checkBoxGrp -query -value1 smartCheck`; // Rename Children flag // optionVar -intValue duplicateSpecialRenameChildren `checkBoxGrp -query -value1 renameChildrenField`; // Number of duplicates // optionVar -intValue duplicateSpecialCount `intSliderGrp -query -value numDuplicatesField`; // Instance flag // int $optionToBool[] = { 0, true, false }; int $i = `radioButtonGrp -query -select geometryTypeGroup`; optionVar -intValue duplicateSpecialCopy $optionToBool[$i]; // Group flag // optionVar -intValue duplicateSpecialGroup `radioButtonGrp -query -select otherOptionsGroup`; // Duplicate upstream nodes flag // optionVar -intValue duplicateSpecialUpstream `checkBoxGrp -query -value1 upstreamCheck`; // Duplicate input Connections flag // optionVar -intValue duplicateSpecialInputConn `checkBoxGrp -query -value1 inputConnCheck`; // Instance leaf shapes flag // optionVar -intValue duplicateSpecialInstanceLeaf `checkBoxGrp -query -value1 instanceLeafCheck`; // Translate values // optionVar -floatValue duplicateSpecialTX `floatFieldGrp -query -value1 transField`; optionVar -floatValue duplicateSpecialTY `floatFieldGrp -query -value2 transField`; optionVar -floatValue duplicateSpecialTZ `floatFieldGrp -query -value3 transField`; // Rotate values // optionVar -floatValue duplicateSpecialRX `floatFieldGrp -query -value1 rotateField`; optionVar -floatValue duplicateSpecialRY `floatFieldGrp -query -value2 rotateField`; optionVar -floatValue duplicateSpecialRZ `floatFieldGrp -query -value3 rotateField`; // Scale values // optionVar -floatValue duplicateSpecialSX `floatFieldGrp -query -value1 scaleField`; optionVar -floatValue duplicateSpecialSY `floatFieldGrp -query -value2 scaleField`; optionVar -floatValue duplicateSpecialSZ `floatFieldGrp -query -value3 scaleField`; if ($doIt) { performDuplicateSpecial 0; addToRecentCommandQueue "performDuplicateSpecial 0" "DuplicateSpecial"; } } // // Procedure Name: // duplicateSpecialOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc duplicateSpecialOptions () { // Name of the command for this option box. // string $cmdName = "duplicateSpecial"; // Build the option box actions. // string $callback = ($cmdName + "Callback"); string $setup = ($cmdName + "Setup"); // STEP 1: Get the option box. // ============================ // // 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; // STEP 2: Pass the command name to the option box. // ================================================= // // Any default option box behavior based on the command name is set // up with this call. For example, updating the 'Help' menu item with // the name of the command. // setOptionBoxCommandName($cmdName); // STEP 3: Activate the default UI template. // ========================================== // // 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; // STEP 4: Create option box contents. // =================================== // tabLayout -scrollable true -tabsVisible false; string $parent = `columnLayout -adjustableColumn 1`; string $instance = (uiRes("m_performDuplicateSpecial.kInstance")); radioButtonGrp -label (uiRes("m_performDuplicateSpecial.kGeometryType")) -numberOfRadioButtons 2 -label1 (uiRes("m_performDuplicateSpecial.kCopy")) -label2 $instance -vertical -changeCommand ("duplicateSpecialOptionsUpdateEnableState " + $parent) geometryTypeGroup; radioButtonGrp -numberOfRadioButtons 3 -label (uiRes("m_performDuplicateSpecial.kGroupunder")) -label1 (uiRes("m_performDuplicateSpecial.kParent")) -label2 (uiRes("m_performDuplicateSpecial.kWorld")) -label3 (uiRes("m_performDuplicateSpecial.kNewGroup")) -vertical -changeCommand ("duplicateSpecialOptionsUpdateEnableState " + $parent) otherOptionsGroup; separator; checkBoxGrp -numberOfCheckBoxes 1 -label1 (uiRes("m_performDuplicateSpecial.kSmartTransform")) -changeCommand ("duplicateSpecialOptionsUpdateEnableState " + $parent) smartCheck; floatFieldGrp -label (uiRes("m_performDuplicateSpecial.kTranslate")) -numberOfFields 3 transField; floatFieldGrp -label (uiRes("m_performDuplicateSpecial.kRotate")) -numberOfFields 3 rotateField; floatFieldGrp -label (uiRes("m_performDuplicateSpecial.kScale")) -numberOfFields 3 scaleField; intSliderGrp -label (uiRes("m_performDuplicateSpecial.kNumberofCopies")) -field true -minValue 1 -maxValue 100 -fieldMaxValue 1000 -changeCommand ("duplicateSpecialOptionsUpdateEnableState " + $parent) numDuplicatesField; separator; checkBoxGrp -numberOfCheckBoxes 1 -label1 (uiRes("m_performDuplicateSpecial.kDuplicateInputGraph")) -changeCommand ("duplicateSpecialOptionsUpdateEnableState " + $parent) upstreamCheck; checkBoxGrp -numberOfCheckBoxes 1 -label1 (uiRes("m_performDuplicateSpecial.kDuplicateInputConnections")) -changeCommand ("duplicateSpecialOptionsUpdateEnableState " + $parent) inputConnCheck; checkBoxGrp -numberOfCheckBoxes 1 -label1 (uiRes("m_performDuplicateSpecial.kInstanceLeafNodes")) -changeCommand ("duplicateSpecialOptionsUpdateEnableState " + $parent) instanceLeafCheck; separator; checkBoxGrp -numberOfCheckBoxes 1 -label1 (uiRes("m_performDuplicateSpecial.kAssignUniqueNametoChildrenNodes")) -value1 0 renameChildrenField; // Turn off the wait cursor. // waitCursor -state 0; // Step 5: Deactivate the default UI template. // =========================================== // setUITemplate -popTemplate; // Step 6: Customize the buttons. // ============================== // // Provide more descriptive labels for the buttons. // Disable those buttons that are not applicable to the option box. // Attach actions to those buttons that are applicable to the option // box. // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performDuplicateSpecial.kDuplicate")) -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_performDuplicateSpecial.kDuplicateOptions")); // Customize the 'Help' menu item text. // setOptionBoxHelpTag( "DuplicateSpecial" ); // Set the current values of the option box. // ========================================= // eval (($setup + " " + $parent + " " + 0)); // Show the option box. // ==================== // showOptionBox(); } // // Procedure Name: // duplicateSpecialHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string duplicateSpecialHelp() { return " Command: DuplicateSpecial - create a copy of selected objects.\n" + "Selection: objects."; } // // 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 = "duplicatePreset"; setOptionVars(false); int $count = `optionVar -query duplicateSpecialCount`; int $copy = `optionVar -query duplicateSpecialCopy`; int $group = `optionVar -query duplicateSpecialGroup`; int $smart = `optionVar -query duplicateSpecialSmart`; int $upstream = `optionVar -query duplicateSpecialUpstream`; int $inputConn = `optionVar -query duplicateSpecialInputConn`; int $renameChild = `optionVar -query duplicateSpecialRenameChildren`; int $instanceLeaf = `optionVar -query duplicateSpecialInstanceLeaf`; float $transX = `optionVar -query duplicateSpecialTX`; float $transY = `optionVar -query duplicateSpecialTY`; float $transZ = `optionVar -query duplicateSpecialTZ`; float $rotatX = `optionVar -query duplicateSpecialRX`; float $rotatY = `optionVar -query duplicateSpecialRY`; float $rotatZ = `optionVar -query duplicateSpecialRZ`; float $scaleX = `optionVar -query duplicateSpecialSX`; float $scaleY = `optionVar -query duplicateSpecialSY`; float $scaleZ = `optionVar -query duplicateSpecialSZ`; $cmd = ($cmd + "(" + $count + "," + $copy + "," + $group + "," + $smart + "," + $upstream + "," + $inputConn + "," + $renameChild + "," + $instanceLeaf + "," + $transX + "," + $transY + "," + $transZ + "," + $rotatX + "," + $rotatY + "," + $rotatZ + "," + $scaleX + "," + $scaleY + "," + $scaleZ + ")" ); return $cmd; } // // Procedure Name: // checkForClipDuplicate // // Description: // Determine if the duplicate command is coming from a trax panel. // // Input Arguments: // None. // // Return Value: // true if the clip specific duplicate should be involked, false otherwise. // proc int checkForClipDuplicate() { string $clips[] = `ls -selection -type animClip`; if (size($clips) == 0) { return false; } string $currentPanel = `getPanel -underPointer`; if( $currentPanel == "" ) { $currentPanel = `getPanel -withFocus`; } string $panelType = `getPanel -typeOf $currentPanel`; if( $panelType == "scriptedPanel" ) { $panelType = `scriptedPanel -query -type $currentPanel`; if ($panelType == "clipEditorPanel"){ return true; } } return false; } // // Procedure Name: // performDuplicateSpecial // // Description: // Perform the duplicate 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 duplicate command with the current // option box values. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // global proc string performDuplicateSpecial (int $action) { string $cmd = ""; if( $action == 0) { if ( checkForClipDuplicate() ) { return performDuplicateClip( $action, "" ); } } switch ($action) { // Execute the command. // case 0: // Get the command. // $cmd = `assembleCmd`; // Execute the command with the option settings. // // *NOTE* we do NOT want to use evalEcho here because // this calls the duplicatePreset command which does // the command echoing. // eval($cmd); break; // Show the option box. // case 1: duplicateSpecialOptions(); break; // Return the command string. // case 2: // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }