// =========================================================================== // 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: August 14, 1996 // // Description: // This is a helper script to perfrom the copyKey command // using the various options that have been set // // Input Arguments: // int action 0 - just execute the command // 1 - show the option box dialog // 2 - return the drag command // // Return Value: // None. // proc setOptionVars (int $forceFactorySettings) { keySetOptionBoxCommon( { "copyKey", "unknown", "setOptionVars", $forceFactorySettings } ); // -options // if ($forceFactorySettings || !`optionVar -exists copyKeyOption`) { optionVar -stringValue copyKeyOption "keys"; } // help images // if ($forceFactorySettings || !`optionVar -exists copyKeyHelpPictures`) { optionVar -intValue copyKeyHelpPictures 0; } } global proc copyKeySetup (string $parent, string $selectionConnection, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars ($forceFactorySettings); setParent $parent; keySetOptionBoxCommon( { "copyKey", $selectionConnection, "setup" } ); // -option // string $option = `optionVar -query copyKeyOption`; if ($option == "keys") { radioButtonGrp -edit -select 1 method; } else { radioButtonGrp -edit -select 2 method; } // help images // int $pictures = `optionVar -q copyKeyHelpPictures`; checkBoxGrp -e -value1 $pictures helpPictures; // Now get all the dependent widgets in the right // enabled/disabled/collapsed/expanded state // copyKeyWidgetsEnable ($selectionConnection); copyKeyHelpPictures; } global proc copyKeyCallback(string $parent, int $doIt, string $selectionConnection, int $fromGraphEditor, int $performAction ) { setParent $parent; keySetOptionBoxCommon( { "copyKey", $selectionConnection, "callback" } ); // -option string $option; if (`radioButtonGrp -query -select method` == 1) { $option = "keys"; } else if (`radioButtonGrp -query -select method` == 2) { $option = "curve"; } else { $option = "area"; } optionVar -stringValue copyKeyOption $option; // help // int $pictures = `checkBoxGrp -query -value1 helpPictures`; optionVar -intValue copyKeyHelpPictures $pictures; if( $doIt ) { string $args[] = { (string) $performAction, $selectionConnection, (string) $fromGraphEditor }; performCopyKeyArgList 1 $args; string $tmpCmd = "performCopyKeyArgList 1 {\"" + $performAction + "\", \""; $tmpCmd += $selectionConnection + "\", \""; $tmpCmd += $fromGraphEditor + "\"}"; addToRecentCommandQueue $tmpCmd "Copy Keys"; } } global proc copyKeyHelpPictures () { int $doPictures = `checkBoxGrp -q -value1 helpPictures`; if( $doPictures == 0 ) { frameLayout -e -collapse yes methodPictureFrame; return; } int $method = `radioButtonGrp -q -select method`; string $methodPicture; if( $method == 1 ) { $methodPicture = "CCPkeyframesOnly.png"; } else if ( $method == 2 ) { $methodPicture = "CCPcurveExact.png"; } else { $methodPicture = "CCPregionExact.png"; } picture -e -image (languageResourcePath($methodPicture)) methodPicture; frameLayout -e -collapse no methodPictureFrame; } global proc copyKeyDoSelectionChanged (string $selectionConnection) // // Description: // Since timeRange is irrelevant when there are // picked keyframes, collapse the timeRangeFrame // when there are. (This is hooked in to a SelectionChanged // trigger.) // { keySetOptionBoxCommon( { "copyKey", $selectionConnection, "selectionChanged" } ); if (match ("dopeSheet", $selectionConnection) != "") { string $currentPanel = `getPanel -withFocus`; string $dopeSheet = $currentPanel + "DopeSheetEd"; float $region[] = `dopeSheetEditor -q -sel $dopeSheet`; if ($region[0] < $region[1] && $region[2] < $region[3] ) { floatFieldGrp -edit -value1 $region[0] frameStart; floatFieldGrp -edit -value1 $region[1] frameEnd; keySetOptionBoxCommon( { "copyKey", $selectionConnection, "callback" } ); } } else { if( `keyframe -q -sl -kc` > 0) { radioButtonGrp -e -enable2 false -select 1 method; } else { // Only enable the radioButtonGrp if the frame is enabled, otherwise // this proc will interfere with the copyKeyWidgetsEnable proc // if (`frameLayout -q -enable optionsFrame` == 1) { radioButtonGrp -e -enable2 true method; } } } } global proc copyKeyWidgetsEnable (string $selectionConnection) // // Description: // These are the widgets that get enabled and // disabled based on the certain states. Put them // here so they're all in one place. // { keySetOptionBoxCommon( { "copyKey", $selectionConnection, "enable" } ); // Options frame // int $enableIt = ( `radioButtonGrp -q -select timeRange` != 1 ); frameLayout -e -enable $enableIt optionsFrame; } proc string copyKeyWidgets( string $tabLayout, string $selectionConnection, int $fromGraphEditor ) { global int $gOptionBoxTextColumnWidthIndex; setParent $tabLayout; string $tabForm = `columnLayout -adjustableColumn true`; keySetOptionBoxCommon( { "copyKey", $selectionConnection, "widgets", $fromGraphEditor } ); frameLayout -bv no -lv no -collapsable no optionsFrame; columnLayout -adjustableColumn true; checkBoxGrp -label (uiRes("m_performCopyKeyArgList.kHelpImages")) -ncb 1 -value1 off -label1 "" -cc1 "copyKeyHelpPictures;" helpPictures; radioButtonGrp -numberOfRadioButtons 3 -label (uiRes("m_performCopyKeyArgList.kMethod")) -label1 (uiRes("m_performCopyKeyArgList.kKeys")) -cc1 "copyKeyHelpPictures" -label2 (uiRes("m_performCopyKeyArgList.kSegments")) -cc2 "copyKeyHelpPictures" -label3 (uiRes("m_performCopyKeyArgList.kRange")) -cc3 "copyKeyHelpPictures" method; frameLayout -bv no -lv no -collapsable yes -collapse yes methodPictureFrame; columnLayout -columnAttach "left" $gOptionBoxTextColumnWidthIndex; picture methodPicture; setParent ..; setParent ..; setParent ..; setParent ..; return $tabForm; } proc copyKeyOptions( string $selectionConnection, int $performAction, int $fromGraphEditor ) { // Customisation options // // Name of the command for this option box (think of it as the base class) string $commandName = "copyKey"; // Title for the option box window string $optionBoxTitle = (uiRes("m_performCopyKeyArgList.kCopyKeysOptions")); // Title for the apply button string $applyTitle = (uiRes("m_performCopyKeyArgList.kCopyKeys")); // Build the option box "methods" // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); // Build the window, with a tab layout // string $widgetList[] = `getStandardWindow $optionBoxTitle 0 "noOptions"`; setUITemplate -pushTemplate DefaultTemplate; // Make the form invisible while we create the widgets in the window // formLayout -e -vis false $widgetList[1]; // Attach the widgets. No tab layout needed. // copyKeyWidgets $widgetList[2] $selectionConnection $fromGraphEditor; // Attach the standard buttons // string $buttonList[] = `addStandardButtons $commandName $applyTitle $widgetList[1] $widgetList[2] "noOptions"`; // attach commands to the standard buttons // // Save // button -e -c ($callback + " " + $widgetList[0] + " false \"\" " + $fromGraphEditor + " " + $performAction + "; hideOptionBox()") $buttonList[3]; // Close // button -edit -command hideOptionBox $buttonList[2]; // Reset // button -edit -command ($setup + " " + $widgetList[2] + " " + $selectionConnection + " true") $buttonList[1]; // DoIt // button -edit -command ($callback + " " + $widgetList[0] + " true \"" + $selectionConnection + "\" " + $fromGraphEditor + " " + $performAction) $buttonList[0]; // Make the form layout visible so we can see what we built, and // reset the template // formLayout -e -vis true $widgetList[1]; setUITemplate -popTemplate; // Customize the 'Help' menu item text. // This is called from 3 different places so look at the selection // connection to try to figure out which one. // if (match ("graphEditor", $selectionConnection) != "") { setOptionBoxHelpTag( "GraphCopy" ); } else if (match ("dopeSheet", $selectionConnection) != "") { setOptionBoxHelpTag( "DopeCopy" ); } else { setOptionBoxHelpTag( "KeysCopyKeys" ); } // Call the setup "method" to fill in the current settings // eval (($setup + " " + $widgetList[2] + " " + $selectionConnection + " false")); showOptionBox(); showWindow $widgetList[0]; if( $fromGraphEditor ) { copyKeyDoSelectionChanged($selectionConnection); scriptJob -protected -event "SelectionChanged" ("copyKeyDoSelectionChanged " + $selectionConnection) -parent $widgetList[2]; } } proc string assembleCmd( string $selectionConnection, int $fromGraphEditor, string $options ) { // doCopyKeyArgList takes a string array // string $cmd = "doCopyKeyArgList 3 { " + "\"" + `optionVar -q copyKeyWhichRange` + "\"" + ",\"" + `optionVar -q copyKeyRange` + "\"" + ",\"" + `optionVar -q copyKeyOption` + "\"" + ",\"" + `optionVar -q copyKeyHierarchy` + "\"" + ",\"" + `optionVar -q copyKeyControlPoints` + "\"" + ",\"" + `optionVar -q copyKeyShapes` + "\"" + ",\"" + `optionVar -q copyKeyUseChannelBox` + "\"" + ",\"" + $selectionConnection + "\"" + ",\"" + $options + "\"" + ",\"" + $fromGraphEditor + "\"" + ",\"" + `optionVar -q copyKeyDriven` + "\"" + " };"; return $cmd; } global proc string performCopyKeyArgList (string $version, string $args[]) // // Input Arguments: // $version: The version of this option box. Used to know how to // interpret the $args array. // "1" : $action, $selectionConnection, $fromGraphEditor // // $args // Version 1 // [0] $action 0 - do the command // 1 - show the option box // 2 - return the drag command // 3 - do the command (bufferCurve version) // 4 - show the option box (bufferCurve version) // 5 - return the drag command (bufferCurve version) // [1] $selectionConnection name of selection connection to use // unless $options has "bufferCurve" in which // case this is the name of the editor // [2] $fromGraphEditor true if being called from the graph editor // // Return Value: // The actual command to execute. // { int $versionNum = $version; int $action = $args[0]; string $selectionConnection = $args[1]; int $fromGraphEditor = $args[2]; string $cmd = ""; switch( $action ) { case 0: setOptionVars( false ); $cmd = assembleCmd( $selectionConnection, $fromGraphEditor, "noOptions" ); eval( $cmd ); break; case 1: copyKeyOptions( $selectionConnection, 0, $fromGraphEditor ); break; case 2: setOptionVars( false ); $cmd = assembleCmd( $selectionConnection, $fromGraphEditor, "noOptions" ); break; case 3: setOptionVars( false ); $cmd = assembleCmd( $selectionConnection, $fromGraphEditor, "bufferCurve" ); eval( $cmd ); break; case 4: copyKeyOptions( $selectionConnection, 3, $fromGraphEditor ); break; case 5: setOptionVars( false ); $cmd = assembleCmd( $selectionConnection, $fromGraphEditor, "bufferCurve" ); break; } return ($cmd); }