// =========================================================================== // 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: 4 April 1997 // // Description: // This is a helper script to perform the 'snapshot' command // using the corresponding option box values. // // // 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) { // snapshotRange // if ($forceFactorySettings || !`optionVar -exists snapshotTSRange`) { optionVar -intValue snapshotTSRange 0; } // -startTime // if ($forceFactorySettings || !`optionVar -exists snapshotStartTime`) { optionVar -floatValue snapshotStartTime 1.0; } // -endTime // if ($forceFactorySettings || !`optionVar -exists snapshotEndTime`) { optionVar -floatValue snapshotEndTime 10.0; } // -increment // if ($forceFactorySettings || !`optionVar -exists snapshotByTime`) { optionVar -floatValue snapshotByTime 1.0; } // -forceUpdate // if ($forceFactorySettings || !`optionVar -exists snapshotForceUpdate`) { optionVar -intValue snapshotForceUpdate 0; } } // // Procedure Name: // snapshotEnabling // // Description: // Set the enable state of start and end time fields. // // Input Arguments: // parent - Top level parent layout of the option box UI. // Required so that object names of the fields can be // successfully resolved. // // state - Enable state of the fields. // // Return Value: // None. // global proc snapshotEnabling(string $parent, int $state) { setParent $parent; frameLayout -edit -enable $state snapshotStartEndFrame; } // // Procedure Name: // snapshotSetup // // 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 snapshotSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls. // snapshotRange // int $useTSRange = `optionVar -query snapshotTSRange`; if ($useTSRange == 1) radioButtonGrp -edit -select 2 snapshotTSRange; else radioButtonGrp -edit -select 1 snapshotTSRange; // -startTime // floatFieldGrp -edit -value1 `optionVar -query snapshotStartTime` snapshotStartTime; // -endTime // floatFieldGrp -edit -value1 `optionVar -query snapshotEndTime` snapshotEndTime; // -increment // floatFieldGrp -edit -value1 `optionVar -query snapshotByTime` snapshotByTime; // -forceUpdate // int $forceUpdate = `optionVar -query snapshotForceUpdate`; if (0 == $forceUpdate) { radioButtonGrp -edit -select 1 animCurveSnapshotUpdate; } else if (1 == $forceUpdate) { radioButtonGrp -edit -select 1 forceSnapshotUpdate; } else { radioButtonGrp -edit -select 1 demandSnapshotUpdate; } // Set the enable state of the start and end time fields. // snapshotEnabling $parent (!$useTSRange); } // // Procedure Name: // snapshotCallback // // 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 snapshotCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then // perform the command. // snapshotRange // if (`radioButtonGrp -query -select snapshotTSRange` == 2) optionVar -intValue snapshotTSRange 1; else optionVar -intValue snapshotTSRange 0; // -startTime // optionVar -floatValue snapshotStartTime `floatFieldGrp -query -value1 snapshotStartTime`; // -endTime // optionVar -floatValue snapshotEndTime `floatFieldGrp -query -value1 snapshotEndTime`; // -increment // optionVar -floatValue snapshotByTime `floatFieldGrp -query -value1 snapshotByTime`; // -forceUpdate // if (`radioButtonGrp -query -select forceSnapshotUpdate`) { optionVar -intValue snapshotForceUpdate 1; } else if (`radioButtonGrp -query -select demandSnapshotUpdate`) { optionVar -intValue snapshotForceUpdate 2; } else { optionVar -intValue snapshotForceUpdate 0; } if ($doIt) { performSnapshot 0; addToRecentCommandQueue "performSnapshot 0" "Snapshot"; } } // // Procedure Name: // snapshotOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc snapshotOptions() { // Name of the command for this option box. // string $commandName = "snapshot"; // Build the option box actions. // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); // 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; // Pass the command name to the option box. // // Any default option box behaviour based on the command name is set // up with this call. // setOptionBoxCommandName($commandName); // 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; // RECOMMENDATION: Place the UI in a scroll layout. If the // option box window is ever resized such that it's entire // contents is not visible then the scroll bars provided by the // scroll layout will allow the user to access the hidden UI. // tabLayout -tabsVisible false -scrollable true; string $parent = `columnLayout -adjustableColumn 1`; // RECOMMENDATION: Use the 'Grp' commands where possible because // they obey the formatting specified in the default template. // This will result in a more consistent look throughout the // application. // radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_performSnapshot.kTimeRange")) -label1 (uiRes("m_performSnapshot.kStartEnd")) -label2 (localizedUIComponentLabel("Time Slider")) -changeCommand1 ("snapshotEnabling " + $parent + " #1") snapshotTSRange; frameLayout -borderVisible false -labelVisible false -collapsable true -collapse false snapshotStartEndFrame; columnLayout -adjustableColumn true; floatFieldGrp -label (uiRes("m_performSnapshot.kStartTime")) snapshotStartTime; floatFieldGrp -label (uiRes("m_performSnapshot.kEndTime")) snapshotEndTime; setParent ..; setParent ..; floatFieldGrp -label (uiRes("m_performSnapshot.kIncrement")) snapshotByTime; radioButtonGrp -numberOfRadioButtons 1 -label (uiRes("m_performSnapshot.kUpdate")) -label1 (uiRes("m_performSnapshot.kOnDemand")) demandSnapshotUpdate; radioButtonGrp -numberOfRadioButtons 1 -label1 (uiRes("m_performSnapshot.kFast")) -shareCollection demandSnapshotUpdate animCurveSnapshotUpdate; radioButtonGrp -numberOfRadioButtons 1 -label1 (uiRes("m_performSnapshot.kSlow")) -shareCollection demandSnapshotUpdate forceSnapshotUpdate; // Turn off the wait cursor. // waitCursor -state 0; // Deactivate the default UI template. // setUITemplate -popTemplate; // Attach actions to those buttons that are applicable to the option // box. Note that the 'Close' button has a default action attached // to it that will hide the window. If a a custom action is // attached to the 'Close' button then be sure to call the 'hide the // option box' procedure within the custom action so that the option // box is hidden properly. // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performSnapshot.kSnapshot")) -command ($callback + " " + $parent + " " + 1) $applyBtn; dimWhen -false "SomethingSelected" $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_performSnapshot.kAnimSnapshotOptions"))); // Customize the 'Help' menu item text. // setOptionBoxHelpTag( "CreateAnimationSnapshot" ); // Set the current values of the option box. // eval (($setup + " " + $parent + " " + 0)); // Show the option box. // showOptionBox(); } // // 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; setOptionVars(false); $cmd = "snapshot " + " -increment " + `optionVar -query snapshotByTime` + " -constructionHistory " + `constructionHistory -query -toggle`; string $updateStyle = "demand"; if (`optionVar -query snapshotForceUpdate` == 0) { $updateStyle = "animCurve"; } else if (`optionVar -query snapshotForceUpdate` == 1) { $updateStyle = "force"; } if (`optionVar -query snapshotTSRange` == 1) { // Note that we're embedding the time slider query into the string, // because if dragged to the shelf with the "Time Slider" option, // we want to re-evaluate what the current time slider range is // each time it is invoked form the shelf. // $cmd = ($cmd + " -startTime `playbackOptions -query -min`" + " -endTime `playbackOptions -query -max`"); } else { float $minTime = `optionVar -query snapshotStartTime`; float $maxTime = `optionVar -query snapshotEndTime`; $cmd = ($cmd + " -startTime " + $minTime + " -endTime " + $maxTime); } $cmd += (" -update "+$updateStyle); if ($updateStyle == "demand") { $cmd += "; updateMotionTrail;"; } return $cmd; } // // Procedure Name: // performSnapshot // // Description: // Perform the 'snapshot' 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 'snapshot' command with the current // option box values. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // // Return Value: // None. // global proc string performSnapshot(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: // Retrieve the option settings // setOptionVars(false); // Get the command. // $cmd = `assembleCmd`; // Execute the command with the option settings. // evalEcho($cmd); break; // Show the option box. // case 1: snapshotOptions; break; // Return the command string. // case 2: // Retrieve the option settings. // setOptionVars (false); // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }