// =========================================================================== // 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. // =========================================================================== global string $gAtomExportTemplateCurrentProject = "CurrentProject"; global int $gAtomExportTemplateSetFileWithBrowser= 0; global string $gAnimExportViewMenu = ""; proc atomExportCleanOptionMenu( ) { global string $gAtomExportViewMenu; string $item, $items[] = `optionMenuGrp -query -itemListLong $gAtomExportViewMenu`; for($item in $items) deleteUI $item; } proc atomExportPopulateOptionMenuWithViews(string $fullname, string $templateName) { global string $gAtomExportViewMenu; if (`optionMenuGrp -q -exists $gAtomExportViewMenu`) { //clean it first atomExportCleanOptionMenu(); string $menu = $gAtomExportViewMenu + "|OptionMenu"; //None always first menuItem -parent $menu -label (uiRes("m_exportAnimSharedOptions.kNone")) ; string $template = basename($templateName,".template"); if(size($template) >0) { //make sure it's loaded. string $cmd = "containerTemplate -silent -force -load -fileName "; $cmd += ("\""+$fullname+"\"") + " " + $template + ";"; //we don't check the catch here since DNA returns //error messages here that screws up catchQuiet //though the template loads catchQuiet(`eval $cmd`); string $cmdList = "containerTemplate -silent -query -viewList " + $template; string $strings[]; if(catchQuiet($strings = eval($cmdList)) == 0) { string $s; for($s in $strings) { if(size($s) >0) menuItem -parent $menu -label $s ; } } } } } global proc string atomExportTemplateGetCurrentDir() // // Return a string corresponding to the current directory preference. // Use the current project's data directory by default. // { global string $gAtomExportTemplateCurrentProject; // first find the current project directory, if it is defined // string $currentProj = (`workspace -q -rd`+"data"); // check what the user has as their preference // if (`optionVar -exists atomExportTemplateDirName`) { string $templateVar = `optionVar -q atomExportTemplateDirName`; if ($templateVar != $gAtomExportTemplateCurrentProject) { $currentProj = $templateVar; } } return $currentProj; } global proc atomExportTemplateSetDirOptionVar() // // Set the optionVar based on the user's entry in the option box // { global string $gAtomExportTemplateCurrentProject; if ( `textFieldGrp -q -en exportTemplateWidget` ) { string $value = `textFieldGrp -q -tx exportTemplateWidget`; if ( $value != "" ) { string $filename = basename($value,""); optionVar -stringValue atomExportTemplateFileName $filename; string $dir = dirname($value); string $currentProj = (`workspace -q -rd`+"data\/"); if ($currentProj == $dir) { $value = $gAtomExportTemplateCurrentProject; } optionVar -sv atomExportTemplateDirName $dir; } else { optionVar -stringValue atomExportTemplateFileName ""; optionVar -sv atomExportTemplateDirName $gAtomExportTemplateCurrentProject; } } } global proc int atomExportTemplateSetFile( string $file, string $type ) { textFieldGrp -e -tx $file exportTemplateWidget; atomExportTemplateSetDirOptionVar(); string $filename = basename($file,""); optionVar -stringValue atomExportTemplateFileName $filename; string $dirToUse = atomExportTemplateGetCurrentDir(); string $fullname = ($dirToUse+"\/"+$filename); atomExportPopulateOptionMenuWithViews($fullname,$filename); return 1; } global proc atomExportTemplateBrowseForFile() { string $callBack = "atomExportTemplateSetFile "; string $action = (uiRes("m_exportAnimSharedOptions.kSetDir")); string $startInDir; $startInDir = `textFieldGrp -q -tx exportTemplateWidget`; if ( size( $startInDir ) == 0 ) { $startInDir = `internalVar -uwd`; } else { $startInDir = dirname($startInDir); } if ( `file -q -ex $startInDir` ) { workspace -dir $startInDir; } global int $gAtomExportTemplateSetFileWithBrowser; $gAtomExportTemplateSetFileWithBrowser= 1; string $template = (uiRes("m_exportAnimSharedOptions.kTemplateFiles")); string $filter = $template + " (*.template)"; string $caption = (uiRes("m_exportAnimSharedOptions.kATOMTemplate")); string $fileCmd = ("fileDialog2 "); $fileCmd += (" -caption \"" + $caption + "\""); //$fileCmd += (" -okCaption \"" + $options[0] + "\""); $fileCmd += (" -fileMode 1"); $fileCmd += (" -startingDirectory \"" + $startInDir + "\""); $fileCmd += (" -returnFilter 0"); $fileCmd += (" -fileFilter \"" + $filter + "\""); $fileCmd += (" -selectFileFilter \"" + $template + "\""); string $file[] = `eval $fileCmd`; if (0 < size($file) && "" != $file[0]) { string $path = fromNativePath($file[0]); string $cmd = ($callBack + "\"" + $path + "\""); if (1 < size($file) && "" != $file[1]) { string $filterType = "template"; $cmd += (" \"" + $filterType + "\""); } else { $cmd += (" \"\""); } eval $cmd; } } 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. // { global string $gAtomExportViewMenu; // CVs checkbox is disabled when channelBox is selected // int $enableShapes = (`radioButtonGrp -q -select channelBoxGrp` == 1 ); checkBoxGrp -e -enable $enableShapes pointsCheckBox; // Start/End fields are enabled by the Start & Start/End options // int $enableStart = (1 == `radioButtonGrp -q -select timeRange2`); int $enableEnd = (2 == `radioButtonGrp - q -select timeRange2`); floatFieldGrp -e -enable ($enableStart || $enableEnd) frameStart; floatFieldGrp -e -enable $enableEnd frameEnd; int $useTemplate = (`radioButtonGrp -q -sl hierarchyGrp` == 3); textFieldGrp -e -enable $useTemplate exportTemplateWidget; symbolButton -e -enable $useTemplate exportTemplateWidgetBrowser; optionMenuGrp -e -enable $useTemplate $gAtomExportViewMenu; //if using templates then don't let us select all or channels int $notTemplate = (0==$useTemplate); radioButtonGrp -e -enable $notTemplate channelBoxGrp; } global proc setExportAnimSharedOptionVars(int $forceFactorySettings) { if( $forceFactorySettings || !`optionVar -exists animExportHierarchy` || (`optionVar -q animExportHierarchy` == 0)) { optionVar -intValue animExportHierarchy 1; } if( $forceFactorySettings || !`optionVar -exists animExportSDK` ) optionVar -intValue animExportSDK 0; if( $forceFactorySettings || !`optionVar -exists animExportConstraints` ) optionVar -intValue animExportConstraints 0; if( $forceFactorySettings || !`optionVar -exists animExportHistory` ) optionVar -intValue animExportHistory 1; if( $forceFactorySettings || !`optionVar -exists animExportAnimLayers` ) optionVar -intValue animExportAnimLayers 0; if( $forceFactorySettings || !`optionVar -exists animExportStatics` ) optionVar -intValue animExportStatics 1; if( $forceFactorySettings || !`optionVar -exists animExportBaked` ) optionVar -intValue animExportBaked 1; if( $forceFactorySettings || !`optionVar -exists animExportPoints` ) optionVar -intValue animExportPoints 0; if( $forceFactorySettings || !`optionVar -exists animExportChannels` ) { // 1 = keyable, 2 = channel box // optionVar -intValue animExportChannels 1; } // Time Range: // 1 = All, 2 = TimeSlider, 3 = Single Frame, 4 = Start/End // if( $forceFactorySettings || !`optionVar -exists animExportTimeRange`) optionVar -intValue animExportTimeRange 1; if( $forceFactorySettings || !`optionVar -exists animExportStartTime`) optionVar -floatValue animExportStartTime 1; if( $forceFactorySettings || !`optionVar -exists animExportEndTime`) optionVar -floatValue animExportEndTime 10; } global proc exportAnimUpdateSharedOptions() { // Hierarchy // if (`radioButtonGrp -exists hierarchyGrp`) { radioButtonGrp -e -sl `optionVar -q animExportHierarchy` hierarchyGrp; } // Set Driven Key // if (`checkBoxGrp -exists includeSdkCheckBox`) { checkBoxGrp -e -value1 `optionVar -q animExportSDK` includeSdkCheckBox; } // Constraints // if (`checkBoxGrp -exists includeConstraintCheckBox`) { checkBoxGrp -e -value1 `optionVar -q animExportConstraints` includeConstraintCheckBox; } // History // if (`checkBoxGrp -exists includeHistoryCheckBox`) { checkBoxGrp -e -value1 `optionVar -q animExportHistory` includeHistoryCheckBox; } // Animation Layers // if (`checkBoxGrp -exists includeAnimLayersCheckBox`) { checkBoxGrp -e -value1 `optionVar -q animExportAnimLayers` includeAnimLayersCheckBox; } // Static values // if (`checkBoxGrp -exists animExportStatics`) { checkBoxGrp -e -value1 `optionVar -q animExportStatics` animExportStatics; } // Baked animation // if (`checkBoxGrp -exists animExportBaked`) { checkBoxGrp -e -value1 `optionVar -q animExportBaked` animExportBaked; } // Control Points // if (`checkBoxGrp -exists pointsCheckBox`) { checkBoxGrp -e -value1 `optionVar -q animExportPoints` pointsCheckBox; } // Channels // if (`radioButtonGrp -exists channelBoxGrp`) { int $channels = `optionVar -q animExportChannels`; radioButtonGrp -e -select $channels channelBoxGrp; } int $timeOpt = `optionVar -query animExportTimeRange`; //for the buttons 1 is time slider and 2 is all but we expect //for animExportTimeRange that 1 is all and 2 is time slider. if ($timeOpt == 1) { radioButtonGrp -e -sl 2 timeRange; } else if ($timeOpt == 2) { radioButtonGrp -e -sl 1 timeRange; } else if ($timeOpt == 3) { radioButtonGrp -e -sl 1 timeRange2; } else { radioButtonGrp -e -sl 2 timeRange2; } floatFieldGrp -e -v1 `optionVar -query animExportStartTime` frameStart; floatFieldGrp -e -v1 `optionVar -query animExportEndTime` frameEnd; //template string $dirToUse = atomExportTemplateGetCurrentDir(); string $filename = `optionVar -q atomExportTemplateFileName`; string $fullname = ($dirToUse+"\/"+$filename) ; textFieldGrp -e -tx $fullname exportTemplateWidget; atomExportPopulateOptionMenuWithViews($fullname,$filename); } global proc exportAnimSharedOptionsCallback() { if (`radioButtonGrp -exists hierarchyGrp`) { optionVar -iv animExportHierarchy `radioButtonGrp -q -sl hierarchyGrp`; optionVar -iv animExportSDK `checkBoxGrp -q -value1 includeSdkCheckBox`; optionVar -iv animExportConstraints `checkBoxGrp -q -value1 includeConstraintCheckBox`; optionVar -iv animExportHistory `checkBoxGrp -q -value1 includeHistoryCheckBox`; optionVar -iv animExportAnimLayers `checkBoxGrp -q -value1 includeAnimLayersCheckBox`; optionVar -iv animExportStatics `checkBoxGrp -q -value1 animExportStatics`; optionVar -iv animExportBaked `checkBoxGrp -q -value1 animExportBaked`; optionVar -iv animExportPoints `checkBoxGrp -q -value1 pointsCheckBox`; optionVar -iv animExportChannels `radioButtonGrp -q -select channelBoxGrp`; //for the buttons 1 is time slider and 2 is all but we expect //for animExportTimeRange that 1 is all and 2 is time slider. int $timeMode = 1; if ( 2 == `radioButtonGrp -q -sl timeRange` ) { $timeMode = 1; } else if ( 1 == `radioButtonGrp -q -sl timeRange` ) { $timeMode = 2; } else if( 1 == `radioButtonGrp -q -sl timeRange2` ) { $timeMode = 3; } else { $timeMode = 4; } optionVar -iv animExportTimeRange $timeMode; optionVar -fv animExportStartTime `floatFieldGrp -q -v1 frameStart`; optionVar -fv animExportEndTime `floatFieldGrp -q -v1 frameEnd`; } } global proc int exportAnimGetHierarchy() { exportAnimSharedOptionsCallback(); return `optionVar -q animExportHierarchy`; } global proc int exportAnimGetSDK() { exportAnimSharedOptionsCallback(); return `optionVar -q animExportSDK`; } global proc int exportAnimGetConstraint() { exportAnimSharedOptionsCallback(); return `optionVar -q animExportConstraints`; } global proc int exportAnimGetHistory() { exportAnimSharedOptionsCallback(); return `optionVar -q animExportHistory`; } global proc int exportAnimGetAnimLayers() { exportAnimSharedOptionsCallback(); return `optionVar -q animExportAnimLayers`; } global proc int exportAnimGetStatics() { exportAnimSharedOptionsCallback(); return `optionVar -q animExportStatics`; } global proc int exportAnimGetBaked() { exportAnimSharedOptionsCallback(); return `optionVar -q animExportBaked`; } global proc int exportAnimGetPoints() { exportAnimSharedOptionsCallback(); return `optionVar -q animExportPoints`; } global proc int exportAnimTimeRange() { exportAnimSharedOptionsCallback(); return `optionVar -q animExportTimeRange`; } global proc float exportAnimGetStart() { exportAnimSharedOptionsCallback(); float $val = `optionVar -q animExportStartTime`; return $val; } global proc float exportAnimGetEnd() { exportAnimSharedOptionsCallback(); float $val = `optionVar -q animExportEndTime`; return $val; } // Channels: 1 = selected, 2 = channel box // global proc int exportAnimGetChannels() { exportAnimSharedOptionsCallback(); return `optionVar -q animExportChannels`; } global proc string animExportGetCommand() // // Description: // Sets the opts string for all of the shared options. // { global string $gAtomExportTemplateCurrentProject; global string $gAtomExportViewMenu; if (`textFieldGrp -q -exists exportTemplateWidget`) { // Since the changed callback is not invoked if the user does not // hit enter, update the value now // atomExportTemplateSetDirOptionVar(); } $gAtomExportTemplateSetFileWithBrowser= 0; string $dirname = `optionVar -query atomExportTemplateDirName`; if ($dirname == $gAtomExportTemplateCurrentProject) { $dirname = (`workspace -q -rd`+"data\/"); } string $filename = `optionVar -query atomExportTemplateFileName`; if (size($filename) == 0) { error((uiRes("m_exportAnimSharedOptions.kMustSpecifyFilename"))); return ""; } string $templateName = $filename; $filename = ($dirname + "\/" + $filename); string $opts; string $kCopyKeyWhichRange = "whichRange"; string $kCopyKeyRange = "range"; string $kCopyKeyOptions = "options"; string $kCopyKeyHierarchy = "hierarchy"; string $kCopyKeyControlPoints = "controlPoints"; string $kCopyKeyUseChannelBox = "useChannelBox"; $opts += (";statics="+exportAnimGetStatics()); $opts += (";baked="+exportAnimGetBaked()); $opts += (";sdk="+exportAnimGetSDK()); $opts += (";constraint="+exportAnimGetConstraint()); $opts += (";animLayers="+exportAnimGetAnimLayers()); int $includeHierarchy = exportAnimGetHierarchy(); int $templateUsed = 0; //if template is used then dont' use channel box string $optsSelection = "selectedOnly"; if ($includeHierarchy == 3) { $optsSelection = "template"; string $base = basename($templateName,".template"); //make sure it's loaded string $cmd = "containerTemplate -force -silent -load -fileName "; $cmd += ("\""+$filename+"\"") + " " + $base + ";"; int $status = catchQuiet(`eval $cmd`); if($status ==0) //loaded fine, so it's okay { $opts +=(";template="+$base +";"); $templateUsed = 1; } } else if($includeHierarchy ==2) $optsSelection = "childrenToo"; $opts += (";selected=" + $optsSelection); if (`optionMenuGrp -exists $gAtomExportViewMenu`) { int $selectedView = `optionMenuGrp -query -select $gAtomExportViewMenu`; if($selectedView != 1) //1 is always None { string $item = `optionMenuGrp -query -value $gAtomExportViewMenu`; $opts += (";view=" + $item); } } // which time range // int $whichRange = exportAnimTimeRange(); float $start = exportAnimGetStart(); float $end = exportAnimGetEnd(); if ($whichRange != 1) { // In the UI, it is presented as 4 options, but everything // other than 1 ("all") can be treated as "time range" from a // copy key standpoint // if ($whichRange == 3) /* single frame */ { $end = $start; } else if ($whichRange == 2) /* time slider */ { $start = `playbackOptions -q -min`; $end = `playbackOptions -q -max`; } $whichRange = 2; } $opts += (";" + $kCopyKeyWhichRange + "=" + $whichRange); string $timeRange = ($start + ":" + $end); $opts += (";" + $kCopyKeyRange + "=" + $timeRange); // -hierarchy // is always none. We do hierarchy matching internally string $hierarchy = "none"; $opts += (";" + $kCopyKeyHierarchy + "=" + $hierarchy); // -controlPoints // int $doControlPoints = exportAnimGetPoints(); $opts += (";" + $kCopyKeyControlPoints + "=" + $doControlPoints); // use channel box attrs // int $useChannelBox = exportAnimGetChannels(); //wait if using a template turn off the channel box if($templateUsed == 1) $useChannelBox = 1; $opts += (";" + $kCopyKeyUseChannelBox + "=" + $useChannelBox); // -option // string $option = "keys"; if (`radioButtonGrp -exists method`) { if (`radioButtonGrp -query -select method` == 1) { $option = "keys"; } else { $option = "curve"; } } $opts += (";" + $kCopyKeyOptions + "=" + $option); // 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 + " " ); string $attrOptions; if ($useChannelBox == 2) { 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] + " " ); $attrOptions=($attrOptions + "at=" + $main[$i] + ";" ); } for( $i = 0; $i < size( $shape ); $i++ ) { $attrs = ( $attrs + "-at " + $shape[$i] + " " ); $attrOptions = ( $attrOptions + "at=" + $shape[$i] + ";" ); } for( $i = 0; $i < size( $history ); $i++ ) { $attrs = ( $attrs + "-at " + $history[$i] + " " ); $attrOptions = ( $attrOptions + "at=" + $history[$i] + ";" ); } if( size( $attrs ) == 0 ) { $cmd = ""; warning (uiRes("m_exportAnimSharedOptions.kNoChannelSelected")); } else { $cmd = ( $cmd + $attrs + "-hierarchy " + $hierarchy + " " ); } } else { $cmd = ($cmd + "-hierarchy " + $hierarchy + " " + "-controlPoints " + $doControlPoints + " " ); } //if we have attrs then also add them to the options //before doing the command so that those attributes //are handled correctly for static values if( size( $attrOptions ) != 0 ) $opts += (";" + $attrOptions); $opts += ";" + $cmd; return $opts; } global proc exportAnimSharedOptions() { global string $gAtomExportViewMenu; checkBoxGrp -numberOfCheckBoxes 1 -label (uiRes("m_exportAnimSharedOptions.kInclude")) -label1 (uiRes("m_exportAnimSharedOptions.kIncludeSDK")) -value1 `optionVar -query animExportSDK` includeSdkCheckBox; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_exportAnimSharedOptions.kIncludeConstraints")) -value1 `optionVar -query animExportConstraints` includeConstraintCheckBox; checkBoxGrp -numberOfCheckBoxes 1 -label1 (uiRes("m_exportAnimSharedOptions.kIncludeHistory")) -value1 `optionVar -query animExportHistory` includeHistoryCheckBox; checkBoxGrp -numberOfCheckBoxes 1 -label1 (uiRes("m_exportAnimSharedOptions.kIncludeAnimLayers")) -value1 `optionVar -query animExportAnimLayers` includeAnimLayersCheckBox; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_exportAnimSharedOptions.kStatics")) -value1 `optionVar -query animExportStatics` animExportStatics; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_exportAnimSharedOptions.kBakedAnimation")) -value1 `optionVar -query animExportBaked` animExportBaked; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_exportAnimSharedOptions.kControlPoints")) -value1 off pointsCheckBox; separator; radioButtonGrp -numberOfRadioButtons 3 -label (uiRes("m_exportAnimSharedOptions.kHierarchy")) -label1 (uiRes("m_exportAnimSharedOptions.kSelected")) -label2 (uiRes("m_exportAnimSharedOptions.kBelow")) -label3 (uiRes("m_exportAnimSharedOptions.kTemplate")) -cc "animExportWidgetsEnable" -select 1 -enable true hierarchyGrp; rowLayout -nc 3 -cw3 425 5 50 -adjustableColumn 1 -cal 1 "both" -cal 2 "both" -cal 3 "left" -ct3 "both" "both" "left"; string $dirToUse = atomExportTemplateGetCurrentDir(); string $filename = `optionVar -q atomExportTemplateFileName`; string $fullname = ($dirToUse+"\/"+$filename) ; textFieldGrp -label (uiRes("m_exportAnimSharedOptions.kTemplateFile")) -tx $fullname -adjustableColumn 2 exportTemplateWidget; separator -w 5 -style "none"; symbolButton -image "navButtonBrowse.png" -c ( "atomExportTemplateBrowseForFile" ) exportTemplateWidgetBrowser; setParent ..; $gAtomExportViewMenu = `optionMenuGrp -label (uiRes("m_exportAnimSharedOptions.kView")) -adj 2`; atomExportPopulateOptionMenuWithViews($fullname,$filename); radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_exportAnimSharedOptions.kChannels")) -label1 (uiRes("m_exportAnimSharedOptions.kAllKeyable")) -cc1 "animExportWidgetsEnable" -label2 (uiRes("m_exportAnimSharedOptions.kFromChannelBox")) -cc2 "animExportWidgetsEnable" -select 1 -enable true channelBoxGrp; radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_exportAnimSharedOptions.kTimeRange")) -l1 (localizedUIComponentLabel("Time Slider")) -label2 (uiRes("m_exportAnimSharedOptions.kAll")) -cc "animExportWidgetsEnable" timeRange; radioButtonGrp -label "" -nrb 2 -scl timeRange -cc "animExportWidgetsEnable" -label1 (uiRes("m_exportAnimSharedOptions.kSingleFrame")) -l2 (uiRes("m_exportAnimSharedOptions.kStartEnd")) timeRange2; floatFieldGrp -label (uiRes("m_exportAnimSharedOptions.kStartTime")) -value1 0.0 frameStart; floatFieldGrp -label (uiRes("m_exportAnimSharedOptions.kEndTime")) -value1 10.0 frameEnd; }