Exporting .ma file to FBX in command line(Mac OS : Maya 2013:MEL scrpts/Python)

hi,

My setUp - Mac OS X, Maya 2013

1)I have a lot of Maya files of extension .ma and I am going to write a script to export all of them to FBX format.

2)And for some of the files, I want particular selections to be exported from each file. So, certain parameters need to be passed to the command line I guess.

My initial thought was to call subprocess.Popen constructor to create a child process which does the conversion for each .ma file coming out of a list of .ma files. but I got another suggestion that involving the pYTHON script through mayapy and the below code was suggested:

basic psuedo-code:
CODE:

import maya.standalone
import maya.cmds as cmds
import maya.mel as mm
import glob

maya.standalone.initialize( name=‘python’ )

def exportFBX():
for f in glob.iglob("/chosenDir//.ma"):
cmds.file (f, force=True, open=True)
#Insert any filter code here
mm.eval(“FBXExport -f %s.fbx;”%(f.rpartition(’.ma’)[0]))

exportFBX()

To run : mayapy this.py

##############
The initial goal was :
Recursively traverse a series of directories

  • Locate all .ma (Maya) files within
  • Export those files to FBX format using varying options depending on the directory path. (animations, models, environments, etc.)
  • The varying options will mostly require particular selections to be exported from each file, but may have FBX-specific settings.

#############

So, even if you tell me the commands to do the export from command line in mAC os x, then I can automate the rocess using blog or os.walk and invoking this command for each .ma file.

Thanks,
Miku

Hi Miku, what do you want to know? It seems you’re on the right track.

[QUOTE=Rob Galanakis;17741]Hi Miku, what do you want to know? It seems you’re on the right track.[/QUOTE]

Hi Rob,

I wanted to invoke the command from subprocess.Popen class for the conversion process.
So, I want the command from MacOS point fo view which exports .ma files to FBX.
Because, I am not comfortable with the other method proposed by my colleague(You can see in my previous post).

Thanks,

You can just launch a maya process with a python script (see the docs on commandline flags), which can import/run some function (‘import mymodule; mymodule.Run()’) to export the fbx files. You’d need to use subprocess.Popen to launch the maya exe, like:
subprocess.call([‘mayabatch.exe’, ‘-script’, ‘“import batchexport;batchexport.Run(%r)”’ % rootfolder])
There are more complex options- so that you could do all your logic in pure-python and then just tell Maya exactly what to do- but they are significantly more complex and not worth it for this case, especially if you’re just starting out with IPC.