Search code examples
command-line-argumentsmaya

Batch run maya with last recent file


I try to make a batch file that basically opens all the stuff I need to work. Opening Maya is quite simple, but there's one step further i'd like to do: make it open my last opened file. if i understand the doc Start Maya from the command line

I could try this:

path/to/maya.exe -command [some MEL commands that may open the last opened file]

But I have no clue how to MEL and I guess for it to work as a windows batch I must keep it as one command line. I try to read the docs but I fail to find anything I can make use of.

python("recent = cmds.optionVar(q='RecentFilesList')[-1]; cmds.file (recent, force=True, open=True)")

Issues:

  • I can't find a way to correctly parse the quote marks through batch to Maya.
  • The file command requires to first save the file to work...

Solutions

Thanks to this answer:

  • use force=Truein cmds.file (recent, force=True, open=True) to force the file command to work without the need to save the file first
  • use one backslash \ before the commands " to properly parse them to Maya
"path\to\maya.exe" -command "python(\"recent=cmds.optionVar(q='RecentFilesList')[-1]; cmds.file (recent, force=True, open=True)\")"

Solution

    1. Usually you replace a " with a \" to get a working mel command. So if you this could work:

      "python(\"recent = cmds.optionVar(q='RecentFilesList')[-1]; cmds.file (recent, open=True)\")"

    But to be honest I did not test it as a commandline argument.

    1. You can modify the file command with force:

      cmds.file(recent, force=True, open=True)