// =========================================================================== // 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 pasteKey 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) { // -t "10:20" // if ($forceFactorySettings || !`optionVar -exists pasteKeyRange`) { optionVar -stringValue pasteKeyRange "0:10"; } // -copies // if ($forceFactorySettings || !`optionVar -exists pasteKeyCopies`) { optionVar -intValue pasteKeyCopies 1; } // timeRangeOverride // if( $forceFactorySettings ||! `optionVar -exists pasteKeyTimeRangeOverride` ) { optionVar -intValue pasteKeyTimeRangeOverride 0; } // timeRange // if ($forceFactorySettings || !`optionVar -exists pasteKeyTargetTime`) { optionVar -intValue pasteKeyTargetTime 3; } // -options // if ($forceFactorySettings || !`optionVar -exists pasteKeyOption`) { optionVar -stringValue pasteKeyOption "merge"; } // help images // if ($forceFactorySettings || !`optionVar -exists pasteKeyHelpPictures`) { optionVar -intValue pasteKeyHelpPictures 0; } // Connect // if ($forceFactorySettings || !`optionVar -exists pasteKeyConnect`) { optionVar -intValue pasteKeyConnect 0; } // Time offset // if ($forceFactorySettings || !`optionVar -exists pasteKeyTimeOffset`) { optionVar -floatValue pasteKeyTimeOffset 0; } // Value offset // if ($forceFactorySettings || !`optionVar -exists pasteKeyValueOffset`) { optionVar -floatValue pasteKeyValueOffset 0; } } global proc pasteKeySetup (string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars ($forceFactorySettings); setParent $parent; // Do selected keys override the time range specified? // checkBoxGrp -edit -value1 `optionVar -q pasteKeyTimeRangeOverride` timeRangeOverride; // -time // int $whichTime = `optionVar -query pasteKeyTargetTime`; radioButtonGrp -edit -select $whichTime timeRange; floatFieldGrp -e -enable ($whichTime == 1 || $whichTime == 2) startTime; floatFieldGrp -e -enable ($whichTime == 2) endTime; string $time = `optionVar -query pasteKeyRange`; string $range[]; tokenize ($time, ":", $range); // Only one time // if( size( $range ) == 1 ) { floatFieldGrp -edit -value1 (float( $range[0] )) startTime; floatFieldGrp -edit -value1 (float( $range[0] )) endTime; } // A time range // else if( size( $range ) > 1 ) { floatFieldGrp -edit -value1 (float( $range[0] )) startTime; floatFieldGrp -edit -value1 (float( $range[1] )) endTime; } // -timeOffset // float $timeOffset = `optionVar -query pasteKeyTimeOffset`; floatFieldGrp -edit -value1 $timeOffset timeOffset; // -valueOffset // float $valueOffset = `optionVar -query pasteKeyValueOffset`; floatFieldGrp -edit -value1 $valueOffset valueOffset; // -copies // int $copies = `optionVar -query pasteKeyCopies`; intSliderGrp -e -value $copies copies; // -option // string $option = `optionVar -query pasteKeyOption`; // pasteInsert // if ($option == "insert") { radioButtonGrp -edit -select 1 adjustment; radioButtonGrp -edit -select 1 method; radioButtonGrp -edit -select 1 replace; } // scaleInsert else if ($option == "scaleInsert") { radioButtonGrp -edit -select 2 adjustment; radioButtonGrp -edit -select 1 method; radioButtonGrp -edit -select 1 replace; } // fitInsert else if ($option == "fitInsert") { radioButtonGrp -edit -select 3 adjustment; radioButtonGrp -edit -select 1 method; radioButtonGrp -edit -select 1 replace; } // pasteReplace else if ($option == "replace") { radioButtonGrp -edit -select 1 adjustment; radioButtonGrp -edit -select 2 method; radioButtonGrp -edit -select 1 replace; } // pasteReplaceCompletely else if ($option == "replaceCompletely") { radioButtonGrp -edit -select 1 adjustment; radioButtonGrp -edit -select 2 method; radioButtonGrp -edit -select 2 replace; } // scaleReplace else if ($option == "scaleReplace") { radioButtonGrp -edit -select 2 adjustment; radioButtonGrp -edit -select 2 method; radioButtonGrp -edit -select 1 replace; } // fitReplace else if ($option == "fitReplace") { radioButtonGrp -edit -select 3 adjustment; radioButtonGrp -edit -select 2 method; radioButtonGrp -edit -select 1 replace; } // pasteMerge else if ($option == "merge") { radioButtonGrp -edit -select 1 adjustment; radioButtonGrp -edit -select 3 method; radioButtonGrp -edit -select 1 replace; } // scaleMerge else if ($option == "scaleMerge") { radioButtonGrp -edit -select 2 adjustment; radioButtonGrp -edit -select 3 method; radioButtonGrp -edit -select 1 replace; } // fitMerge else if( $option == "fitMerge" ) { radioButtonGrp -edit -select 3 adjustment; radioButtonGrp -edit -select 3 method; radioButtonGrp -edit -select 1 replace; } // help images // int $pictures = `optionVar -q pasteKeyHelpPictures`; checkBoxGrp -e -value1 $pictures helpPictures; // connect // int $connect = `optionVar -q pasteKeyConnect`; checkBoxGrp -e -value1 $connect connect; updatePasteOptionsEnable; } global proc pasteKeyCallback (string $parent, int $doIt, string $selectionConnection, int $performAction, int $fromGraphEditor ) { setParent $parent; // Do selected keys override time range specified? // optionVar -intValue pasteKeyTimeRangeOverride `checkBoxGrp -q -value1 timeRangeOverride`; // -time // int $whichTime = `radioButtonGrp -query -select timeRange`; string $time = string (`floatFieldGrp -query -value1 startTime`) + ":" + string (`floatFieldGrp -query -value1 endTime`); optionVar -intValue pasteKeyTargetTime $whichTime; optionVar -stringValue pasteKeyRange $time; // -timeOffset float $timeOffset = `floatFieldGrp -query -value1 timeOffset`; optionVar -floatValue pasteKeyTimeOffset $timeOffset; // -valueOffset float $valueOffset = `floatFieldGrp -query -value1 valueOffset`; optionVar -floatValue pasteKeyValueOffset $valueOffset; // -copies // int $copies = `intSliderGrp -query -value copies`; optionVar -intValue pasteKeyCopies $copies; // -option // string $option = ""; int $selected = `radioButtonGrp -query -select adjustment`; if ($selected == 2) { $option = "scale"; } else if ($selected == 3) { $option = "fit"; } $selected = `radioButtonGrp -query -select method`; if ($selected == 1) { if( $option == "" ) { $option = $option + "insert"; } else { $option = $option + "Insert"; } } else if ($selected == 2) { if( $option == "" ) { $option = $option + "replace"; } else { $option = $option + "Replace"; } if( `radioButtonGrp -query -select replace` == 2 ) { $option = $option + "Completely"; } } else if ($selected == 3) { if( $option == "" ) { $option = $option + "merge"; } else { $option = $option + "Merge"; } } optionVar -stringValue pasteKeyOption $option; // help // int $pictures = `checkBoxGrp -query -value1 helpPictures`; optionVar -intValue pasteKeyHelpPictures $pictures; // connect // int $connect = `checkBoxGrp -q -value1 connect`; optionVar -intValue pasteKeyConnect $connect; if( $doIt ) { string $args[] = {(string) $performAction, $selectionConnection, $fromGraphEditor }; performPasteKeyArgList ("1", $args); string $tmpCmd = "performPasteKeyArgList 1 {"; $tmpCmd += "\"" + $performAction + "\", "; $tmpCmd += "\"" + $selectionConnection + "\", "; $tmpCmd += "\"" + $fromGraphEditor + "\"}"; addToRecentCommandQueue $tmpCmd "Paste Keys"; } } global proc pasteKeyHelpPictures () { int $doPictures = `checkBoxGrp -q -value1 helpPictures`; if( $doPictures == 0 ) { picture -e -visible no helpPicture; return; } int $adjustment = `radioButtonGrp -q -select adjustment`; int $method = `radioButtonGrp -q -select method`; int $connect = `checkBoxGrp -q -value1 connect`; int $isFromClipboard = (`radioButtonGrp -q -select timeRange` == 4); string $helpPicture = "CCPpaste"; if( $adjustment == 1 ) { if( $isFromClipboard ) { $helpPicture += "Clip"; } else { $helpPicture += "Preserve"; } } else if( $adjustment == 2 ) { $helpPicture += "Scale"; } else { $helpPicture += "Fit"; } if( $method == 1 ) { $helpPicture += "Insert"; } else if( $method == 2 ) { $helpPicture += "Replace"; if( $isFromClipboard ) { if( `radioButtonGrp -query -select replace` == 2 ) { $helpPicture += "Complete"; } else { $helpPicture += "Range"; } } } else { $helpPicture += "Merge"; } if(( $connect == 1 ) && ( `checkBoxGrp -q -enable connect` )) { $helpPicture += "Connect"; } $helpPicture += ".png"; picture -e -image (languageResourcePath($helpPicture)) -visible yes helpPicture; } global proc updatePasteOptionsEnable () { int $whichTimeRange = `radioButtonGrp -q -select timeRange`; int $isTimeRange = ($whichTimeRange == 2); // enable the ones that can accept time ranges // if( $isTimeRange ) { int $isPreserve = (`radioButtonGrp -q -select adjustment` == 1); radioButtonGrp -e -enable1 ( !$isTimeRange ) adjustment; radioButtonGrp -e -enable2 yes adjustment; radioButtonGrp -e -enable3 yes adjustment; // If we've disabled the "Preserve" option but it was selected, // select "Fit" instead. // if( $isPreserve && $isTimeRange ) { $isPreserve = false; radioButtonGrp -e -select 3 adjustment; } radioButtonGrp -e -enable1 (!$isPreserve) method; radioButtonGrp -e -enable2 yes method; radioButtonGrp -e -enable3 (!$isPreserve) method; if( $isPreserve ) { radioButtonGrp -e -select 2 method; } } // disable the ones that can't accept time ranges // else { int $isFromClipboard = (`radioButtonGrp -q -select timeRange` == 4); radioButtonGrp -e -enable1 yes -select 1 adjustment; radioButtonGrp -e -enable2 no adjustment; radioButtonGrp -e -enable3 no adjustment; radioButtonGrp -e -enable1 yes method; radioButtonGrp -e -enable2 $isFromClipboard method; radioButtonGrp -e -enable3 yes method; if(( $whichTimeRange != 0 ) && ( !$isFromClipboard ) && ( `radioButtonGrp -q -select method` == 2 )) { radioButtonGrp -e -select 1 method; } } // The replace option is enabled if the replace method is selected. // int $isReplaceMethod = (`radioButtonGrp -q -select method` == 2); int $enableReplaceCurve = ( !$isTimeRange && $isReplaceMethod ); radioButtonGrp -e -enable $isReplaceMethod replace; radioButtonGrp -e -enable2 $enableReplaceCurve replace; if( !$enableReplaceCurve && (`radioButtonGrp -q -select replace` == 2) ) { radioButtonGrp -e -select 1 replace; } // The connect option is only enabled when the method is NOT "Merge" // checkBoxGrp -edit -enable (`radioButtonGrp -q -select method` != 3) connect; pasteKeyHelpPictures; } proc string pasteKeyWidgets( string $tabLayout, int $fromGraphEditor ) { global int $gOptionBoxTextColumnWidthIndex; setParent $tabLayout; string $tabForm = `columnLayout -adjustableColumn true`; radioButtonGrp -numberOfRadioButtons 4 -label (uiRes("m_performPasteKeyArgList.kTimeRange")) -label1 (uiRes("m_performPasteKeyArgList.kStart")) -cc1 ("floatFieldGrp -e -enable true startTime; " + "floatFieldGrp -e -enable false endTime; " + "updatePasteOptionsEnable;") -label2 (uiRes("m_performPasteKeyArgList.kStartEnd")) -cc2 ("floatFieldGrp -e -enable true startTime; " + "floatFieldGrp -e -enable true endTime; " + "updatePasteOptionsEnable;") -label3 (uiRes("m_performPasteKeyArgList.kCurrent")) -cc3 ("floatFieldGrp -e -enable false startTime; " + "floatFieldGrp -e -enable false endTime; " + "updatePasteOptionsEnable;") -label4 (uiRes("m_performPasteKeyArgList.kClipboard")) -cc4 ("floatFieldGrp -e -enable false startTime; " + "floatFieldGrp -e -enable false endTime; " + "updatePasteOptionsEnable;") -cw 5 93 timeRange; frameLayout -bv no -lv no -collapsable yes -collapse (!$fromGraphEditor) timeRangeOverrideFrame; checkBoxGrp -ncb 1 -label "" -label1 (uiRes("m_performPasteKeyArgList.kSelectedKeysOverrideSpecified")) -adjustableColumn 2 timeRangeOverride; setParent ..; floatFieldGrp -label (uiRes("m_performPasteKeyArgList.kStartTime")) -value1 0.0 startTime; floatFieldGrp -label (uiRes("m_performPasteKeyArgList.kEndTime")) -value1 10.0 endTime; floatFieldGrp -label (uiRes("m_performPasteKeyArgList.kTimeOffset")) -value1 0.0 timeOffset; floatFieldGrp -label (uiRes("m_performPasteKeyArgList.kValueOffset")) -value1 0.0 valueOffset; intSliderGrp -label (uiRes("m_performPasteKeyArgList.kCopies")) -field true -min 1 -value 1 copies; separator; checkBoxGrp -label (uiRes("m_performPasteKeyArgList.kHelpImages")) -ncb 1 -value1 off -label1 "" -cc1 "pasteKeyHelpPictures;" helpPictures; radioButtonGrp -numberOfRadioButtons 3 -label (uiRes("m_performPasteKeyArgList.kClipboardAdjustment")) -label1 (uiRes("m_performPasteKeyArgList.kPreserve")) -cc1 "updatePasteOptionsEnable" -label2 (uiRes("m_performPasteKeyArgList.kScale")) -cc2 "updatePasteOptionsEnable" -label3 (uiRes("m_performPasteKeyArgList.kFit")) -cc3 "updatePasteOptionsEnable" adjustment; radioButtonGrp -numberOfRadioButtons 3 -label (uiRes("m_performPasteKeyArgList.kPasteMethod")) -label1 (uiRes("m_performPasteKeyArgList.kInsert")) -cc1 "updatePasteOptionsEnable" -label2 (uiRes("m_performPasteKeyArgList.kReplace")) -cc2 "updatePasteOptionsEnable" -label3 (uiRes("m_performPasteKeyArgList.kMerge")) -cc3 "updatePasteOptionsEnable" method; radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_performPasteKeyArgList.kReplaceRegion")) -label1 (uiRes("m_performPasteKeyArgList.kTimeRange2")) -cc1 "updatePasteOptionsEnable" -label2 (uiRes("m_performPasteKeyArgList.kEntireCurve")) -cc2 "updatePasteOptionsEnable" replace; checkBoxGrp -label (uiRes("m_performPasteKeyArgList.kConnect")) -label1 "" -cc1 "pasteKeyHelpPictures" connect; columnLayout -columnAttach "left" $gOptionBoxTextColumnWidthIndex; picture helpPicture; setParent ..; return $tabForm; } proc pasteKeyOptions( 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 = "pasteKey"; // Title for the option box window string $optionBoxTitle = (uiRes("m_performPasteKeyArgList.kPasteKeysOptions")); // Title for the apply button string $applyTitle = (uiRes("m_performPasteKeyArgList.kPasteKeys")); // 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. // pasteKeyWidgets $widgetList[2] $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 \"\" " + $performAction + " " + $fromGraphEditor + "; hideOptionBox()") $buttonList[3]; // Close // button -edit -command hideOptionBox $buttonList[2]; // Reset // button -edit -command ($setup + " " + $widgetList[2] + " true") $buttonList[1]; // DoIt // button -edit -command ($callback + " " + $widgetList[0] + " true \"" + $selectionConnection + "\" " + $performAction + " " + $fromGraphEditor) $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( "GraphPaste" ); } else if (match ("dopeSheet", $selectionConnection) != "") { setOptionBoxHelpTag( "DopePast" ); } else { setOptionBoxHelpTag( "KeysPasteKey" ); } // Selection changes. if( $fromGraphEditor ) { pasteKeyDoSelectionChanged($selectionConnection); scriptJob -protected -event "SelectionChanged" ("pasteKeyDoSelectionChanged " + $selectionConnection + ";") -parent $widgetList[2]; } // Call the setup "method" to fill in the current settings // eval (($setup + " " + $widgetList[2] + " false")); showOptionBox(); showWindow $widgetList[0]; } global proc pasteKeyDoSelectionChanged (string $selectionConnection) // // Description: // Since timeRange is irrelevant when there are // picked keyframes, collapse the timeRange // when there are. (This is hooked in to a SelectionChanged // trigger.) // { 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] startTime; floatFieldGrp -edit -value1 $region[1] endTime; } } } proc string assembleCmd( string $selectionConnection, string $options, int $fromGraphEditor ) { // doPasteKeyArgList takes a string array // $cmd = "doPasteKeyArgList 5 { " + "\"" + `optionVar -q pasteKeyRange` + "\"" + ",\"" + `optionVar -q pasteKeyCopies` + "\"" + ",\"" + `optionVar -q pasteKeyTargetTime` + "\"" + ",\"" + `optionVar -q pasteKeyOption` + "\"" ; string $option = `optionVar -q pasteKeyOption`; if (($option == "merge") || ($option == "scaleMerge") || ($option == "fitMerge")) { $cmd = $cmd + ", \"0\""; } else { $cmd = $cmd + ", \"" + `optionVar -q pasteKeyConnect` + "\""; } $cmd = $cmd + ", \"" + $selectionConnection + "\""; $cmd = $cmd + ", \"" + $options + "\""; $cmd = $cmd + ", \"" + $fromGraphEditor + "\""; $cmd = $cmd + ", \"" + `optionVar -query pasteKeyTimeOffset` + "\""; $cmd = $cmd + ", \"" + `optionVar -query pasteKeyValueOffset` + "\""; $cmd = $cmd + ", \"" + `optionVar -query pasteKeyTimeRangeOverride` + "\""; $cmd = $cmd + "};"; return $cmd; } global proc string performPasteKeyArgList (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, "noOptions", $fromGraphEditor ); eval( $cmd ); break; case 1: pasteKeyOptions( $selectionConnection, 0, $fromGraphEditor ); break; case 2: setOptionVars (false); $cmd = assembleCmd( $selectionConnection, "noOptions", $fromGraphEditor ); break; case 3: setOptionVars (false); $cmd = assembleCmd( $selectionConnection, "bufferCurve", $fromGraphEditor ); eval( $cmd ); break; case 4: pasteKeyOptions( $selectionConnection, 3, $fromGraphEditor ); break; case 5: setOptionVars (false); $cmd = assembleCmd( $selectionConnection, "bufferCurve", $fromGraphEditor ); break; } return ($cmd); }