Hi I've successfully installed numpy in maya 2016 (for mac).
When clicking "set" in your script, the following error pops up in the script editor: "# Error: NameError: file <maya console> line 1: name 'alignVtxToPlane' is not defined #"
Hi Lukas
Thanks for trying out my script.
Looking at your error, it seems that function 'alignVtxToPlane' in the script was not defined correctly.
Could you elaborate on how you loaded the script so I can recreate the problem on my mac?
i followed this tut to run the script in maya (or add it to the shelf):
http://www.samwirch.com/blog/importing-and-running-external-python-scripts-maya-2011
so it looks like this:
import sys
import os
def psource(module):
file = os.path.basename( module )
dir = os.path.dirname( module )
toks = file.split( '.' )
modname = toks[0]
# Check if dirrectory is really a directory
if( os.path.exists( dir ) ):
# Check if the file directory already exists in the sys.path array
paths = sys.path
pathfound = 0
for path in paths:
if(dir == path):
pathfound = 1
# If the dirrectory is not part of sys.path add it
if not pathfound:
sys.path.append( dir )
# exec works like MEL's eval but you need to add in globals()
# at the end to make sure the file is imported into the global
# namespace else it will only be in the scope of this function
exec ('import ' + modname) in globals()
# reload the file to make sure its up to date
exec( 'reload( ' + modname + ' )' ) in globals()
# This returns the namespace of the file imported
return modname
# When you import a file you must give it the full path
psource( '/Users/Lukas/Library/Preferences/Autodesk/maya/2016/scripts/AutoAlignComponentsToPlaneTool_v_1_0.py' )
Oops, my mistake. The script you posted is correct.
Okay, I figured out the problem.
The web tutorial you followed only calls the main functions (In this case, the UI part of the code) which means that the GUI is displayed but the other functions like 'alignVtxToPlane' (The part where the script tells what to do when the 'set' button is pressed) is left out.
All you have to do to resolve this issue is to open the script normally, which is explained at the earlier answer I posted.
Hope this helps.
oh and it's the first time i'm trying to run an external py script in maya... so this instructions are the first google found...
in your manual you just write "load the python script in maya". i've no clue how to achieve this.
Thanks for your help!
The web tutorial you followed earlier is one way to load an external python script, but it is primarily intended for developers who wants to edit scripts on an external code editing program like emacs or IDLE.
For someone who only wants to use the script in Maya's script editor, you simply go to
File -> Load Script
and select the python file you want to use.
It will load the script on the python tab and you simply push the execute button.
Replies to this question:
Ken Jiang said over 10 years ago:
Lukas Müller said over 10 years ago:
Ken Jiang said over 10 years ago:
Ken Jiang said over 10 years ago:
Lukas Müller said over 10 years ago:
Ken Jiang said over 10 years ago:
Lukas Müller said over 10 years ago: