executing external python script and returning a list?

298 views
Skip to first unread message

Gerard v

unread,
May 5, 2014, 1:25:56 AM5/5/14
to python_in...@googlegroups.com
Hi.

I wrote a script using pyAlembic that I can use to parse a file and list contents etc. I am not sure how to execute the external script from within maya, with an argument (path) and return a list that is generated from the script.

I have read up on python's subprocess module and  os.popen but I'm a little confused by the application. (I dont have a programming background)  Is there another way to return a value? It seems pretty complicated for what *seems* to be a basic requirement.

Tried looking for examples online but coming up short. Can anyone point me to either a python-For-Dummies-level explanation, an example or even mention if subprocess is the way to go?

Thanks
Gerard.

Fredrik Averpil

unread,
May 5, 2014, 1:51:45 AM5/5/14
to python_in...@googlegroups.com
Hi Gerard,

Here's an example how you can catch (or list the output) from python's subprocess: http://fredrik.averpil.com/post/63722065215

To source the script and run it within Maya, first do:

import sys
sys.path.append('c:/where/your/script/is/at')
import yourScriptName


And optionally/preferably execute a function inside the module, so it doesn't get run just because you have sourced it (above):

yourScriptName.functionName()


Check out python's "optparse" for a clean way of dealing with arguments. But that's not really applicable when you execute the script within Maya. If executed like described above, you can just supply arguments to the function:

yourScriptName.functionName('hello', 5, 'blue')



// Fredrik




Gerard Gmail

unread,
May 5, 2014, 3:19:29 AM5/5/14
to python_in...@googlegroups.com
Thank you Fredrik. I'll take a look at the example. One caveat is that my external py script imports alembic / py alembic  which prohibits it from being imported in maya 2014.  However it looks like we have the option of moving onto 2015 which seems to be happy with those modules. 

Either way your examples will assist my understanding so thanks again!!

Gerard. 
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWPYGBwQMYZ5Ro8gPvrssMKVFshN6mqmbWsu-bDwnRu3%2Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages