maya.standalone

82 views
Skip to first unread message

tomas mikulak

unread,
May 23, 2019, 6:26:50 PM5/23/19
to python_in...@googlegroups.com

Hi everyone,
could somebody help me with running script with argument(path) to save new file maya standalone will create and save it to given location and all that from maya.
I wrote simple python script that takes path argument and when I do it manually openning cmd and typing mayapy path\\script.py -p “c:\\”
it works and creates simple scene with sphere named test on c drive
but I can’t figure it out how to run it from maya.
this is just concept what I need standalone to do.
batchMaya.py

Justin Israel

unread,
May 23, 2019, 6:45:47 PM5/23/19
to python_in...@googlegroups.com
Are you saying that you are seeing failures when you run it from Maya? Or that you don't know how to execute it from Maya? If its a matter of how to even run the script, you would go about that using the 'subprocess' module:

import subprocess
exitcode = subprocess.call(["mayapy", "/path/to/script.py", "-p", "c:\\"]) 

See:

--
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/CAEUzAD282xN-WZq2nGN%2BUn9fZGyd6ZGNNJ%3DBNdwJEjcWz34C_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

tomas mikulak

unread,
May 24, 2019, 12:56:52 AM5/24/19
to python_in...@googlegroups.com
I used subprocess but it didn’t create a file. and it gave me error wrong path, now I see a light there, I put -p “c:\\” as one argument and you separated it, I will give it a try, thanks

tomas mikulak

unread,
May 24, 2019, 1:12:46 AM5/24/19
to python_in...@googlegroups.com
no still nothing.

here is how I try to run it from maya


import maya.cmds as mc
import os
import subprocess
import sys

mp = 'c:\Program Files\Autodesk\Maya2016.5\bin\mayapy.exe'

function = '\\discobolos1\websters\install\MAYA_SCRIPTS\PYTHON\batchMaya.py'

print(function)
arg = ' -p '
arg2 = '"c:\\"'
print(arg)
print(command)


subprocess.call([mp,function,arg,arg2])


if I run subprocess.call([mp]) it runs mayapy su I know it is not all wrong, but I have tried many \ or \\ variations for paths and it always ends with Result:2 in maya and no file is created




pi 24. 5. 2019 o 6:56 tomas mikulak <mikula...@gmail.com> napísal(a):

Justin Israel

unread,
May 24, 2019, 2:07:17 AM5/24/19
to python_in...@googlegroups.com
It is much easier if you just stick with forward slashing for your paths, which will work fine in Windows as far as I know:

mp = 'c:/Program Files/Autodesk/Maya2016.5/bin/mayapy.exe'
function = '//discobolos1/websters/install/MAYA_SCRIPTS/PYTHON/batchMaya.py'

I'm not really sure about the first part of the function. Is that a network path? Do you get any errors in your console/shell?

Justin Israel

unread,
May 24, 2019, 2:11:50 AM5/24/19
to python_in...@googlegroups.com
On Fri, May 24, 2019 at 6:07 PM Justin Israel <justin...@gmail.com> wrote:
It is much easier if you just stick with forward slashing for your paths, which will work fine in Windows as far as I know:

mp = 'c:/Program Files/Autodesk/Maya2016.5/bin/mayapy.exe'
function = '//discobolos1/websters/install/MAYA_SCRIPTS/PYTHON/batchMaya.py'

I'm not really sure about the first part of the function. Is that a network path? Do you get any errors in your console/shell?

I'm still not fully clear if UNC paths can use forward slashes or not, but if you want to try with backslashes, you need to remember to use a raw string, otherwise you would have to double escape the backslashes:

mp = r'c:\Program Files\Autodesk\Maya2016.5\bin\mayapy.exe'
function = r'\\discobolos1\websters\install\MAYA_SCRIPTS\PYTHON\batchMaya.py'
 
Note the r character in front of the string which means python won't interpret the backslashes.

tomas mikulak

unread,
May 24, 2019, 2:22:43 AM5/24/19
to python_in...@googlegroups.com
no error now, before I got error about path don’t exist. I might just save script on c:/ to see if that was some path problem or what, it is just frustraiting.

Marcus Ottosson

unread,
May 24, 2019, 2:45:17 AM5/24/19
to python_in...@googlegroups.com

The path didn’t exist because, as Justin mentioned, Python interpreted those backslashes to make “escape characters”.

path = '\\discobolos1\websters\install\MAYA_SCRIPTS\PYTHON\batchMaya.py'  
raw_path = r'\\discobolos1\websters\install\MAYA_SCRIPTS\PYTHON\batchMaya.py'

print("path: %s" % path)
print("raw_path: %s" % raw_path)

# path: \discobolos1\websters\install\MAYA_SCRIPTS\PYTHOatchMaya.py
# raw_path: \\discobolos1\websters\install\MAYA_SCRIPTS\PYTHON\batchMaya.py

Note the PYTHONOathMaya.py, that’s what Python was looking for because \b got converted into O.


tomas mikulak

unread,
May 24, 2019, 2:54:34 AM5/24/19
to python_in...@googlegroups.com
ok, 
I changed backslash to forward slash 
import maya.cmds as mc
import os
import subprocess
import sys

mp = 'c://Program Files//Autodesk//Maya2016.5//bin//mayapy.exe'
function = 'c://batchMaya.py'
arg = ' -p '
arg2 = 'c://'

subprocess.call([mp,function,arg,arg2])

even version like this


import maya.cmds as mc
import os
import subprocess
import sys

mp = r'c:/Program Files/Autodesk/Maya2016.5/bin/mayapy.exe'
function = r'c:/batchMaya.py'
arg = ' -p '
arg2 = r'c:/'



subprocess.call([mp,function,arg,arg2])

no file created.

pi 24. 5. 2019 o 8:45 Marcus Ottosson <konstr...@gmail.com> napísal(a):

tomas mikulak

unread,
May 25, 2019, 2:47:36 PM5/25/19
to python_in...@googlegroups.com
could somebody just run my script with any path to prove me I can’t do simple things, thanks

tomas mikulak

unread,
May 26, 2019, 7:36:58 PM5/26/19
to python_in...@googlegroups.com
I have some progress, I put variable name and path to one arrgument and it is tryint to work now, but it starts to complain about path again and I don't know why it is trying to save to default scenes


so 25. 5. 2019 o 20:47 tomas mikulak <mikula...@gmail.com> napísal(a):
mayaBatch.jpg

tomas mikulak

unread,
May 26, 2019, 8:44:15 PM5/26/19
to python_in...@googlegroups.com
ok, I finally made it, I had to use another set of brackets for argument
a=subprocess.Popen([mp ,function, [' -p \"c:\\ \"']],stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
I also found out how to print to maya console when it breaks,

thanks guys, very much appreciated,

tomas

ne 26. 5. 2019 o 1:42 tomas mikulak <mikula...@gmail.com> napísal(a):

Justin Israel

unread,
May 26, 2019, 9:29:22 PM5/26/19
to python_in...@googlegroups.com
On Mon, May 27, 2019 at 12:44 PM tomas mikulak <mikula...@gmail.com> wrote:
ok, I finally made it, I had to use another set of brackets for argument
a=subprocess.Popen([mp ,function, [' -p \"c:\\ \"']],stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

Say whaaat? How does that not result in an exception when you try to pass a list as one of the args in the command? Is this a Windows specific thing? It is definitely not portable for Linux:

    >>> subprocess.call(['echo', ['test']])
    TypeError: execv() arg 2 must contain only string

 
Reply all
Reply to author
Forward
0 new messages