View Full Version : [Resolved] Calling Python Functions from within a Marking Menu?


Zeusbwr
10 October 2007, 09:56 PM
I am trying to make a marking menu that calls python functions, anyone know how to? I see no option to create the marking menu and call python code..

I have a big toolset of functions built with python that i need to be called from a marking menu... any ideas?

Zeusbwr
10 October 2007, 09:59 PM
Hah, got it :)

Thats what i get for searching the forum before searching the mel command reference. There is a function to call python from mel.

Here is an example for any searchers:
python( "sys.version_info" );

EricLyman
10 October 2008, 01:00 AM
Wow, I caught this thread right before it was archived :)

Well, I'm also trying to get some Python code working in my marking menu. I tried your sample code though, and it returns this:

python( "sys.version_info" );

# Error: line 1: name 'sys' is not defined
# Traceback (most recent call last):
# File "<maya console>", line 1, in
# NameError: name 'sys' is not defined #

Any ideas?

thanks!

NaughtyNathan
10 October 2008, 08:49 AM
eric, you need to import any Python modules you want to use, in this case the sys module.

you could do it like this:

python( "import sys;sys.version_info" );

but that's going to attempt to import it every time you select the menuItem (whether this really matters I don't know.. python is probably clever enough to ignore repeated imports, but who knows what issues this may present?). Better to import it once at the start of your script. Any modules imported by MEL appear to be globally accessible from that point on...

:nathaN

CGTalk Moderation
10 October 2008, 08:49 AM
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.


1