View Full Version : How to call an external Python script?

10 October 2010, 10:45 AM

maybe this is a stupid question, but I didn't find anything in the docs on that matter.
I wote a script in Python and I want that script to be called out of an expression.

If it was an external MEL script, this was no problem. I just define a "global proc()", source the script and that's it....but how's that done for calling external Python?

Thank you in advance!

10 October 2010, 01:29 PM
you "source" python by importing it, you define "global procs" using def func(): and you can call python from MEL using the python command. I'm not sure what else you would need to know?


10 October 2010, 05:16 PM
Thank you for your reply. Unfortunately, I couldn't make it work entirely.

The import statement seems to be working, as Maya found all the small Syntax Errors in my external script file. When the Python function was called in the expression, I got an error claiming my function was not defined. I am sure this is just a very small issue but I cannot find what it is.

Here's virtually what I wrote in the expression:

string $import = "import killVolume001"; string $funct = "kVolume()";

And here's the part of the content of my external Python script where my function is defined:

from pymel.core import *

def kVolume():
fluid = ls('fluid1')
box = ls('killBox')

What do I need to do in order to enable the expression to execute kVolume()?

10 October 2010, 07:26 PM
Assuming that killVolume001 is the name of your python file and it's saved in the right place, try this in your expression:
python("import killVolume001;killVolume001.kVolume()");

CGTalk Moderation
10 October 2010, 07:26 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.