FBX Exporting, Batching files and Maya Python

Hello again everyone!

I’ve a question regarding FBXExport and batching through files.

We’re using FBX as our standard animation format, which is great when we need to export from one file. However, I’m finding very little online about a problem I’ve encountered batching through several files using the FBXExport commands in python.

The problem I’m having is that the FBXexport command seems to be deferred until the final file in a loop, and then it runs on that file the number of times the loop iterated. My sample code is below.

I understand this is because Maya does not wait for FBX to return a result or process (and as far as i can see the FBX plugin does not return a result/process anyway.) So it fires off the FBXExport command, then moves to the next loop iteration. Meanwhile the FBX exporter has not initialized, and so waits till all files have looped through, initializes, and runs a bunch of times.

I have two questions about this, if anyone can answer.

1: Has anyone found a way to avoid this behavior? Is there a flag or setting I’m missing that will wait to open the next file until the exporter has initialized and run? Am I going about this all wrong?

2: If not, how do you guys and gals work around this? Currently I’m working on writing a log file out once the export is finished, then reading said log file to see if the export has in fact finished. If not, then go to a wait loop. If so, move to the next file in the loop dir. This has not worked out as well for me just yet, and I’d prefer a cleaner solution.

I’ve also tried deferring the export, and that does not seem to work either.

Any suggestions? Or has anyone solved this problem already and want to give me some hints?

Thanks!

-ian



import maya.cmds as cmds
import maya.mel as mel

#find all files in given dir using utility function
tList = batch.findFiles("C:	argetDirectory")

for t in tList:

    #open the file
    cmds.file(t, o = True, f = True)

    #find the filename
    filename = cmds.file(q = True, sn = True)

    #build the fbx filename
    filename = filename.replace('.mb','.fbx')

    # select the root bone in the scene
    cmds.select("Root")

    # select all joints in the hierarchy
    jointHierarchy = cmds.select(cmds.ls(dag = 1, sl = 1, type = 'joint'))

    # Export the given fbx filename
    mel.eval(('FBXExport -f \"{}\" -s').format(filename))


Could the problem be that you are using mel.eval, rather than using maya.cmds file(filename, exportSelected=True, type=“FBX export”) ?

That seems to do it.

I’d tried exporting using



cmds.file(filename, es = True, type = "FBX")


previously, but would get an error to the effect of ‘Use FBXExport, not file export’. The assumption I was working under was that there was only one FBX type for exporting. I suppose I was wrong.

Thank you very much! This will save me a great deal of time!

-ian