Maya.exe with FBXimport from cmd

Hi everyone,

I’d like to find a graceful solution to loading an FBX file to Maya from the command line.

This is what I have right now

maya.exe -command "loadPlugin fbxmaya;FBXImport -f \"c:/test.fbx\";file -rename \"c:/test.fbx\";"

The command opens Maya, imports the FBX, rename’s the scene.

From there I’d ideally like to hit ‘save’, which then ‘exports’ the FBX file to the path specified.

If that isn’t possible, then for now I’ll settle for needing to ‘File > Export’. Problem there is that when you go to export the scene, the path in the file browser isn’t set to the path which I specified in the -rename above.

How can I ensure that the path in the file browser is set to the assets location when using ‘File > Export’ or ‘File > Save’.

Any ideas?

You’re better off throwing 90% of this in a Python or Mel script that does most of the work, then just executing that script from the command line as your -command argument. That way, you can change the script, and not have to worry about the .bat file (or whatever) that you’re using to launch Maya with. You can still pass the name of the file you want to process to the script as part of the args the way you are doing currently. To get Maya to save in a specific location, include that in the file name in the same way you are loading and renaming the file. As far as being able to hit save in Maya itself, and having it go to the correct location, it should work fine so long as you have already saved the file in that location from the script, but you can programmatically play with Maya’s project settings to set them to the correct directory. This leads to all kinds of fairly minor problems, so I don’t recommend it. Oh, and I haven’t played with this stuff in a while, but you are probably still forced to use the export method to get an .fbx file rather than a .ma or .mb. If you want to get into really scary turf, you can hijack Maya’s save hotkey, menu, and button and have them do an export instead, but doing this breaks Maya’s ability to do regular saves when you’re running this way. Who knows, perhaps that is what you want.

Like Brett says- build a python script that, when run inside Maya, does exactly what you want it to do, and then do ‘python(import myscript; myscript.main())’ or whatever the syntax is as your command.

If you want to just open the fbx file, rename it and export it again without actually doing anything to it its probably easier just to copy the file and give it another name :slight_smile: but this is probably not what you want to do.

If you want to do something programatically to the fbx while while it is in maya. its probably best to write a python script that starts up mayaPy.exe and runs your commands and then exports out the file to the new path. using mayabatch doesn’t start up the UI so its faster. The syntax for that is the same as maya.exe

If you want a user to actually do something to the file in maya (something that can not be done in a script, like a review or something like that) thenI would do what btribble and rob suggested. One thing to be aware of though is that you can not save the fbx file. you need to export it. so if you expect that the file needs to be saved between when it is imported to maya and exported, you are going to need to create a temporary maya file somewhere.

This is how i wold do it:

maya.exe -script runMyPythonScript.mel

runMyPythonScript.mel only contains one line of code:

python(“import pyStartup as startup; startup.runFunction()”);

*edit
its actually mayaPy.exe that I was talking about, not mayaBatch.exe :slight_smile: