// =========================================================================== // 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. // =========================================================================== // Description: // // Input Arguments: // // Return Value: // global proc animExportSetup(string $nextOptions[]) // // Description: // Takes a string array containing an option keyword and its argument. // This is used to set the copyKey widgets. // { string $kCopyKeyWhichRange = "whichRange"; string $kCopyKeyRange = "range"; string $kCopyKeyOptions = "options"; string $kCopyKeyHierarchy = "hierarchy"; string $kCopyKeyControlPoints = "controlPoints"; string $kCopyKeyShapes = "shapes"; string $kCopyKeyHelpPictures = "helpPictures"; string $kCopyKeyUseChannelBox = "useChannelBox"; if ($nextOptions[0] == $kCopyKeyWhichRange) { // time range // int $timeRange = $nextOptions[1]; radioButtonGrp -edit -select $timeRange timeRange; } else if ($nextOptions[0] == $kCopyKeyRange) { // start/end times // string $time = $nextOptions[1]; string $range[]; tokenize ($time, ":", $range); float $start = float ($range[0]); float $end = float ($range[1]); floatFieldGrp -edit -value1 $start frameStart; floatFieldGrp -edit -value1 $end frameEnd; } else if ($nextOptions[0] == $kCopyKeyOptions) { // -option // string $option = $nextOptions[1]; if ($option == "keys") { radioButtonGrp -edit -select 1 method; } else { radioButtonGrp -edit -select 2 method; } } else if ($nextOptions[0] == $kCopyKeyHierarchy) { // -hierarchy // string $hierarchy = $nextOptions[1]; if ($hierarchy == "below") { radioButtonGrp -edit -select 2 hierarchy; } else { radioButtonGrp -edit -select 1 hierarchy; } } else if ($nextOptions[0] == $kCopyKeyControlPoints) { // -controlPoints // int $controlPoints = $nextOptions[1]; checkBoxGrp -e -value1 $controlPoints controlPoints; } else if ($nextOptions[0] == $kCopyKeyShapes) { // -shape // int $shapes = $nextOptions[1]; checkBoxGrp -e -value1 $shapes shapes; } else if ($nextOptions[0] == $kCopyKeyHelpPictures) { // help images // int $pictures = $nextOptions[1]; checkBoxGrp -e -value1 $pictures helpPictures; } else if ($nextOptions[0] == $kCopyKeyUseChannelBox) { // use channel box attrs // int $boxAttrs = $nextOptions[1]; radioButtonGrp -e -select ( $boxAttrs + 1 ) channels; if( $boxAttrs ) { frameLayout -e -collapse yes attributesFrame; } else { frameLayout -e -collapse no attributesFrame; } } // Now get all the dependent widgets in the right // enabled/disabled/collapsed/expanded state // animExportWidgetsEnable; animExportHelpPictures; } global proc string animExportGetOpts() // // Description: // Sets the opts string for all of the copyKey options. // { string $opts; string $kCopyKeyWhichRange = "whichRange"; string $kCopyKeyRange = "range"; string $kCopyKeyOptions = "options"; string $kCopyKeyHierarchy = "hierarchy"; string $kCopyKeyControlPoints = "controlPoints"; string $kCopyKeyShapes = "shapes"; string $kCopyKeyHelpPictures = "helpPictures"; string $kCopyKeyUseChannelBox = "useChannelBox"; // which time range // int $whichRange = `radioButtonGrp -q -select timeRange`; $opts += (";" + $kCopyKeyWhichRange + "=" + $whichRange); // -time // string $timeRange = string (`floatFieldGrp -query -value1 frameStart`) + ":" + string (`floatFieldGrp -query -value1 frameEnd`); $opts += (";" + $kCopyKeyRange + "=" + $timeRange); // -option // string $option; if (`radioButtonGrp -query -select method` == 1) { $option = "keys"; } else { $option = "curve"; } $opts += (";" + $kCopyKeyOptions + "=" + $option); // -hierarchy // string $hierarchy; int $selected = `radioButtonGrp -query -select hierarchy`; if ($selected == 2) { $hierarchy = "below"; } else { $hierarchy = "none"; } $opts += (";" + $kCopyKeyHierarchy + "=" + $hierarchy); // -controlPoints // int $doControlPoints = `checkBoxGrp -query -value1 controlPoints`; $opts += (";" + $kCopyKeyControlPoints + "=" + $doControlPoints); // -shapes // int $doShapes = `checkBoxGrp -query -value1 shapes`; $opts += (";" + $kCopyKeyShapes + "=" + $doShapes); // help // int $helpPictures = `checkBoxGrp -query -value1 helpPictures`; $opts += (";" + $kCopyKeyHelpPictures + "=" + $helpPictures); // use channel box attrs // int $useChannelBox = `radioButtonGrp -query -select channels`; $useChannelBox--; $opts += (";" + $kCopyKeyUseChannelBox + "=" + $useChannelBox); // Since the copyKey command is fairly complex to assemble, the string // passed to AnimExport will be long. The first section is the // options in the option box. The second section is the copyKey command // without the -cb api call. // // Effectively these contain the same data, but the two formats are // needed to make parsing easier. // string $cmd = "copyKeyCmd="; $cmd = $cmd + "-animation objects "; // Now assemble the options into a string to pass to animExport. // The > character will be replaced by a quotation mark in the // AnimExport plug-in. This is required, since the translator option // box does not handle escaped quotation marks. // if ($whichRange == 2) { $cmd = ( $cmd + "-time >" + $timeRange + "> "); $cmd = ( $cmd + "-float >" + $timeRange + "> "); } // If there's a time specified, always add the option // $cmd = ( $cmd + "-option " + $option + " " ); if ($useChannelBox == 1) { string $main[]; string $shape[]; string $history[]; int $i; string $attrs; catch( $main = `channelBox -q -sma mainChannelBox` ); catch( $shape = `channelBox -q -ssa mainChannelBox` ); catch( $history = `channelBox -q -sha mainChannelBox` ); for( $i = 0; $i < size( $main ); $i++ ) { $attrs = ( $attrs + "-at " + $main[$i] + " " ); } for( $i = 0; $i < size( $shape ); $i++ ) { $attrs = ( $attrs + "-at " + $shape[$i] + " " ); } for( $i = 0; $i < size( $history ); $i++ ) { $attrs = ( $attrs + "-at " + $history[$i] + " " ); } if( size( $attrs ) == 0 ) { $cmd = ""; warning (uiRes("m_animExportOptions.kNoChannelSelected")); } else { $cmd = ( $cmd + $attrs + "-hierarchy " + $hierarchy + " " ); } // Now add the specific objects from the channel box // string $objList[] = `channelBox -q -mainObjectList mainChannelBox`; if ((size($main) > 0) && (size($objList) > 0)) { for ($object in $objList) $cmd = $cmd + " " + $object; } $objList = `channelBox -q -shapeObjectList mainChannelBox`; if ((size($shape) > 0) && (size($objList) > 0)) { for ($object in $objList) $cmd = $cmd + " " + $object; } $objList = `channelBox -q -historyObjectList mainChannelBox`; if ((size($history) > 0) && (size($objList) > 0)) { for ($object in $objList) $cmd = $cmd + " " + $object; } } else { $cmd = ($cmd + "-hierarchy " + $hierarchy + " " + "-controlPoints " + $doControlPoints + " " + "-shape " + $doShapes + " " ); } $opts += ";" + $cmd; return $opts; } global proc animExportHelpPictures() { int $doPictures = `checkBoxGrp -q -value1 helpPictures`; if( $doPictures == 0 ) { frameLayout -e -collapse yes methodPictureFrame; return; } int $method = `radioButtonGrp -q -select method`; string $methodPicture; if( $method == 1 ) { $methodPicture = "CCPkeyframesOnly.png"; } else { $methodPicture = "CCPcurveExact.png"; } picture -e -image (languageResourcePath($methodPicture)) methodPicture; frameLayout -e -collapse no methodPictureFrame; } global proc animExportWidgetsEnable() // // 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. // { int $enableit; // Shapes and CVs checkboxes // if (`exists channels`) { $enableIt = (( `radioButtonGrp -q -select channels` == 1 ) && ( `radioButtonGrp -q -enable channels` )); frameLayout -e -enable $enableIt attributesFrame; } // Start/End fields // if (`exists startEndFrame`){ $enableIt = (( `radioButtonGrp -q -select timeRange` == 2 ) && ( `radioButtonGrp -q -enable timeRange` )); frameLayout -e -enable $enableIt startEndFrame; } } proc string animExportWidgets( string $tabLayout) { global int $gTextColumnWidthIndex; setParent $tabLayout; string $tabForm = `columnLayout -adjustableColumn true`; frameLayout -bv no -lv no -collapsable yes -collapse false hierChanAttrFrame; columnLayout -adjustableColumn true; radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_animExportOptions.kHierarchy")) -label1 (uiRes("m_animExportOptions.kSelected")) -label2 (uiRes("m_animExportOptions.kBelow")) -enable true hierarchy; radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_animExportOptions.kChannels")) -label1 (uiRes("m_animExportOptions.kAllKeyable")) -cc1 "animExportWidgetsEnable" -label2 (uiRes("m_animExportOptions.kFromChannelBox")) -cc2 "animExportWidgetsEnable" -enable true channels; frameLayout -bv no -lv no -collapsable no attributesFrame; columnLayout -adjustableColumn true; checkBoxGrp -label (uiRes("m_animExportOptions.kControlPoints")) -ncb 1 -value1 off -label1 "" controlPoints; checkBoxGrp -label (uiRes("m_animExportOptions.kShapes")) -ncb 1 -value1 on -label1 "" shapes; setParent ..; setParent ..; separator; setParent ..; setParent ..; radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_animExportOptions.kTimeRange")) -label1 (uiRes("m_animExportOptions.kAll")) -cc1 "animExportWidgetsEnable" -label2 (uiRes("m_animExportOptions.kStartEnd")) -cc2 "animExportWidgetsEnable" timeRange; frameLayout -bv no -lv no -collapsable no startEndFrame; columnLayout -adjustableColumn true; floatFieldGrp -label (uiRes("m_animExportOptions.kStartTime")) -value1 0.0 frameStart; floatFieldGrp -label (uiRes("m_animExportOptions.kEndTime")) -value1 10.0 frameEnd; separator; checkBoxGrp -label (uiRes("m_animExportOptions.kHelpImages")) -ncb 1 -value1 off -label1 "" -cc1 "animExportHelpPictures;" helpPictures; radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_animExportOptions.kMethod")) -label1 (uiRes("m_animExportOptions.kKeys")) -cc1 "animExportHelpPictures" -label2 (uiRes("m_animExportOptions.kSegments")) -cc2 "animExportHelpPictures" method; frameLayout -bv no -lv no -collapsable yes -collapse yes methodPictureFrame; columnLayout -columnAttach "left" $gTextColumnWidthIndex; picture methodPicture; setParent ..; setParent ..; setParent ..; setParent ..; return $tabForm; } global proc int animExportOptions( string $parent, string $action, string $initialSettings, string $resultCallback ) // // Description: // This script posts the anim export options. // // Parameters: // $parent - the elf parent layout for this options layout. It is // always a scrollLayout. // $action - the action that is to be performed with this invokation // of this proc. Valid options are: // "query" - construct the options string and pass it // to the resultCallback. // "post" - post all the elf controls. // $resultCallback - // This is the proc to be called with the result string. // resultCallback ( string $optionsString ) // // Returns: // 1 if successfull. // 0 otherwise. // { int $result; string $currentOptions; string $optionList[]; string $optionBreakDown[]; int $index; optionVar -intValue animExportAnimationFile true; if ($action == "post") { setUITemplate -pushTemplate DefaultTemplate; setParent $parent; columnLayout animExportMultiObjLayout; // Make the layout invisible during the control creation. // columnLayout -e -vis false animExportMultiObjLayout; formLayout animExportForm; rowColumnLayout -numberOfColumns 2 -rat 1 "top" 5 -cal 1 "right" -cw 2 250 animExportFileOptsLayout; text -label (uiRes("m_animExportOptions.kPrecision")) ; rowColumnLayout -numberOfColumns 2; radioCollection animExportCollection; radioButton -label (uiRes("m_animExportOptions.kFloat8")) -cl animExportCollection animExportFloatBtn; text -label ""; radioButton -label (uiRes("m_animExportOptions.kDouble17")) -cl animExportCollection animExportDoubleBtn; text -label ""; radioButton -label (uiRes("m_animExportOptions.kCustom")) -onc "intField -e -en true animExportIntFld" -ofc "intField -e -en false animExportIntFld" -cl animExportCollection animExportCustomBtn; intField -min 1 -max 17 -s 1 -v 17 -en false animExportIntFld; setParent ..; text -label (uiRes("m_animExportOptions.kFileContents")) ; checkBox -label (uiRes("m_animExportOptions.kUseNode")) -v off animExportNodeChk; text -label ""; checkBox -label (uiRes("m_animExportOptions.kVerboseUnits")) -v off animExportVerboseChk; setParent ..; separator animExportSep; formLayout -edit -attachForm animExportFileOptsLayout "top" 10 -attachForm animExportFileOptsLayout "left" 65 -attachControl animExportSep "top" 5 animExportFileOptsLayout -attachForm animExportSep "left" 0 -attachForm animExportSep "right" 0 animExportForm; string $copyKeyTab = animExportWidgets("animExportMultiObjLayout"); setParent ..; setUITemplate -popTemplate; // Now to set the current settings. // $currentOptions = $initialSettings; if (size($currentOptions) > 0) { tokenize($currentOptions, ";", $optionList); for ($index = 0; $index < size($optionList); $index++) { tokenize($optionList[$index], "=", $optionBreakDown); if ($optionBreakDown[0] == "intValue") { int $intValue = $optionBreakDown[1]; intField -edit -value $intValue animExportIntFld; } else if ($optionBreakDown[0] == "precision") { int $precision = $optionBreakDown[1]; if ($precision == 8) { radioCollection -edit -select animExportFloatBtn animExportCollection; } else if ($precision == 17) { radioCollection -edit -select animExportDoubleBtn animExportCollection; } else { radioCollection -edit -select animExportCustomBtn animExportCollection; intField -edit -value $precision animExportIntFld; } } else if ($optionBreakDown[0] == "nodeNames") { int $value = $optionBreakDown[1]; checkBox -e -v $value animExportNodeChk; } else if ($optionBreakDown[0] == "verboseUnits") { int $value = $optionBreakDown[1]; checkBox -e -v $value animExportVerboseChk; } else { animExportSetup($optionBreakDown); } } } columnLayout -e -vis true animExportMultiObjLayout; $result = 1; } else if ($action == "query") { if (`radioButton -query -sl animExportFloatBtn`) { $currentOptions += "precision=8"; } else if (`radioButton -query -sl animExportDoubleBtn`) { $currentOptions += "precision=17"; } else if (`radioButton -query -sl animExportCustomBtn`) { $currentOptions += ("precision=" + `intField -q -value animExportIntFld`); } $currentOptions += (";intValue="+`intField -q -value animExportIntFld`); $currentOptions += (";nodeNames="+`checkBox -q -v animExportNodeChk`); $currentOptions += (";verboseUnits="+`checkBox -q -v animExportVerboseChk`); $currentOptions += animExportGetOpts(); eval($resultCallback+" \""+$currentOptions+"\""); $result = 1; } else { $result = 0; } return $result; }