PDA

View Full Version : calling python from menu item


raffael3d
02-16-2011, 07:25 PM
I was looking at this, but doesnt seem to work for me

http://www.vfxoverflow.com/questions/609/python-to-mel-is-it-possible-to-source-a-python-file-through-a-mel-menuitem


I have a menu and I need to call python scripts from within that menu

I have
menuItem -label "Plot Scene" -c "python('import ScenePlot_Fast')";

the script is called ScenePlot_Fast.py

it gives me syntax error
any advice?
thanks

NaughtyNathan
02-16-2011, 08:50 PM
python() is a MEL command, so won't accept 'single quotes'

menuItem -label "Plot Scene" -c "python(\"import ScenePlot_Fast\")";escaped because they are already inside a string.
:nathaN

raffael3d
02-16-2011, 09:21 PM
thanks. I still get tough an error message which says

# Error: ImportError: No module named ScenePlot_Fast #

why is that? does it have issues loading the original script?

NaughtyNathan
02-16-2011, 10:03 PM
is ScenePlot_Fast.py in your python path? what happens if you just type:

import ScenePlot_Fast

into the script Edtor? (in a python tab!)
:nathaN

raffael3d
02-16-2011, 11:45 PM
# Error: ImportError: No module named ScenePlot_Fast #

so is the script basically not loaded?
it was in the scripts folder for startup

fantasizer
02-17-2011, 02:38 AM
It is not an uncommon task. Take a look at jc.menu (http://sites.google.com/site/cgriders/jc/menu). It does everything for you: append path, load script, pass arguments. You can even import the script and it'll generate the menu for you.

whisperwing
02-18-2011, 04:26 AM
import sys
print sys.path

is the path your script is in in sys.path ?

# Error: ImportError: No module named ScenePlot_Fast #

so is the script basically not loaded?
it was in the scripts folder for startup

Azrail
02-21-2011, 11:06 AM
As far as I know python codes should be in your PYTHONPATH so they can be imported as modules. In mel type
getenv PYTHONPATH
to see where are your python search paths.
sys.path also works, but prints out too much useless info for the case.

CGTalk Moderation
02-21-2011, 11:06 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.