FBX Exporting from Maya

I am currently working on a tool for my production. This tool includes an FBX exporter using two presets, one for a skeletalMesh and one for animation on that skeletalMesh. What this tool will do is allow the animator (or tech-artist) to export their animation using a click of a button rather than have to go into the FBX exporter function inside of Maya. The same can be said for the skeletalMesh.

I currently see there are two options. Either load “preset files” which I have already placed in a special location on PerForce. I can load the script on my computer using the following code:
pm.mel.eval(‘FBXLoadExportPresetFile -f “E:/PerForce/WorkSpace/UE4/HGGame/ArtScripts/Maya/Animation.fbxexportpreset”;’)

As a note, I have tried to make a straight pymel command but am returned with this error:

Error: RuntimeError: file <string> line 2: FBXLoadExportPresetFile: Error bad syntax.

Use syntax: FBXLoadExportPresetFile -f “filepath” #

The issue with the above MEL code is that my team’s file path to PerForce are all different. I want to use $ so that we can replace the E:/ and have Maya automatically locate the file it needs. Replacing any relevant pieces of the filepath returns:
// Error: Preset file not found. //
// Error: $perforce\UE4\HGGame\ArtScripts\Maya\Animation.fbxexportpreset //

Error: MelError: file C:\Program Files\Autodesk\Maya2014\Python\lib\site-packages\pymel\core\language.py line 846: Error during execution of MEL script: Preset file not found.

So obviously it is not looking for the correct location. Does anyone know how I can use a variable so that we can find the file across multiple platforms?

Also, if the above cannot be done, my other option is to find every single line of code that is needed to export the different types of files I am looking for. This would take a lot longer and would be far worse to look at, code wise, as it could theoretically add several hundred lines of code. If needed, I can do this but it would take a lot more time.

I’d just set the options in code personally. There aren’t actually that many settings you’ll need to modify. I’ve done this kind of thing before as part of export automations for Unreal, Unity and a couple of others and it’s usually only about 7 lines of code on average.

So you’d just do something like this:


pm.mel.eval('FBXResetExport') # This ensures the user's settings are ignored so that you can just set values which differ from the default
pm.mel.eval('FBXExportInputConnections -v 0')
pm.mel.eval('FBXExportBakeComplexAnimation -v 1')
# ... etc.

# And then export
pm.mel.eval('FBXExport -f "%s" -s' % outFilePath)

One benefit of setting them from code is that it doesn’t alter the user’s settings. So the next time the user goes to export something via the normal file>export method their settings will be the same as they had them last.

1 Like

Would I have to edit every single option out there or would I just need the stuff I need changed from default?

Also,

pm.mel.eval(‘FBXExportSkeleton -v 1’) does not seem to work but apparently is not needed?

Lastly,

How would I change the location to work for multiple work stations?

I generally don’t allow users to do ‘raw’ fbx exports into game data - there are too many things they might mess up – but I don’t care what they do if they are making an FBX outside the game.

My exporter loads the export preset appropriate to a given file and exports it. I distribute my fbx presets as data (along with things like icon bitmaps or binaries) and access them them that way. I prefer this to doing it in code because the presets will force all the settings in one go, so I don’t have to worry about the state a user might have left things in when I wasn’t looking.

FWIW, here’s a link to the wrapper I use to avoid all the mel garbage:

1 Like

PS it looks like your error might be related to some other code that is expanding an environment variable on your machine but not on somebody else’s: if you have a PERFORCE environment variable set to “E:\Perforce” and the other user does not, running os.expandvars on your machine would give a valid string but would produce the error you listed for a user who didnt have PERFORCE set correctly

That is pretty cool Theodox! How would I load your code so I can use Python or Pymel instead of mel?

Also, my company is exporting as fbx and importing into UE4 then saving out the .ueasset for later use.

Regarding the Perforce Environment variable, I just recently joined the team and don’t have much experience in dealing with sort of thing (yet). I don’t know what/if we have for an environment variable but I will definitely look into os.expandvars!


import FBXWrapper as fbxw
fbxw.FBXExport (f = 'your_file_name_here')

named python flags get turned into mel flags, unflagged arguments are passed through.

As for the other part, if people have different paths you’ll need to make sure that everybody has an enviroment variable set which points at their perforce root. os.environ[‘PERFORCE’] will find it for you, your code should just complain and tell the user to set it properly before running the tool.

https://www.inkling.com/read/programming-python-mark-lutz-4th/chapter-3/shell-environment-variables

Thanks again Theodox! If I have further issues, I’ll continue to post here!