March 2019: ewertb.soundlinker.com is getting relocated to ewertb.mayasound.com, please update your bookmarks.

MEL How-To #68

Back · Previous · Next Maya

How do I specify the options for an Export plug-in (a.k.a. File Translator)?

The options string is generated by the MEL script that is defined as the "Options" MEL script for the Export type. The exact name of this file is arbitrary and is specified within the exporter plug-in.

For example, the OBJ exporter uses "objExportOptions.mel" to display its options for the user. During an Export, Maya calls this script in two modes: "post" and "query". In "post" mode the "objExportOptions" script populates the "File Type Specific Options" layout of the Export Options panel, setting all UI elements to their current values (or defaults for the first time the Exporter is run). In "query" mode the script reads the settings for the options set by the user and concatenates all options in the form:

optionName1=value1;optionName2=value2;...

To communicate the options between the Exporter and the options panel, Maya saves them in an optionVar. The name of this optionVar is defined within "pv_performAction.mel" as "<exportType>Options". In the case of the OBJ exporter, an optionVar with the name "OBJexportOptions" is created. To query the current state of the options:

optionVar -q OBJexportOptions;
// Result: groups=1;ptgroups=0;materials=0;smoothing=0;normals=0 //

To build the 'file' command to perform an "Export All" function:

file -typ <exportType> -op <optionsString> -ea $theFile;

As a real-world example:

string $exportType = "OBJexport";
string $optionsString = `optionVar -q OBJexportOptions`;
string $theFile = "D:/AW/user/projects/foo.obj";

file -typ $exportType -op $optionsString -ea $theFile;

For "Export Selected":

file -typ <exportType> -op <optionsString> -es $theFile;

In my experience, the OBJexport file translator makes no distinction between Export All and Export Selected -- it always assumes an Export All. Of course, your in-house Exporters will be smarter than this, right?

Armed with this information you are able to use the options as defined in the Exporter panel. But what if you want to define them yourself?

Firstly, you will need to know the names of all of the options. Secondly, you will need to know what values are valid for its corresponding name. These can be gleaned in one of two ways:

  1. Echo the optionVar ($optionsString above) and pick out the name of each option. Some names may make their purpose obvious and you'll be able to judge what their value means (on/off values, for instance). Others may require some educated guessing.

  2. Load up the MEL script responsible for generating these options (the "Options" MEL script described above) and determine what option names are used, their purpose, and their range of values.

The latter of these two will provide a more complete assessment of the options and how each's corresponding value is derived.

Tuesday, July 17, 2001