Execute GameFbxExporter Maya with Python

Viewed 2615

I need to export thousand of files with the GameFbXExporter Plugin from Maya, and I was wondering if there was any way to script those exports, knowing that the parameters are fine in every files. All I need to do is fill the path section and the name of the exported file in FBX, then launching the export itself with the plugin.

I'm kind of lost and doesn't know how to do this. Could someone help me understand how to reach that please?

Thank you

1 Answers

The game exporter is written in MEL, so you can interact with it from Python using the maya.mel module. This will open the dialog, for example:

import maya.mel as mel
mel.eval("gameFbxExporter();")

Unfortunately a quick look at the actual game exporter scripts (which are in your maya install directory in the scripts/others directory -- they all start with the prefix "gameFBX") make it look like the UI is hopelessly entangled with the actual act of exporting; it doesn't seem to expose anything which actually just exports the current file in a batch friendly way.

The operative procedure is called gameExp_FBXExport, defined in "gameFbxExporter.mel." It appears like the actual business of exporting is actually delegated to the regular FBX plugin -- all the other stuff in the game exporter is just managing fbx presets, selecting parts of the scene to export (if you have the scenes set that way) and then calling the fbx plugin. So, you may be able to batch the process using Python by looping over your files and calling FBXExport() from Python. This will export file to FBX:

 import maya.cmds as cmds
 cmds.FBXExport('-file', 'path/to/file.fbx')

It will just use whatever FBX settings are currently active, so you will need to be confident that the files are correctly set up. You'll be tempted to write it as cmds.FBXExport(f='path/to/file') but that won't work -- the FBX plugin commands don't use regular python syntax.

If your current settings rely on the export-selected functionality you'll need to figure out how to cache the correct selections -- if you're using the "export selections set" functionality you should be able to have your exporter find the set by name and the select it before exporting.

 cmds.select("name_of_selection_set")
 cmds.FBXExport('-file', 'path/to/file.fbx')

You can use the other FBX plugin commands -- documented here to inspect and manipulate the settings in your files as you go along.

Most professional users don't use the GameExport pipeline precisely because it's very opaque and not batch friendly. In the long run you'll probably want to write a simple system that provides standard settings for different file types and exports the FBXes directly without the GameExporter - while it's a not-trivial project it's going to be easier to maintain and expand than hacking your way around the edges of Autodesk's version which is, frankly, pretty lame.

If you're not already familiar with it http://tech-artists.org/ is a great place to look for pipeline help and advice.

Related