Sylvain,
I would like to be able to get a maya standalone instance from within the
Maya script editor, run a python function in that maya standalone instance,
sending it arguments, and capture its return value in the maya script
editor.
is there a way to return an instance of maya standalone in the script
editor something like this:
import get_maya_inst as gmi
my_args = 'anything'
maya_inst = gmi.maya_inst()
maya_inst.import_module('my_module_name')
return_val = maya_inst.my_module_name.my_awesome_function(my_args)
maya_inst = None #maya_inst released / quit through garbage collection
print(return_val)
Otherwise,
Is there a way you could post a more generic and step by step demo of your
example on how to achieve the original goals of sReinfrank's question?
On Monday, May 11, 2009 at 10:53:20 AM UTC-7, Sylvain Berger wrote:
>
> I manage to do this... it is a bit complex to explain, so i'll try my best.
>
> 1. Create a command calling mayapy.exe -m <script to run> <arguments>
> 2. Create the script you are calling with mayapy.exe, in this script you
> can grab the arguments sent to the script using sys.argv
> example:
> import sys
> # store the arguments in variables
> argument1 = sys.argv[1]
> argument2 = sys.argv[2]
> etc.
>
> 3. call the mayapy.exe command using subprocess. Here is part of my
> script... Note that I am capturing the stdout and stderr of mayaPy so I can
> diagnose problem more easily... you don't have to capture them.
>
> import subprocess
> cmdAndArgs = 'mayapy.exe -m mayaPy.avol.batchExportInit
> '+objExportedScene+' '+avolObj.NodeName+' '+camExportedScene+'
> '+str(createPreviewRender)
> tempFolder = os.path.dirname(objExportedScene)
> # Create log file
> sdtoutFile = r'%s\stdout.txt' %tempFolder
> stderrFile = r'%s\sterr.txt' %tempFolder
> outptr = file(sdtoutFile, 'w')
> errptr = file(stderrFile, 'w')
> # Call the subprocess using convenience method
> startupinfo = subprocess.STARTUPINFO()
> startupinfo.dwFlags = subprocess.STARTF_USESHOWWINDOW
> retval = subprocess.call(cmdAndArgs, startupinfo=startupinfo, bufsize=0,
> executable=None, stdin=None, stdout=outptr, stderr=errptr)
> # Close log handles
> errptr.close()
> outptr.close()
>
>
> This works fine for me... From maya I am exporting an object, I start a
> maya in background using mayapy.exe, I cleanup the object, save it, etc.
> In my case maya is loked because I am waiting for the stdout of the
> subprocess, but if you send the process and don't wait for it, maya should
> be free.
>
> Hope this helps
>
> On Sat, May 9, 2009 at 9:53 PM, sRheinfrank <[email protected]
> <javascript:>> wrote:
>
>>
>> Hi---I want to be able to capture arguments from a UI in a Maya
>> session and send them to Mayapy to run in the background to keep from
>> locking up the current session while waiting for the process to
>> finish---
>>
>> Ideally, I could access mayapy through the Script Editor (through a
>> system call) and also pass it arguments and the right module to
>> process them and still be able to work in Maya while it's running in
>> the background... I figure using the maya.standalone module would be a
>> vital part of this, what I'm unclear on is just how to get it going
>> purely by running a command from within Maya....
>>
>> Thanks!!
>> -Steve
>>
>>
>>
>
>
> --
> They say, "Evil prevails when good men fail to act." What they ought to
> say is, "Evil prevails."
> Nicolas Cage as Yuri Orlov in Lord of War.
>
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/90f30d03-b0cc-4bbc-9092-8d5a9b7b6af6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.