FBX Export Scripting

We do the majority of our exports from Maya to Unity as FBXs and the export process needs to be integrated into our tools both for individual file export and batch exporting purposes. This meant using the FBX UI within Maya to manually set export options was out and we needed another method to apply consistent settings to various types of exports such as animations or static props.

FBX Presets

Initially the use of FBX presets seemed like a good answer; within Maya you open the FBX export window, specify some options and save out a preset which you can then apply to later exports. We used this option for a while, however ultimately discarded it for a few reasons:

  1. It created extra files to manage.

  2. You had to open Maya and load the preset to see what the settings were.

  3. It required setting paths in Maya’s ENV variables in order to be found.

FBXProperties

The downsides with FBX presets led us to look into more direct application of settings via the various MEL commands that were available. This seemed very promising initially; we could apply the settings we wanted and have all the scripting contained in our python files. Quickly we ran into another problem with this though; not all the FBX properties have an associated MEL command; so how to get at these?

The search ended with the discovery of the “FBXProperties” command which allows you to see all the properties for an FBX export.

Partial FBXProperties result

// PATH: Export|AdvOptGrp|UI|ShowWarningsManager ( TYPE: Bool ) ( VALUE: "true" ) //
// PATH: Export|AdvOptGrp|UI|GenerateLogData ( TYPE: Bool ) ( VALUE: "true" ) //
// PATH: Export|AdvOptGrp|FileFormat|Obj|Triangulate ( TYPE: Bool ) ( VALUE: "true" ) //
// PATH: Export|AdvOptGrp|FileFormat|Obj|Deformation ( TYPE: Bool ) ( VALUE: "true" ) //
// PATH: Export|AdvOptGrp|Fbx|AsciiFbx ( TYPE: Enum ) ( VALUE: "Binary" ) (POSSIBLE VALUES: "Binary" "ASCII" ) //
// PATH: Export|AdvOptGrp|Fbx|ExportFileVersion ( TYPE: Alias ) ( VALUE: "FBX201200" ) (POSSIBLE VALUES: "FBX201200" "FBX201100" "FBX201000" "FBX200900" "FBX200611" ) //

Armed with this command we took all the information that it outputs and input it into a large PyMEL dictionary so we could easily manipulate it. Unfortunately this is a mostly manual process since FBX Properties only prints out values in the script editor instead of returning them in a useful format like a list.

Example dictionary entry:

'advanced_fbx_exportFileVersion' : {
    'v' : 'FBX201100',
    'fbxProperty' : 'Export|AdvOptGrp|Fbx|ExportFileVersion',
    'melScriptingCommand' : 'FBXExportFileVersion',}

To create our own ‘preset’ settings we simply created functions which manipulate the values in the dictionary.

example 'preset' function

def _someSettings(self):   
self.fbxExportSettingsDict['include_animation']['v'] = 'false'    
self.fbxExportSettingsDict['include_camera']['v'] = 'false'    
self.fbxExportSettingsDict['include_embedTexture']['v'] = 'false'    
self.fbxExportSettingsDict['include_light']['v'] = 'false'Export

Export

When it comes time to export, which we perform with the standard “FBXExport” command, we apply the values in the dictionary to the actual FBX export settings via a running of the “FBXProperty” command across all the items in the dictionary.settings application function

for s in self.fbxExportSettingsDict.keys():
    pm.mel.eval('FBXProperty '+self.fbxExportSettingsDict[s]'fbxProperty']+' -v ' + self.fbxExportSettingsDict[s]['v'])

The application of settings in this manner works smoothly except with the case of the “FBXExportFileVersion” property which behaves differently because it is an aliased attribute. So for expediency I special cased this.

Conclusion

It was somewhat tedious work to set up this system but gives us a number of benefits:

  • A single unified way to set all FBX export settings.

  • A place to gather information about a given property in one place; MEL command it relates to, possible values and documention of its’ effect.

  • Avoids confusingly named MEL commands.

  • Avoids MEL commands which operate in a variety of different ways.

  • Full control over every aspect of FBX export.

The downsides are:

  • If we update FBX versions we need to manually update our dictionary.

  • We are doing things a bit outside the ‘standard’ way which often leads to unforeseen issues.