Problem doing an FBX export with PyMEL

Im using the pymel.core.mel -class in order to run a command only available in MEL, but it whines at my syntax and the official docs are of no help:

import pymel.core as pm
myPath = "C:\Users\Martin\Desktop\lolk\mrlolk.fbx"
pm.mel.FBXExport(filename=myPath, s=True)

Doc on the MEL command: http://download.autodesk.com/global/docs/maya2014/en_us/index.html?url=files/GUID-E85FCD1E-57BE-48FF-9D46-ED64091562B1.htm,topicNumber=d30e145806
Doc on pymel.core.mel: http://download.autodesk.com/us/maya/2011help/PyMel/generated/classes/pymel.core.language/pymel.core.language.Mel.html

It’s been a long time since I’ve tried, but I could never get the PyMel version to work. Just used the MEL command as a string wrapped up by eval or something.

It is not surprising that this command doesn’t work with PyMel or maya.cmds. Its not an official part of maya’s core. Its an external plugin that was integrated. As with an external plugin, its hit-or-miss how well it integrates into maya.

Try something like:

pm.FBXExport("-file", <path>)

just verified that this works, nice one!

cmds.FBXExport('-file', 'C:/temp/test.fbx', '-s')

i tried using the fbx splugin properly and never could get it to fly. I ended up just using the FBXExport as mentioned. Was this a half assed plugin or half assed documentation?

Doesn’t seem to work for me

import maya.cmds as cmds
cmds.FBXExport('-file', 'C:/temp/test.fbx', '-s')

Error: line 1: Cannot find procedure “OneClickGetContactingAppName”.

Traceback (most recent call last):

File “<maya console>”, line 2, in <module>

File “<string>”, line 2, in FBXExport

RuntimeError: line 1: Cannot find procedure “OneClickGetContactingAppName”.

I should note, I did my test in 2015 service pack 4.

I’ve been using this successfully for a variety of exporters for awhile now.


filename = 'path_to_export_file'
pm.mel.FBXExport(s=True, f=filename)

I think using the long keyname is probably breaking your original example.

The actual FBXExport mel command only has the short flags, and the pymel mel wrapper is pretty simple, and just does a simple change of key=value into -key value

mel command:
FBXExport -f [filename] [-s];

If you want to export with a bunch of options, you’d do something like this


pm.mel.FBXResetExport()
pm.mel.FBXExportBakeComplexAnimation(v=False)
pm.mel.FBXExportConstraints(v=False)
pm.mel.FBXExportInputConnections(v=False)
pm.mel.FBXExportUseSceneName(v=True)
pm.mel.FBXExportInAscii(v=True)
pm.mel.FBXExportSkins(v=True)
pm.mel.FBXExportShapes(v=True)
pm.mel.FBXExportCameras(v=False)
pm.mel.FBXExportLights(v=False)
pm.mel.FBXExportFileVersion(v='FBX201300')
filename = 'path_to_export_file'
pm.mel.FBXExport(s=True, f=filename)

2 Likes

Okay, great! Finally got it working.
Thanks a bunch guys!

[QUOTE=R.White;25561]I’ve been using this successfully for a variety of exporters for awhile now.


filename = 'path_to_export_file'
pm.mel.FBXExport(s=True, f=filename)

[/QUOTE]

How is this different from the original syntax in the first post?

edit: nvm. reading comprehension fail.

Another question:
Everything is working for me (the FBX files are created in the way I want them created).
But… I get an error:
// Error: line 1: Cannot find procedure “OneClickGetContactingAppName”. //
…which also brings up the Stack Trace window.

I can just supress that error message ofc, but I would like to know why the heck Im getting that false-positive error.

EDIT: Can’t even supress it.
Tried pm.scriptEditorInfo(suppressErrors=True) and I still get the error in the script line + stack trace window

I’ve never gotten that particular error before.
The command looks like it should be tied to the OneClick plugin, but in my Maya 2014 install it isn’t listed as a command on the plugin info panel.
However in 2015 that command does exist on the plugin, and I do get that error if the plugin isn’t loaded. Re-enabling the plugin caused the error to stop, so hopefully that works for you.

So that’s fun, looks like FBXExport has a dependency on OneClick in 2015.

[QUOTE=R.White;25946]I’ve never gotten that particular error before.
The command looks like it should be tied to the OneClick plugin, but in my Maya 2014 install it isn’t listed as a command on the plugin info panel.
However in 2015 that command does exist on the plugin, and I do get that error if the plugin isn’t loaded. Re-enabling the plugin caused the error to stop, so hopefully that works for you.

So that’s fun, looks like FBXExport has a dependency on OneClick in 2015.[/QUOTE]

Great! Activating that plugin in 2015 gets rid of that annoying error message!

FWIW I think that cmds generates a wrapper for the plugin mel commands if they use an MSyntax internally to parse their arguments and flags (I think that’s what MPXCommand.hasSyntax() is there for). However if you just roll your own and interpret the MArgList directly in your doIt() method, cmds doesn’t know what to do. So I think FBX is doing it the lazy way, which is why it works with the string series ("-f", “filename”) but not the usual f=filename.

I didn’t realize until I looked into this recently that cmds automatically creates a wrapper for all plugin-derived mel at startup (subject to the note above). So, you can call cmds.FBXExport() or whatever but there’s a certain level of randomness in how complete the automatic wrapper is.

Related: http://techartsurvival.blogspot.com/2014/10/laziness-and-cleanliness-and-mel-oh-my.html includes some code for a wrapper that lets you write for usual syntax even when the plugin is busted a la FBX