Automating The Graphics Build Using mel


 
 

One often overlooked aspect of Maya, is that it can actually be run in a batch mode. The script below is designed to recursively descend into the specified directory; open all maya binary files found; and then export them as an obj file.

To run this script in batch mode (assuming it has been saved as C:/GameData/Export.mel) we simply need to type

maya -batch -script C:/GameData/Export.mel

[mel script (1k)]

 
 

 

 


//--------------------------------------------------------------------------------- SETTINGS

// change this to the name of you plugin you want to use.
global string $g_plugin = "C:/Program Files/Alias/Maya6.0/bin/plug-ins/objExport.mll";

// change this to the input directory
global string $g_InDirectory = "C:/GameData/";

// change this to the correct output extension, obj in this case
global string $g_OutExt = "obj";

//---------------------------------------------------------------------------------

//--------------------------------------------------------------------------------- DIRECTORY RECURSION
// we simply now want to recurse through the directory structure
// exporting any Maya Binary files as obj files.
// to do this we can use a number of handy mel functions,
//

proc RecursiveDirExport(string $dir)
{

  // redeclare the global so we can access it
global string $g_OutExt;

// get a directory listing

string $dir_list[] = `getFileList -folder $dir -fs "*.mb"`;

// loop through each maya binary file in the directory

for($i=0;$i<size($dir_list);++$i)
{
  // first open the file
file -open -force ($dir+$dir_list[$i]);

// strip the mb from the filename and append a new extension

$filename = ($dir + `substring $dir_list[$i] 1 (size($dir_list[$i])-2)` + $g_OutExt);

// export the file as an objfile

file -exportAll -force -type "OBJexport" $filename;
}

// now get a second file list and check each one.

$dir_list = `getFileList -folder $dir`;

// loop through each file returned.

for($i=0;$i<size($dir_list);++$i)
{
  // if we have a directory, recurse into it and export files
if( `filetest -d ($dir+$dir_list[$i])` )
{
  RecursiveDirExport( ($dir + $dir_list[$i] + "/") );

}

}

}


//--------------------------------------------------------------------------------- MAIN

// load the exporter plugin
loadPlugin $g_plugin;

// output all of the files in the directory
RecursiveDirExport( $g_InDirectory );



 

 

What Next?

Adding Custom Mel Functions Into the API

A Documentation System for Maya

Writine a Command Line Exporter

Writing A Plugin File Translator

index

Rob Bateman [2004]

[HOME] [MEL] [API]