// =========================================================================== // 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 9, 2017 // // Description: // This is a helper script to perform the filterCurve -f keySync // 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( { "keySync", "unknown", "setOptionVars", $forceFactorySettings } ); // Override default WhichRange to 4 (Selection) // time range: 1: all, 2: playbackRange, 3: start/end, 4: selection if( $forceFactorySettings || !`optionVar -exists keySyncWhichRange` ) { optionVar -intValue keySyncWhichRange 4; } } global proc keySyncSetup (string $parent, string $selectionConnection, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars ($forceFactorySettings); setParent $parent; keySetOptionBoxCommon( { "keySync", $selectionConnection, "setup", 0 } ); keySyncWidgetsEnable ($selectionConnection); } global proc keySyncCallback( string $parent, int $doIt, string $selectionConnection, int $performAction ) { setParent $parent; keySetOptionBoxCommon( { "keySync", $selectionConnection, "callback" } ); if( $doIt ) { performKeySync( $performAction, $selectionConnection); string $tmpCmd = "performKeySync "; $tmpCmd += "\"" + $performAction + "\", "; $tmpCmd += "\"" + $selectionConnection + "\""; addToRecentCommandQueue $tmpCmd "KeySync"; } } global proc keySyncWidgetsEnable(string $selectionConnection) { keySetOptionBoxCommon( { "keySync", $selectionConnection, "enable" } ); } proc string keySyncWidgets( string $tabLayout, string $selectionConnection ) { setParent $tabLayout; string $tabForm = `columnLayout -adjustableColumn true`; keySetOptionBoxCommon( { "keySync", $selectionConnection, "widgets", 1, 0, 1, 1, 1 } ); return $tabForm; } global proc keySyncDoSelectionChanged(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.) // { keySetOptionBoxCommon( { "keySync", $selectionConnection, "selectionChanged" } ); keySyncWidgetsEnable ($selectionConnection); } proc keySyncOptions( string $selectionConnection, int $performAction ) { // Customisation options // // Name of the command for this option box (think of it as the base class) string $commandName = "keySync"; // Title for the option box window string $optionBoxTitle = (uiRes("m_performKeySync.kKeySyncCurveOptions")); // Title for the apply button string $applyTitle = (uiRes("m_performKeySync.kApplyAndClose")); // 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 each tab // keySyncWidgets $widgetList[2] $selectionConnection; // 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 + "; hideOptionBox()") $buttonList[3]; // Close // button -edit -label (uiRes("m_performKeySync.kCancel")) -command hideOptionBox $buttonList[2]; // Reset // button -edit -command ($setup + " " + $widgetList[0] + " " + $selectionConnection + " true") $buttonList[1]; // Do It // button -edit -command ($callback + " " + $widgetList[0] + " true \"" + $selectionConnection + "\"" + $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( "GraphKeySyncCurve" ); } else if (match ("dopeSheet", $selectionConnection) != "") { setOptionBoxHelpTag( "DopeKeySyncCurve" ); } else { setOptionBoxHelpTag( "" ); } // Call the setup "method" to fill in the current settings // eval (($setup + " " + $widgetList[0] + " " + $selectionConnection + " false")); showOptionBox(); showWindow $widgetList[0]; keySyncDoSelectionChanged($selectionConnection); scriptJob -protected -event "SelectionChanged" ("keySyncDoSelectionChanged " + $selectionConnection) -parent $widgetList[2]; } proc string assembleCmd( string $selectionConnection, string $options ) { string $cmd = "doKeySyncArgList 1 { " + "\"" + `optionVar -q keySyncWhichRange` + "\"" + ",\"" + `optionVar -q keySyncRange` + "\"" + ",\"" + $selectionConnection + "\"" + ",\"" + $options + "\"" + " };"; return $cmd; } // The action variable means // 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) global proc string performKeySync( int $action, string $selectionConnection ) { string $cmd = ""; switch( $action ) { case 0: setOptionVars( false ); $cmd = assembleCmd( $selectionConnection, "noOptions" ); eval( $cmd ); break; case 1: keySyncOptions( $selectionConnection, 0 ); break; case 2: setOptionVars( false ); $cmd = assembleCmd( $selectionConnection, "noOptions" ); break; case 3: setOptionVars( false ); $cmd = assembleCmd( $selectionConnection, "bufferCurve" ); eval( $cmd ); break; case 4: keySyncOptions( $selectionConnection, 3 ); break; case 5: setOptionVars( false ); $cmd = assembleCmd( $selectionConnection, "bufferCurve" ); break; } return ($cmd); }