PDA

View Full Version : Running Pythonscripts in Maya without the GUI


WouterGilsing
08-14-2012, 08:45 PM
Title says everything I guess.

I've written a Pythonscript and halfway the script I want to call another python script (with maya commands) and run it without opening the mayagui. I need to pass some variables from the main script to the maya script too.

My script does the same thing for Nuke, but I already managed that part of the script:

os.system(pathToNukeApplication+ ' -t nukeScript.py ' + variable1 + ' ' +variable2)

Is it possible to do this for Maya in a simular way? I've been using Pymel and regular python for the mayascript, and I'm currently working on OS X 10.7

Last time I asked a question here, I got some very good advice, very quickly. So thanks in advance!

zoharl
08-15-2012, 05:07 AM
Read this:

http://download.autodesk.com/global/docs/maya2013/en_us/index.html?url=files/Python_Python_from_an_external_interpreter.htm,topicNumber=d30e714204

But I would recommend against a stand-alone app. It's buggy, not fully compatible, and I don't see any benefits compared to running it from the gui. If I had to run it from the outside, at the most I would have used the commandPort() interface to communicate with the gui.

WouterGilsing
08-15-2012, 09:03 AM
Forgot to mention I searched for a solution myself before asking it here on the forums. I found the mayapy thing too. It works fine, but only if I run mayapy and type my code, line for line and execute it line by line, all directly in the mayapyconsole.

That's not what I try to accomplish, I want to make mayapy directly run a script from my HD and execute it. When I tried to do this the way I did it with Nuke, it launched Mayapy and immediately closed it again, without executing the script I told it to execute...

sonicstrawbery
08-15-2012, 12:06 PM
Hi,

I just saved these lines in d:\test.py :

import maya.standalone
import maya.cmds as cmds

maya.standalone.initialize( name='python' )
cmds.file ('D:/test.ma', force=True, open=True)

def createASet():

spheres = cmds.ls('*Sphere*')
cmds.sets(spheres, n='set1')
cmds.file(save=True, force=True)

createASet()

It just creates a basic set with the spheres in the scene.

Then you can launch it in the windows/osx/linux shell :

mayapy d:\test.py

It reads the script and exectues all the actions. Is it what you're looking for ?

Cheers,
Sebastien

zoharl
08-15-2012, 12:56 PM
I'm not familiar with this OS X thingy, but try to find the console (cmd.exe on windows) and run a test script of hello world using mayapy, and see if they environment is configured well. Also you should try the '-E' switch: mayapy -E hello.py

CGTalk Moderation
08-15-2012, 12:56 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.