|
|
|
Tell us what you think of the site.
|
Autodesk Media & Entertainment User Community
|
Autodesk® 3ds Max®
|
|
Autodesk® Maya®
|
|
Autodesk® Softimage®
|
|
Autodesk® MotionBuilder®
|
|
Autodesk® Mudbox™
|
|
Autodesk® ImageModeler™
|
|
Autodesk® Sketchbook® Pro
|
|
Autodesk® Smoke on Mac®
|
| sourcing: I really ought to know by now, but...
|
|
|
I am confused. I am having trouble collecting all my scripts from various projects into one custom directory. i work on Mac & Windows and I have always had a problem with this no matter which version of Maya I’m running.
Maya is searching the correct directories for scripts, as specified in the MAYA_SCRIPT_PATH of the Maya.env file and verified by the getenv command in the script editor. I naively imagined that scripts in the directories searched by Maya would be automatically sourced: I thought that was the whole point of the script path.
Now some scripts in the custome directory will work without being sourced and others will not. It does not seem to matter whether or not they have been made into procedures. Some will work when sourced with “source xxxx.mel” and need this every time I call them from the command line. Others need to be manually sourced before they will work, but subsequently don’t need sourcing. All from the same directory.
I have seen it suggested that you create a list of scripts in a userSetup file, but this seems like an unnecessary extra step every time you want to add a script. Also some scripts seem to run when they are added to this rather than just be sourced: not the desired effect.
If anyone could set me straight about this it would be much appreciated.
thanks
|
|
|
|
I am actually having the same issue. I have never understood the mystery of adding scripts in Maya.
I just downloaded a mel script and the install directions say to source the script. I did this and then in the command line I typed “spinFaces” command as the directions stated and the mel script executes. I then saved this command to my shelf and assigned a hotkey. However, when I restart Maya and try and use the script, I get and error that “spinFaces” can’t be found. I placed the script in the maya/scripts folder and not the maya/2009/scripts folder. This has worked for most every script I have installed. In order for this new script to work, I have to source it everytime I restart Maya. Once it has been sourced, it works for the entire session until I quit Maya.
Can someone please shed some light on this?
thanks,
Wes
Wes McDermott | 3D Artist | Author
http://the3dninja.com
http://the3dninja.com/blog
|
|
|
|
I’m fairly new to the scripting side of Maya but from what I understand from others the whole show (is supposed to) work like this:
Upon startup maya loads all scripts from the native script path.
Then it will search all user defined script paths and source the userSetup.py and userSetup.mel scripts from these folders,
and subsequently loading/sourcing all scripts that are explicitely loaded from these.
That’s it.
During operation, e.g. when you enter a command that maya does not know yet, it will search all known script paths for a
script (mel, don’t know about python) that matches the command name you just entered (flipPoly(); thus needs to be a procedure
defined in flipPoly.mel to be sourced automatically upon first call).
Any procedures not in a file that has been sourced previously automatically or manually will not be found.
|
|
|
|
Hey,
Thanks for the info. It makes sense. I just can’t figure out why my script still has to be sourced apon opening Maya. I only have to source it once but if I quit Maya and re-open, I have to source the script again. I keep getting the error “Can’t find procedure spinFaces.” The mel script has a global proc spinFaces() procedure. I have placed the mel script in the path my documents/maya/scripts folder. It seems like it should work.
thanks for the help,
Wes
Wes McDermott | 3D Artist | Author
http://the3dninja.com
http://the3dninja.com/blog
|
|
|
|
Mystery Solved!
The issue with my script was that I needed to have the name of the mel script match the global proc spinFaces(). So I changed the name of the script from spinFaces_v2.0b.mel to spinFaces.mel and it worked.
Wes McDermott | 3D Artist | Author
http://the3dninja.com
http://the3dninja.com/blog
|
|
|
|
if you are interested in appending your userSetup.mel file with new scripts, i just wrote this up:
global proc createProc() {
if (`window -exists createWin`)
deleteUI createWin;
window -title "Add New Script to userSetup" -wh 150 75 createWin;
columnLayout;
text -label "New Script Name:";
textField -width 150 scriptText;
button -label "add new script!" -width 150 -command "createCom" createButton;
showWindow createWin; }
global proc createCom () {
string $newScriptName = `textField -q -tx scriptText`;
string $fileName = (`internalVar -userScriptDir` + "userSetup.mel");
int $fileID = `fopen $fileName "a"`;
fprint $fileID ("\n" + "source " + $newScriptName + ";");
fclose $fileID;
print ("Appended " + $fileName + "!\n");
if (`window -exists createWin`)
deleteUI createWin; }
createProc;
it creates a simple window that you can just type in the name of your new script and it will append your userSetup.mel file to add your script when you hit the button.
hope that helps.
|
|
|
|
Thanks very much for the script! It will definetly be used.
thanks,
Wes
Wes McDermott | 3D Artist | Author
http://the3dninja.com
http://the3dninja.com/blog
|
|
|
|
When Maya does a hash of all of your scripts in there respective directories it is expecting that the name of the script (XXXXX.mel) has a global proc named XXXXX. If you want to get to any scripts that are not named the same as the mel script then you have to source it.
I’ve been making library like functions like this quick pizza script
global proc pizzaHut()
{
print “\n”;
print “Pizza Hut”;
}
global proc pizzaFactory()
{
print “\n”;
print “Pizza Factory”;
}
global proc pizza (string $command)
{
eval($command)
}
Then I without sourcing I run these
pizza("pizzaFactory");
and it prints out…
Pizza Factory
|
|
|
|
| Settings
| Choose Theme color:
|
|
|
|
|
|
|
|
|