python with maya batch

661 views
Skip to first unread message

tomas mikulak

unread,
Sep 26, 2022, 2:37:32 PM9/26/22
to python_in...@googlegroups.com
Hi, 
I have a question about running python script on maya file opened with batch mode. 
So far I was calling mel that ran python, but now I see more simpler solution with python. 
let's say a want to open a file d:\test.ma and run a python script on it called fixIt.py that has def whatTo(name, fixName)

So I need to pass some arguments to this definition under script. 

so the syntax should be:
"c:\Program Files\Autodesk\Maya2018\bin\mayabatch" -batch -file "D:test.ma" -command " "

thanks, 
tomas

Marcus Ottosson

unread,
Sep 26, 2022, 5:56:10 PM9/26/22
to python_in...@googlegroups.com

If I was you, I’d turn that around.

  1. Run script
  2. Script opens file

For example.

fixIt.py

# Gain access to maya.cmds
from maya import standalone
standalone.initialize()

# Use maya.cmds to do magic
from maya import cmds
cmds.file("d:/test.ma", open=True)
print("Fixing it")

That you could run as such:

"c:\program files\autodesk\maya2023\bin\mayapy.exe" "d:/fixIt.py"

--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAEUzAD19O%3DZ8-7LnmSfp1-b0FzvBLfAREjzcLkXaktsvUOd-_A%40mail.gmail.com.

tomas mikulak

unread,
Sep 26, 2022, 6:08:59 PM9/26/22
to python_in...@googlegroups.com
Thanks for idea,
my need is more complex. I will use folder as an input. drag drop it on bat file that points to python script. in structure dropped I will find all files based on structure position those will be written into separate batch commands into new bat file that runs after creation. and to this step I need to assign python commands with arguments. 

this is working I use it just I use mel as mid step

I just need to get the right syntax 
-command “import fixIt; fixIt.whatTo(\”cat\”,\”dog\”)”

tomas mikulak

unread,
Sep 27, 2022, 8:19:48 PM9/27/22
to python_in...@googlegroups.com
Hi Marcus,
I finally got over with it. all those stages, what you have to write, because it will be written to bat file and that has to work in maya is time consuming for me. but this is the final syntax
-command "python(""import layoutRead""); python(""layoutRead.readData("\\\\\\""'+mc.ls(sl=True)[1]+'"\\\\\\"","\\\\\\""'+scene+'"\\\\\\"")"");"


in bat file :
-command "python(""import layoutRead""); python(""layoutRead.readData("\\\""SH010_temp"\\\"","\\\""Z:/WEBSTEROVCI/work/E_20/SQ011/layout/publish/websterovci_SQ011_layout_v014.ma"\\\"")"");"


thank yo for your time,
tomas

ut 27. 9. 2022 o 0:08 tomas mikulak <mikula...@gmail.com> napísal(a):

Marcus Ottosson

unread,
Sep 28, 2022, 3:30:28 AM9/28/22
to python_in...@googlegroups.com
I really think you should reconsider the approach I suggested; you can accomplish absolutely everything from Python, including dropping a folder with files for automation and it'd be a lot more readable and maintainable than what you've got there.

tomas mikulak

unread,
Sep 28, 2022, 3:48:36 AM9/28/22
to python_in...@googlegroups.com
but I use python to make all it work. now i finally managed to do it from one module. It still is not pythonist clean but it makes me satisfied a could detour mel, even if batch mode only accepts mel commands I can call python just mel way.
I will grow and understand it more hopefully. but for me nocoder is this a smart step,
thanks,
tomas

Reply all
Reply to author
Forward
0 new messages