// =========================================================================== // 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: Nov 3 98 // // Description: // This is a helper script to perfrom the snapKey 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( { "snapKey", "unknown", "setOptionVars", $forceFactorySettings, 1 } ); // snapKey time or value? // if ($forceFactorySettings || !`optionVar -exists snapKeyTimeValue`) { optionVar -intValue snapKeyTimeValue 1; } // snapKey time multiple // if ($forceFactorySettings || !`optionVar -exists snapKeyTimeMultiple`) { optionVar -floatValue snapKeyTimeMultiple 1.0; } // snapKey value multiple // if ($forceFactorySettings || !`optionVar -exists snapKeyValueMultiple`) { optionVar -floatValue snapKeyValueMultiple 1.0; } } global proc snapKeySetup (string $parent, string $selectionConnection, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars ($forceFactorySettings); setParent $parent; keySetOptionBoxCommon( { "snapKey", $selectionConnection, "setup", 1 } ); // snap key time or value? // int $snapTimeValue = `optionVar -query snapKeyTimeValue`; radioButtonGrp -edit -select $snapTimeValue snapTimeValue; // snap time multiple // float $snapToTime = `optionVar -query snapKeyTimeMultiple`; floatFieldGrp -edit -value1 $snapToTime snapToTime; // snap value multiple // float $snapToValue = `optionVar -query snapKeyValueMultiple`; floatFieldGrp -edit -value1 $snapToValue snapToValue; // Now get all the dependent widgets in the right // enabled/disabled/collapsed/expanded state // snapKeyWidgetsEnable ($selectionConnection); } global proc snapKeyCallback( string $parent, int $doIt, string $selectionConnection, int $performAction, int $fromGraphEditor ) { setParent $parent; keySetOptionBoxCommon( { "snapKey", $selectionConnection, "callback" } ); // snap time or value? // optionVar -intValue snapKeyTimeValue `radioButtonGrp -q -sl snapTimeValue`; // time multiple // optionVar -floatValue snapKeyTimeMultiple `floatFieldGrp -q -value1 snapToTime`; // value multiple // optionVar -floatValue snapKeyValueMultiple `floatFieldGrp -q -value1 snapToValue`; if( $doIt ) { performSnapKeyArgList( 1, { (string) $performAction, $selectionConnection, $fromGraphEditor } ); string $tmpCmd = "performSnapKeyArgList 1 {"; $tmpCmd += "\"" + $performAction + "\", "; $tmpCmd += "\"" + $selectionConnection + "\", "; $tmpCmd += "\"" + $fromGraphEditor + "\"}"; addToRecentCommandQueue $tmpCmd "Snap Keys"; } } global proc snapKeyDoSelectionChanged (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( { "snapKey", $selectionConnection, "selectionChanged" } ); } global proc snapKeyWidgetsEnable (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( { "snapKey", $selectionConnection, "enable" } ); // Time/Value multiple fields // $doTimeValue = `radioButtonGrp -q -select snapTimeValue`; floatFieldGrp -e -enable ( $doTimeValue != 2 ) snapToTime; floatFieldGrp -e -enable ( $doTimeValue != 1 ) snapToValue; } proc string snapKeyWidgets( string $tabLayout, string $selectionConnection, int $fromGraphEditor ) { global int $gTextColumnWidthIndex; setParent $tabLayout; string $tabForm = `columnLayout -adjustableColumn true`; keySetOptionBoxCommon( { "snapKey", $selectionConnection, "widgets", $fromGraphEditor, 1 } ); radioButtonGrp -nrb 3 -label (uiRes("m_performSnapKeyArgList.kSnap")) -label1 (uiRes("m_performSnapKeyArgList.kTimes")) -label2 (uiRes("m_performSnapKeyArgList.kValues")) -label3 (uiRes("m_performSnapKeyArgList.kBoth")) -sl 1 -changeCommand ("snapKeyWidgetsEnable " + $selectionConnection) snapTimeValue; floatFieldGrp -label (uiRes("m_performSnapKeyArgList.kSnapTimestoMultipleof")) -value1 1.0 snapToTime; floatFieldGrp -label (uiRes("m_performSnapKeyArgList.kSnapValuestoMultipleof")) -value1 1.0 snapToValue; setParent ..; return $tabForm; } proc snapKeyOptions( 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 = "snapKey"; // Title for the option box window string $optionBoxTitle; string $applyTitle; $optionBoxTitle = (uiRes("m_performSnapKeyArgList.kSnapKeysOptions")); $applyTitle = (uiRes("m_performSnapKeyArgList.kSnapKeys")); // 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. // snapKeyWidgets $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 \"\" " + $performAction + " " + $fromGraphEditor + "; 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 + "\" " + $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( "GraphSnap" ); } else if (match ("dopeSheet", $selectionConnection) != "") { setOptionBoxHelpTag( "DopeSnap" ); } else { setOptionBoxHelpTag( "KeysSnapKeys" ); } // Call the setup "method" to fill in the current settings // eval (($setup + " " + $widgetList[2] + " " + $selectionConnection + " false")); showOptionBox(); showWindow $widgetList[0]; if( $fromGraphEditor ) { snapKeyDoSelectionChanged($selectionConnection); scriptJob -protected -event "SelectionChanged" ("snapKeyDoSelectionChanged " + $selectionConnection + "; snapKeyWidgetsEnable " + $selectionConnection + ";") -parent $widgetList[2]; } } proc string assembleCmd( string $selectionConnection, string $options, string $doSelectNotSnap, int $fromGraphEditor ) { int $snapTimeValue = `optionVar -q snapKeyTimeValue`; int $snapTime = $snapTimeValue != 2; int $snapValue = $snapTimeValue != 1; // doSnapKeyArgList takes a string array // $cmd = "doSnapKeyArgList 1 { " + "\"" + `optionVar -q snapKeyAllAnimCurves` + "\"" + ",\"" + `optionVar -q snapKeyHierarchy` + "\"" + ",\"" + `optionVar -q snapKeyUseChannelBox` + "\"" + ",\"" + `optionVar -q snapKeyDriven` + "\"" + ",\"" + `optionVar -q snapKeyControlPoints` + "\"" + ",\"" + `optionVar -q snapKeyShapes` + "\"" + ",\"" + `optionVar -q snapKeyWhichRange` + "\"" + ",\"" + `optionVar -q snapKeyRange` + "\"" + ",\"" + $snapTime + "\"" + ",\"" + $snapValue + "\"" + ",\"" + `optionVar -q snapKeyTimeMultiple` + "\"" + ",\"" + `optionVar -q snapKeyValueMultiple` + "\"" + ",\"" + $doSelectNotSnap + "\"" + ",\"" + $selectionConnection + "\"" + ",\"" + $options + "\"" + ",\"" + $fromGraphEditor + "\"" + " };"; return $cmd; } // $version == 1 // [0] $action 0 - do the command // 1 - show the option box // 2 - return the drag command // 3 - do the command (bufferCurve vers.) // 4 - show the option box (bufferCurve vers.) // 5 - return the drag command (bufferCurve vers.) // 6 - do the "selectKey -unsnappedKeys" command // associated with the snapKey option settings // 7 - return the "selectKey -unsnappedKeys" cmd // associated with the snapKey option // settings // [1] $selectionConnection name of selection connection to use // [2] $fromGraphEditor true if called from GraphEditor/DopeSheet // global proc string performSnapKeyArgList( int $version, string $args[] ) { int $action = $args[0]; string $selectionConnection = $args[1]; int $fromGraphEditor = $args[2]; string $cmd = ""; switch( $action ) { // Snap Key From Edit->Keys menu // case 0: setOptionVars( false ); $cmd = assembleCmd ($selectionConnection, "noOptions", 0, $fromGraphEditor); eval( $cmd ); break; case 1: snapKeyOptions( $selectionConnection, 0, $fromGraphEditor ); break; case 2: setOptionVars( false ); $cmd = assembleCmd ($selectionConnection, "noOptions", 0, $fromGraphEditor); break; // Snap Key From GE/DS Edit menu // case 3: setOptionVars( false ); $cmd = assembleCmd ($selectionConnection, "bufferCurve", 0, $fromGraphEditor); eval( $cmd ); break; case 4: snapKeyOptions( $selectionConnection, 3, $fromGraphEditor ); break; case 5: setOptionVars( false ); $cmd = assembleCmd ($selectionConnection, "bufferCurve", 0, $fromGraphEditor); break; // Select Unsnapped from GE/DS menu uses the optionVars // from snapKey. // case 6: setOptionVars( false ); $cmd = assembleCmd ($selectionConnection, "bufferCurve", 1, $fromGraphEditor); eval( $cmd ); break; case 7: setOptionVars( false ); $cmd = assembleCmd ($selectionConnection, "bufferCurve", 1, $fromGraphEditor); break; } return ($cmd); }