// =========================================================================== // 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: Oct, 2000 // // Description: // This is a helper script to perform the 'motionTrail' command // to create a motion trail 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) { // motionTrailRange // if ($forceFactorySettings || !`optionVar -exists motionTrailTSRange`) { optionVar -intValue motionTrailTSRange 1; } // -startTime // if ($forceFactorySettings || !`optionVar -exists motionTrailStartTime`) { optionVar -floatValue motionTrailStartTime 1.0; } // -endTime // if ($forceFactorySettings || !`optionVar -exists motionTrailEndTime`) { optionVar -floatValue motionTrailEndTime 10.0; } // -increment // if ($forceFactorySettings || !`optionVar -exists motionTrailByTime`) { optionVar -floatValue motionTrailByTime 1.0; } // -forceUpdate (obsolete) // if (`optionVar -exists motionTrailForceUpdate`) { optionVar -remove motionTrailForceUpdate; } // Draw Style (obsolete) // if (`optionVar -exists motionTrailDrawStyle`) { optionVar -remove motionTrailDrawStyle; } // Display Frames // if ($forceFactorySettings || !`optionVar -exists motionTrailFrames`) { optionVar -intValue motionTrailFrames 1; } // Anchor Transform // if ($forceFactorySettings || !`optionVar -exists motionTrailAnchorTransform`) { optionVar -intValue motionTrailAnchorTransform 0; } // Pre and Post Frames // if ($forceFactorySettings || !`optionVar -exists motionTrailPre`) { optionVar -floatValue motionTrailPre 0; } if ($forceFactorySettings || !`optionVar -exists motionTrailPost`) { optionVar -floatValue motionTrailPost 0; } // Trail thickness // if ($forceFactorySettings || !`optionVar -exists motionTrailThickness`) { optionVar -floatValue motionTrailThickness 1.0; } // Keyframe size // if ($forceFactorySettings || !`optionVar -exists motionTrailKeySize`) { optionVar -floatValue motionTrailKeySize 1.0; } // Pinned // if ($forceFactorySettings || !`optionVar -exists motionTrailPin`) { optionVar -intValue motionTrailPin 1; } // Allow no keys // if ($forceFactorySettings || !`optionVar -exists motionTrailAllowNoKeys`) { optionVar -intValue motionTrailAllowNoKeys 1; } } // // Procedure Name: // motionTrailEnabling // // 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 motionTrailEnabling(string $parent, int $state) { setParent $parent; frameLayout -edit -enable $state motionTrailStartEndFrame; } // // Procedure Name: // motionTrailSetup // // 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 motionTrailSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls. // motionTrailRange // int $useTSRange = `optionVar -query motionTrailTSRange`; if ($useTSRange == 1) radioButtonGrp -edit -select 2 motionTrailTSRange; else radioButtonGrp -edit -select 1 motionTrailTSRange; // -startTime // floatFieldGrp -edit -value1 `optionVar -query motionTrailStartTime` motionTrailStartTime; // -endTime // floatFieldGrp -edit -value1 `optionVar -query motionTrailEndTime` motionTrailEndTime; // -increment // floatFieldGrp -edit -value1 `optionVar -query motionTrailByTime` motionTrailByTime; // Display Frames // checkBoxGrp -edit -value1 `optionVar -q motionTrailFrame` motionTrailFrameWidget; // Anchor Transform checkBoxGrp -edit -value1 `optionVar -q motionTrailAnchorTransform` motionTrailAnchorTransformWidget; // Pre and Post Frames // floatFieldGrp -edit -value1 `optionVar -query motionTrailPre` motionTrailPreWidget; floatFieldGrp -edit -value1 `optionVar -query motionTrailPost` motionTrailPostWidget; // Thickness and keyframe size // floatFieldGrp -edit -value1 `optionVar -query motionTrailThickness` motionTrailThicknessWidget; floatFieldGrp -edit -value1 `optionVar -query motionTrailKeySize` motionTrailKeySizeWidget; // Pinning // int $pinValue = `optionVar -q motionTrailPin` ? 1 : 2; radioButtonGrp -edit -select $pinValue motionTrailPinWidget; // Allow no keys // checkBoxGrp -edit -value1 `optionVar -q motionTrailAllowNoKeys` motionTrailAllowNoKeysWidget; // Set the enable state of the start and end time fields. // motionTrailEnabling $parent (!$useTSRange); } // // Procedure Name: // motionTrailCallback // // 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 motionTrailCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then // perform the command. // motionTrailRange // if (`radioButtonGrp -query -select motionTrailTSRange` == 2) optionVar -intValue motionTrailTSRange 1; else optionVar -intValue motionTrailTSRange 0; // -startTime // optionVar -floatValue motionTrailStartTime `floatFieldGrp -query -value1 motionTrailStartTime`; // -endTime // optionVar -floatValue motionTrailEndTime `floatFieldGrp -query -value1 motionTrailEndTime`; // -increment // optionVar -floatValue motionTrailByTime `floatFieldGrp -query -value1 motionTrailByTime`; // frame display // optionVar -intValue motionTrailFrames (`checkBoxGrp -query -value1 motionTrailFrameWidget`); // anchor transform // optionVar -intValue motionTrailAnchorTransform (`checkBoxGrp -query -value1 motionTrailAnchorTransformWidget`); // Pre and Post Frames // optionVar -floatValue motionTrailPre `floatFieldGrp -query -value1 motionTrailPreWidget`; optionVar -floatValue motionTrailPost `floatFieldGrp -query -value1 motionTrailPostWidget`; // Thickness and keyframe size // optionVar -floatValue motionTrailKeySize `floatFieldGrp -query -value1 motionTrailKeySizeWidget`; optionVar -floatValue motionTrailThickness `floatFieldGrp -query -value1 motionTrailThicknessWidget`; // Pinning // int $pinValue = (`radioButtonGrp -query -select motionTrailPinWidget` == 2) ? 0 : 1; optionVar -intValue motionTrailPin $pinValue; // Allow no keys // optionVar -intValue motionTrailAllowNoKeys (`checkBoxGrp -query -value1 motionTrailAllowNoKeysWidget`); if ($doIt) { performMotionTrail 0; addToRecentCommandQueue "performMotionTrail 0" "MotionTrail"; } } // // Procedure Name: // motionTrailOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc motionTrailOptions() { // Name of the command for this option box. // string $commandName = "motionTrail"; // 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("snapshot"); // 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_performMotionTrail.kTimeRange")) -label1 (uiRes("m_performMotionTrail.kStartEnd")) -label2 (localizedUIComponentLabel("Time Slider")) -changeCommand1 ("motionTrailEnabling " + $parent + " #1") motionTrailTSRange; frameLayout -borderVisible false -labelVisible false -collapsable true -collapse false motionTrailStartEndFrame; columnLayout -adjustableColumn true; floatFieldGrp -label (uiRes("m_performMotionTrail.kStartTime")) motionTrailStartTime; floatFieldGrp -label (uiRes("m_performMotionTrail.kEndTime")) motionTrailEndTime; setParent ..; setParent ..; floatFieldGrp -label (uiRes("m_performMotionTrail.kIncrement")) motionTrailByTime; floatFieldGrp -label (uiRes("m_performMotionTrail.kPreFrames")) motionTrailPreWidget; floatFieldGrp -label (uiRes("m_performMotionTrail.kPostFrames")) motionTrailPostWidget; separator; radioButtonGrp -numberOfRadioButtons 2 -columnWidth3 170 160 200 -label (uiRes("m_performMotionTrail.kPinning")) -annotation (uiRes("m_performMotionTrail.kPinnedAnnot")) -label1 (uiRes("m_performMotionTrail.kAlwaysDraw")) -label2 (uiRes("m_performMotionTrail.kDrawWhenSel")) motionTrailPinWidget; floatFieldGrp -label (uiRes("m_performMotionTrail.kTrailThickness")) motionTrailThicknessWidget; floatFieldGrp -label (uiRes("m_performMotionTrail.kKeySize")) motionTrailKeySizeWidget; checkBoxGrp -label (uiRes("m_performMotionTrail.kShowFrames")) -label1 "" -numberOfCheckBoxes 1 motionTrailFrameWidget; checkBoxGrp -label (uiRes("m_performMotionTrail.kArbitraryParent")) -label1 "" -numberOfCheckBoxes 1 motionTrailAnchorTransformWidget; checkBoxGrp -label (uiRes("m_performMotionTrail.kAllowNoKeys")) -label1 "" -numberOfCheckBoxes 1 motionTrailAllowNoKeysWidget; // 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_performMotionTrail.kCreateMotionTrail")) -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_performMotionTrail.kMotionTrailOptions"))); // Customize the 'Help' menu item text. // setOptionBoxHelpTag( "MotionTrail" ); // 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 " + " -motionTrail 1 " + " -increment " + `optionVar -query motionTrailByTime` ; if (`optionVar -query motionTrailTSRange` == 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 motionTrailStartTime`; float $maxTime = `optionVar -query motionTrailEndTime`; $cmd = ($cmd + " -startTime " + $minTime + " -endTime " + $maxTime); } if (`optionVar -query motionTrailAnchorTransform` == 1) { // the user wants to use the last selected item // as the anchor transform string $selectedItems[] = `ls -sl`; int $numItems = size($selectedItems); if ($numItems > 0) { string $anchorXFormItem = $selectedItems[$numItems - 1]; $cmd = ($cmd + " -anchorTransform " + $anchorXFormItem); } } string $motionTrailCmd = "doMotionTrail 3 { \""+$cmd+"\", "+ "\""+`optionVar -query motionTrailFrames`+"\"," + "\""+`optionVar -query motionTrailPre`+"\"," + "\""+`optionVar -query motionTrailPost`+"\"," + "\""+`optionVar -query motionTrailThickness`+"\"," + "\""+`optionVar -query motionTrailKeySize`+"\"," + "\""+`optionVar -query motionTrailPin`+"\"," + "\""+`optionVar -query motionTrailAnchorTransform`+"\"," + "\""+`optionVar -query motionTrailAllowNoKeys`+"\"}"; return $motionTrailCmd; } // // Procedure Name: // performMotionTrail // // Description: // Perform the 'motionTrail' 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 'motionTrail' 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 performMotionTrail(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. // eval($cmd); break; // Show the option box. // case 1: motionTrailOptions; break; // Return the command string. // case 2: // Retrieve the option settings. // setOptionVars (false); // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }