Export an FBX from Maya using Python

Tutorial / 23 May 2021

There are a fair amount of people out there who have weighed in on how to do this in various forums but I didn't find a single one that actually worked despite them being voted as the solution. Perhaps they worked in previous versions of Maya. I don't know, but I got this solution by sure educated guess, trial and error. This works as of Maya 2018: 


def exportMeshes(*args): 
     nameField = cmds.textField(shipNameTextField, editable = True, query = True, text=True)
     projectDirectory = cmds.workspace(query = True, directory = True) 
     print('The projectDirectory is: ' + str(projectDirectory)) savePath = str(projectDirectory) + nameField cmds.sysFile(savePath, makeDir = True) cmds.file(savePath, exportSelected = True, type = 'FBX')

The code above creates a new folder in your project named by a text field in a form. I didn't include the form. If you need to know how to build a form and query a textfield just search on my site for textfield and you will find info on how to do that. Cheers!

Note, Artstation's janky code format doesn't allow for tabbing, so copy and paste may not work, you may need to re-establish the tabs.