Ok, I think I got this working now.
The sys.exit() did end up sending data over from Maya, but again this data was returned 1) As a string I’d have to decode and 2) along with some other spew from mayapy.exe which I didn’t really want and 3) classified as an ‘error’ which I felt would be confusing down the road.
What I ended up finding while googling your suggestions is the cPickle module.
I use subprocess to call mayapy.exe from MoBu, passing a python file as the argument. The python file (argument) performs the Maya query, then pickles the results to a text file on disk. I then read the pickle output into MoBu. Now I have all the data I need, in the exact data construct my Maya python file collected. Also cool to note, is that since Maya uses mayapy.exe as a middle-man, I am able to communicate between two different versions of python (2.6 —> 2.5 --> 2.6).
Here are some example supporting files to demonstrate. (I haven’t implemented them fully, but they should hopefully demonstrate where I’m going with this):
MoBu_Requst.py
'''
Example: Send a query to Maya using mayapy.exe from MoBu
'''
import os, subprocess
# apparently this is necessary with Maya 2009 according to the internets
os.chdir('C:/Program Files/Autodesk/Maya2009/bin')
# Call MayaTest.test() from MoBu through subprocess
mayapy = subprocess.Popen(["C:/Program Files/Autodesk/Maya2009/bin/mayapy.exe", "c:/scripts/MayaTest.py"],stderr=subprocess.PIPE, stdout=subprocess.PIPE)
output, errors = mayapy.communicate()
MayaTest.py
'''
Example: Opens a specific Maya file containing some joints. All joints in the
file are picked to c:/mayapy_outfile.txt
'''
import cPickle
import maya.standalone
maya.standalone.initialize( name='python' )
import maya.cmds as cmds
def test():
cmds.file( 'c:/Test/JointTest.mb', o=True)
uResult = cmds.ls( type='joint' )
sResult = [str(r) for r in uResult]
FILE = open("c:/mayapy_output.txt", 'w')
cPickle.dump( sResult, FILE )
FILE.close()
if __name__ == "__main__":
test()
MoBu_Decode.py
'''
Example: Loads the pickeled results from Mobu_Request into a
variable named results
'''
import cPickle
results = []
FILE = open("c:/mayapy_output.txt", 'r')
results = cPickle.load(FILE)
FILE.close
print results
Thanks everyone for their help. If anyone has any comments on this, do share!
-csa