PDA

View Full Version : how to source a script


designingpatrick
11-05-2009, 12:36 AM
What am I missing here?

Declare a global procedure; global proc myProc ()
{
}
;
,
Save it in the maya scripts folder in the user's documents,
run the command, "source myProc;",
receive error -cannot find myProc for source statement.

goleafsgo
11-05-2009, 01:00 AM
"source" takes a file name...in your example was the mel file called "myProc.mel"?

norbertnacu
11-05-2009, 02:50 AM
Hey,
If you have Maya open and you added a mel script(s) Maya doesn't know that (Maya doesn't have a notify function like c#). What you have you to do is call the rehash command. If you put your mel script(s) in the valid mel script folder ( getenv MAYA_SCRIPT_PATH ), assuming Maya is closed, you can just call the source command.

ie..
source MyProc() // I recommend adding the () open and close bracket.
source MyProc; // This is also valid, but it's kinda confusing in my opinion.

IMHO
You should read a basic programming book to understand some basic programming :)

Cheerios,
Norbert

JayHoo
11-05-2009, 10:28 AM
rehash;
eval("source script.mel");

This works in a similar situation for me. Maybe without the "";

benio33
11-05-2009, 10:49 AM
"internalVar -usd"

This mel command will point you to a user scripting directory, put your file ther and call rehash command like the guys above stated.

designingpatrick
11-05-2009, 03:50 PM
Thanks for the input. Looks like it works after the rehash and eval. The steps I was taking earlier were straight from this book, "Mel Companion: Maya scripting for 3D artists". Looks like I should have done some research on the book prior to purchasing, apparently it is full of syntax errors or breaks in code logic. Oh well.

Geuse
11-08-2009, 01:25 PM
I think what he describes is valid.
But sure he could've mentioned you have to restart Maya for it to work. Or use the rehash command. The important thing to know is that the name of the global proc must be the same for the name of the mel script. In that case Maya source it upon start.
If however for one reason or another the name of the mel script does not match the name of the global procedure in the file, you either have to source it in you userSetup.mel-file or in maya manually prior to executing the script.

benio33
11-09-2009, 09:12 AM
Thanks for the input. Looks like it works after the rehash and eval. The steps I was taking earlier were straight from this book, "Mel Companion: Maya scripting for 3D artists". Looks like I should have done some research on the book prior to purchasing, apparently it is full of syntax errors or breaks in code logic. Oh well.

Actually the book is really good. I went through it few times when started learning MEL and there are some syntax errors, but they are really hard to avoid when writing a programming book when the copywriter cannot automatically syntax check the code. Believe me, comparing to other programming books this one is really well written, and valuable even later on writting MEL. Anyways, MEL soon will vanish , so I'd move to Python if I were to learn Maya programming.

designingpatrick
11-09-2009, 05:39 PM
I know what you mean about MEL's demise, but I wouldn't count on it disappearing within the next 5 years. Let's call it IE6. Keep in mind that Maya's python is little more than MEL with Python-like syntax. How can you count on only knowing Python? I feel like it's still developing too much to count on; look at PyMEL- that's an example of Python integrated like it should be, but how many studios use PyMel?

Thanks for the input. I'm going to continue moving through the book, because I can tell that it teaches the principles. I'll just pretend that the code is pseudo-code.

phix314
11-11-2009, 07:47 AM
I know what you mean about MEL's demise, but I wouldn't count on it disappearing within the next 5 years. Let's call it IE6. Keep in mind that Maya's python is little more than MEL with Python-like syntax. How can you count on only knowing Python? I feel like it's still developing too much to count on; look at PyMEL- that's an example of Python integrated like it should be, but how many studios use PyMel?

Thanks for the input. I'm going to continue moving through the book, because I can tell that it teaches the principles. I'll just pretend that the code is pseudo-code.

One thing I'm trying to do is develop a script in MEL, and translate to Python to make sure I've got all my bases covered.

CGTalk Moderation
11-11-2009, 07:47 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.