// =========================================================================== // 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: // This script is the export deformer weight option box dialogs. // // Input Arguments: // None. // // Return Value: // None. // proc setOptionVars (int $forceFactorySettings) { if ( $forceFactorySettings || !`optionVar -exists exportDefWeightDirName`) { optionVar -sv exportDefWeightDirName "CurrentProject"; } if ( $forceFactorySettings || !`optionVar -exists exportDefWeightFileExtension`) { optionVar -sv exportDefWeightFileExtension "XML"; } if ( $forceFactorySettings || !`optionVar -exists exportDefWeightFileName`) { optionVar -sv exportDefWeightFileName "weightSet"; } } proc string mapFileExtension_melToUI( string $mel ) { string $ui = $mel; if( $mel == "XML" ) { $ui = (uiRes("m_performExportDeformerWeights.kXMLExtension")); } else if( $mel == "JSON" ) { $ui = (uiRes("m_performExportDeformerWeights.kJSONExtension")); } else { uiToMelMsg( "mapFileExtension_melToUI", $mel, 1 ); } return $ui; } // Call back from text field changes // global proc exportDefWeightFileNameChanged() { if( !`textField -exists weightFileNameField` ) return; string $name = `textField -query -text weightFileNameField` ; if ( $name == "" ) { // automatically generate a name // TO DO } optionVar -sv exportWeightFileName $name; } // Get the current directory. Get the last used directory or the current // working directory. Use as the starting point for the file brower dialog // proc string exportDefWeightGetCurrentDir() { // first find the current project directory, if it is defined // string $currentProj = (`workspace -q -rd`); // check what the user has as their preference // if (`optionVar -exists exportDefWeightDirName`) { string $cacheVar = `optionVar -q exportDefWeightDirName`; if ($cacheVar != "CurrentProject") { $currentProj = $cacheVar; } } if(!endsWith( $currentProj, "/" ) ) { $currentProj += "/"; } return $currentProj; } global proc int exportDefWeightSetFile( string $fullPath, string $type ) { // $type not used string $buffer[]; string $file = ""; string $dir = ""; int $depth = tokenize( $fullPath, "/", $buffer ); if ($depth > 1) { $file = $buffer[$depth-1]; $dir = substring ($fullPath, 1, size($fullPath) - size($file)); } else { $file = $fullPath; } if ( `textField -exists weightFileNameField` ) { textField -e -tx $file weightFileNameField; } // set the option variable for the current directoy if (`optionVar -exists exportDefWeightDirName`) { string $currentProj = (`workspace -q -rd`); if ($currentProj == $dir) { optionVar -sv exportDefWeightDirName "CurrentProject"; } else { optionVar -sv exportDefWeightDirName $dir; } } return 1; } // Get the file name and make sure that it has an extension on it // Note: we aren't forcing xml has a file extension just adding it // in case the user hasn't added any extension // proc string getValidFileName() { string $fileName = `textField -query -text weightFileNameField` ; string $buffer[]; int $depth = tokenize( $fileName, ".", $buffer ); if ($depth == 1) { // doesn't have any extensions so add one string $fileExtension = mapFileExtension_melToUI(`optionMenuGrp -q -v weightFileExtension`); if( $fileExtension == "XML") { $fileName += ".xml"; } else { $fileName += ".json"; } } return $fileName; } global proc exportDefWeightBrowse() { string $cmd = "exportDefWeightSetFile "; string $action = (uiRes("m_performExportDeformerWeights.kWeightExportFile")); string $startInDir; $startInDir = exportDefWeightGetCurrentDir(); if ( size( $startInDir ) == 0 ) { $startInDir = `internalVar -uwd`; } if ( `file -q -ex $startInDir` ) { // set the work space to the current directory workspace -dir $startInDir; } // get the file extension string $fileExtension = mapFileExtension_melToUI(`optionMenuGrp -q -v weightFileExtension`); if ( $fileExtension == "XML" ) { fileBrowser( $cmd, $action, "xmlcache", 1 ); // TO DO temp steal the xml cache } else { fileBrowser( $cmd, $action, "json", 1 ); } } // Procedure Name: // exportDeformerWeightsSetup // // 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. // global proc exportDeformerWeightsSetup (string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars( $forceFactorySettings ); setParent $parent; // No relevant UI to update currently } // Procedure Name: // exportDeformerWeightsCallback // // 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. // global proc exportDeformerWeightsCallback (string $parent, int $doIt) { setParent $parent; if ($doIt) { performExportDeformerWeights false; addToRecentCommandQueue "performExportDeformerWeights false" "exportDeformerWeights"; } } global proc fileExtensionCallback() { // get the file extension string $fileExtension = mapFileExtension_melToUI(`optionMenuGrp -q -v weightFileExtension`); // set the optionVar optionVar -sv exportDefWeightFileExtension $fileExtension; } proc string exportDeformerWeightsWidgets( string $parent ) { setParent $parent; string $tabForm = `columnLayout -adjustableColumn true`; // Create an option menu listing existing deformer nodes // optionMenuGrp -enable 1 -label (uiRes("m_performExportDeformerWeights.kExistingNodes")) deformWeightList; // add all the deformers to the menu // int $pp; string $dfArray[]; if (size(`ls -sl`) > 0) { catch($dfArray = `findExportableDeformers`); } int $dfCount = size($dfArray); for ($pp = 0; $pp < $dfCount; $pp++) { menuItem -label $dfArray[$pp]; } if ($dfCount == 0) { menuItem -label (uiRes("m_performExportDeformerWeights.kNoDeformer")) ; optionMenuGrp -e -enable 0 deformWeightList; } //Add JSON or XML dropdwon optionMenuGrp -enable 1 -label (uiRes("m_performExportDeformerWeights.kFileFormat")) -cc "fileExtensionCallback" weightFileExtension; menuItem -label `mapFileExtension_melToUI( "XML" )`; menuItem -label `mapFileExtension_melToUI( "JSON" )`; // Directory name // rowLayout -nc 3 -adjustableColumn 2 -cw 3 50 fileNameRowLayout; text -label (uiRes("m_performExportDeformerWeights.kWeightImportDirectory")); textField -cc ( "exportDefWeightFileNameChanged" ) weightFileNameField; symbolButton -image "navButtonBrowse.png" -c ( "exportDefWeightBrowse" ) weightFileBrowser; setParent ..; return $tabForm; } global proc exportDeformerWeightsOptions () { string $commandName = "exportDeformerWeights"; // Build the option box "methods" // 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; setOptionBoxCommandName("exportDeformerWeights"); setUITemplate -pushTemplate DefaultTemplate; waitCursor -state 1; tabLayout -scr true -tv false; // To get the scroll bars string $parent = `columnLayout -adjustableColumn 1`; exportDeformerWeightsWidgets $parent; waitCursor -state 0; setUITemplate -popTemplate; // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performExportDeformerWeights.kDfrmExport")) -command ($callback + " " + $parent + " " + 1) $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_performExportDeformerWeights.kExportDeformerWeightsOptions")); // Customize the 'Help' menu item text. // setOptionBoxHelpTag( "ExportDeformerWeights" ); // 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 = "deformerWeights -export"; // deformer string $deformer = `optionMenuGrp -q -v deformWeightList`; $cmd += " -deformer \""+ $deformer + "\""; // add the file extension string $fileExtension = mapFileExtension_melToUI(`optionMenuGrp -q -v weightFileExtension`); if ($fileExtension != "") { $cmd += " -format \""+ $fileExtension + "\""; } // add path string $directory = `optionVar -q exportDefWeightDirName`; if ($directory != "CurrentProject") { $cmd += " -path \"" + $directory + "\""; } // add the file name string $fileName = getValidFileName(); $cmd += " \"" + $fileName + "\""; return $cmd; } // Procedure Name: // performExportDeformerWeights // // Description: // Option box for exporting deformer weights // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // // Return Value: // None. // global proc string performExportDeformerWeights (int $action) { string $cmd = ""; switch ($action) { case 0: // Execute the command. // Retrieve the option settings // setOptionVars(false); // Get the command. // $cmd = `assembleCmd`; // Execute the command with the option settings. // evalEcho($cmd); break; case 1: // Show the option box. // exportDeformerWeightsOptions; break; case 2: // Get the command. // $cmd = `assembleCmd`; } return $cmd; }