PDA

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


DEVILSAN
12-08-2012, 09:30 PM
So I am trying to run the method below from python script [RenderUI.py (http://pastebin.com/9gfYaWRV)] 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 readMayaFile.py using mayapy.exe interpreter
fileToOpen="I:/scenes/san_telus_pan_v009.ma"
code_str = \
"""
import readMayaFile
readMayaFile.getCams("""+fileToOpen+""")
"""
# save the code
phile=os.path.join(os.path.split(__file__)[0],"test.py")
filename=phile
fout = open(filename, "w")
fout.write(code_str)
fout.close()
# 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)
process.wait()
print process.returncode,"<" # 0 = success, optional check
# read the result to a string
strRead = process.stdout.read()
print strRead


the readMayaFile.py contains :

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

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

gmask
12-27-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?

DEVILSAN
12-27-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-27-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.