Initialize maya.standalone from cmd prompt with mayaPyManager

hi,

I am trying to subprocess open mayapy and then open a maya.standalone session, initialize it and then proceed sending commands to the session like opening a maya file and doing stuff. all that from within a cmd prompt in windows.

I used as a base a slightly re-written version of Sebastian Wiesner, and coppled it with some custom ui loader of loading a qt designer file interface where the user can choose path and other stuff.

now inside the class MainWindow I try this:

def initializeMayaFile(self, path):
    self.le_textOut.setText('...initializing Maya scene, please wait')
    pmng = MayaPyManager( r'C:/Program Files/Autodesk/Maya2015/bin/mayapy.exe', 
								None
								)
    self.le_textOut.append (str(pmng))
    pmng.run_module( "maya.standalone")
    self.le_textOut.append ( str(pmng.run_command( "maya.standalone.initialize()" )))

I am not sure if he doesn’t even get to run_module, since it doesn’t return anything. but maybe that’s silenced by mayapy.

that’s my output and errors:

…initializing Maya scene, please wait
<main.MayaPyManager object at 0x00000000032EE8D0>
(‘’, 'Traceback (most recent call last):
File “<string>”, line 1, in <module>
NameError: name 'maya' is not defined
')

anybody any idea if this would even work?
and even if it would work, later with the cmds.file (open) blabla I saw people hacked it by puting a certain time to wait. but since that depends on how heavy the files are. there’s no communication of wait until loaded and stuff?

I remember back in the days it was very easy to do a maya.standalone initialization. but I didn’t have to use mayapy. this time I have to because I need the registered modules there.

maybe someone tried already.

thanks.

What are you trying to do here? Open an interactive python prompt with maya.standalone initialized and a maya scene loaded? MayaPyManager (correct me if I’m wrong here, Theodox) is set up to run modules/commands/scripts and return their output, not to launch an interactive prompt. If you want that I would just call mayapy.exe yourself with a startup script and initialize maya.standalone and open your file. Something like this:

import subprocess
cmd = [MAYAPY_EXE, '-i', startup_script, file_to_open]
subprocess.Popen(cmd, creationflags=subprocess.CREATE_NEW_CONSOLE)

Where startup script does your maya.standalone initialization and opens the argument you passed in.

MayaPyManager is intended for creating and running an isolated mayapy with (if you need it) particular environment variables or other setup instructions. It looks from the code like maybe you’re trying to interact with it after starting it, which is not what it does. The expected use-case would be to create a script which does things (using Maya.standalone and maya.cmds) and then to pass that to the manager, like this:


yourMayaPyMgr = MayaPyManager('path/to/mayapy.exe', None, 'path', v=True)
yourMayaPyMgr.run_script('your_script.py')

you’d want to put the standalone and any other initialization into the script, not pass it the manager as an argument. Running maya.standalone as a module won’t do anything besides importing the module and exiting.


import maya.standalone
maya.standalone.initialize()
import maya.cmds
print cmds.ls()
# do real work here...

into your_script.py

If you’re trying to run maya interactively, you probably want to use the commandPort or you could try something like GitHub - theodox/standaloneRPC: a simple RPC server for controlling a maya.standalone instance remotely

See also the reply on the gist page