Maya In Batch Mode

1,876 views
Skip to first unread message

PBL_Kiran

unread,
Apr 26, 2011, 2:56:27 AM4/26/11
to python_inside_maya
I just want to know how to open maya in batch mode and perform some
multiple tasks on multiple files...

It should be a standalone application...

Ex : open every file in batch mode and create a sphere and save it.

Shawn Patapoff

unread,
Apr 26, 2011, 12:53:37 PM4/26/11
to python_in...@googlegroups.com

Chad Dombrova

unread,
Apr 26, 2011, 12:58:36 PM4/26/11
to python_in...@googlegroups.com
keep in mind that this example actually differs quite a bit from maya -batch or maya -prompt since it does not initialize any of the mel scripts that maya normally does (no plugins loaded, minimal optionVars, no user prefs, etc).  IMHO, the best way to run a python script that simulates maya -batch is to import pymel.core, although there is some overhead from the extra initialization.  it's also nice because you can write a script that works both in batch mode and in gui mode with no extra code.

-chad


 


On Mon, Apr 25, 2011 at 11:56 PM, PBL_Kiran <pblnra...@gmail.com> wrote:
I just want to know how to open maya in batch mode and perform some
multiple tasks on multiple files...

It should be a standalone application...

Ex : open every file in batch mode and create a sphere and save it.

--
http://groups.google.com/group/python_inside_maya


Chad Dombrova

unread,
Apr 26, 2011, 1:14:32 PM4/26/11
to python_in...@googlegroups.com
had a request for what this would look like using pymel:


import pymel.core as pm
import sys

def main( argv = None ):
        print "Hello world!"
        
if __name__ == "__main__":
    main()


honestly, i have no idea why that example uses MGlobal.executeCommand. by default print goes to sys.stdout. in gui mode sys.stdout goes to the script editor and you must use sys.__stdout__  to write to the console/shell/terminal, but in batch mode everything goes to the shell.


also, if you're on linux or osx you can add this to the top of your file:

#!/usr/bin/env mayapy

then:

chmod 777 myfile.py
 
as long as mayapy is on the PATH you can now execute your script directly like this:

./myfile.py

instead of like this:

mayapy mayfile.py

-chad


-chad

Chad Dombrova

unread,
Apr 26, 2011, 1:18:19 PM4/26/11
to python_in...@googlegroups.com
one more thing: the example forgot to pass along sys.argv:
 
import pymel.core as pm
import sys

def main( *args ):
        print "Hello world!", args
        
if __name__ == "__main__":
    main(sys.argv[1:])

sys.argv[0] is the path of the file being executed exactly how it was executed (i.e. it may look like "../../myfile.py" if that's the path that was passed to python), or if using "python -c" it will contain "-c".

-chad


PBL_Kiran

unread,
Apr 27, 2011, 1:55:56 PM4/27/11
to python_inside_maya
Chad,

I am a bit confused....

Could u just give me script with script filename to execute maya in
batch and create a sphere and save the file.

So that i will just copy the script and save it as prescribed filename
and then execute....

Ex:

Filename : xyz.py

import abc as xyz
...
...
...

wynan...@gmail.com

unread,
May 12, 2017, 4:13:15 AM5/12/17
to Python Programming for Autodesk Maya
yes please!

I really want to get into running maya in batch, so that I can do a procedures to multiple files.
Thanks

Marcus Ottosson

unread,
May 12, 2017, 4:20:16 AM5/12/17
to python_in...@googlegroups.com
What is this in response to? :O


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/967430d1-6f60-48dc-bb06-ecf7da0441dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

wynan...@gmail.com

unread,
May 12, 2017, 5:24:58 AM5/12/17
to Python Programming for Autodesk Maya
I replied to PBLNRAO Kiran.
I have solved my issue to a degree, by running a mel script.

//batchExportFBX.mel

//Get the folder with the animations to process
$folder = "C:/animations/SOURCE/";

//Get the files within that folder
$files = `getFileList -filespec "*.m*"
-folder $folder`;

//check there are files in the folder
if ($files[0] == "") {
error ("There are no animations in " + $folder + " folder!");
}
//Loop through each file in folder
for ($filename in $files){
//Open file
file -open -f -loadReferenceDepth "all" ($folder+$filename);
//RUN ExportFBX.mel on each file
source "c:/Scripts/ExportFBX.mel";
}

I would prefer it to not have to run it through the script editor, as it would be more efficient to not open up maya at all, but I don't know how to do that. please help!
Thanks


Reply all
Reply to author
Forward
0 new messages