Launching python script through command prompt using the -script flag

2,055 views
Skip to first unread message

Michael Graessle

unread,
Aug 15, 2008, 7:52:14 PM8/15/08
to python_in...@googlegroups.com
I was curious about if anyone knew of a way to launch a python script using the -script flag, such as when you launch maya.exe from the command prompt.  For example C:\Program Files\Autodesk\Maya2008\bin\maya.exe -script myscript.py.  I have done this using mel scripts, and even python scripts run when Maya is launched this way; however, the python script is I believe being run as a mel script, which is causing Maya to not recongize the commands.  Is there a way to get around this or another flag to use.  Any help or ideas would be appreciated.

thanks,

Michael

Ofer Koren

unread,
Aug 16, 2008, 3:33:42 AM8/16/08
to python_in...@googlegroups.com
It's a bit dirty, but you can run another mel script that will run your python script.
There's also the -command flag that you can feed with a command directly, as in:

maya.exe -command python("print 'Hello World'")

John Creson

unread,
Aug 16, 2008, 4:28:12 AM8/16/08
to python_in...@googlegroups.com
maya.exe -command python("import myScript;myScript.myFunction()")

John Creson

unread,
Aug 16, 2008, 4:36:14 AM8/16/08
to python_in...@googlegroups.com
Actually, the import will run your script if you have scripted without
functions or have a line in your script that calls your function.

So maybe

maya.exe -command python("import myScript")

will work for you, but it's better to create and call your functions.

Also, if you want to use the pythonScripts script that is in the
devkit/other/PyQt... to build a menu inside Maya with access to your
pythonScripts,
You should name your main function the same as your script (like MEL)

so you might be invoking.

maya.exe -command python("import myScript;myScript.myScript()")

Michael Graessle

unread,
Aug 16, 2008, 2:21:01 PM8/16/08
to python_in...@googlegroups.com
Thanks!  I think that running the python script through a mel script should work.  I was thinking about trying something similar as well.
Reply all
Reply to author
Forward
0 new messages