Message 1 of 7
How to wait for maya to finish loading after calling maya.exe with subprocess.Popen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
Im calling maya.exe with subprocess.Popen()
and i cant figure out how to wait for maya to finish loading before sending it commands.
currently it either waits for maya to close to continue to the next line of code,
or I have it open a socket and based on the stdout feedback i just check if "Device is available" is in the print out ( last readout has it in there..)
I know im stictching this together pretty sloppily, but Im trying to learn how to call maya outside of maya, but still be able to talk to it.
If anyone has good resources how to accomplish this, i would appreciate the feedback.
Thanks
import shlex
import subprocess
cmd = r'''"C:/Program Files/Autodesk/Maya2018/bin/maya.exe" -noAutoloadPlugins -command "commandPort -n \":7333\" -stp \"python\";"'''
args = shlex.split(cmd)
print(args)
process = subprocess.Popen(args, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
output = process.stdout.readline()
if process.poll() is not None:
break
if output:
print(output.strip())
if "Device is available" in str(output.strip()):
maya = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
maya.connect(('localhost', 7333))
maya.send('import maya.cmds as cmds;cmds.file("{0}", o=True, f=True);'.format(asset_cln_ver).encode('utf-8'))
# Actions that require maya UI and not mayapy.exe
maya.send('cmds.file(rename="{0}");cmds.file(save=True,type="mayaAscii")'.format(asset_cln_top).encode('utf-8'))
maya.close()
rc = process.poll()