View Full Version : trying to execute python script with mayapy to retrieve data from maya scene file

12 December 2012, 09:30 PM
So I am trying to run the method below from python script [ (] and read data returned by it using mayapy but don't know why i am not getting the correct result even if the logic seems to be right..

def readFile(self):
## call to using mayapy.exe interpreter
code_str = \
import readMayaFile
# save the code
fout = open(filename, "w")
# execute the code with mayapy and pipe the result to a string
mayapy="D:/Program Files/Autodesk/Maya2013/bin/mayapy.exe"
test = mayapy+" " + filename
process = subprocess.Popen(test, shell=True, stdout=subprocess.PIPE)
print process.returncode,"<" # 0 = success, optional check
# read the result to a string
strRead =
print strRead

the contains :

#mapay interprer file
import os
import maya.standalone
import maya.cmds as cmds

def getCams(phileToOpen):
cmds.file(phileToOpen, force=True,open=True)"camera")
return cams
Can anyone please help me figure out what am I doing wrong in the implementing the logic in readFile() method ?

12 December 2012, 05:00 AM
I haven't tried running your code but is it reporting an error?

If you are expecting a list of cameras then what are the incorrect results it's returning?

12 December 2012, 05:07 PM
wasnt giving an error , but since you are too late to reply i figured it out a while back..

it is supposed to be sys.stdout.write(data) to to pipe out data to back to UI

CGTalk Moderation
12 December 2012, 05:07 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.