MEL procedure on file needs to source itself to get global variables?

MEL procedure on file needs to source itself to get global variables?

Anonymous
Not applicable
1,220 Views
4 Replies
Message 1 of 5

MEL procedure on file needs to source itself to get global variables?

Anonymous
Not applicable

I know, why MEL... Sadly, Maya LT doesn't let my clients use Python, so that's my torture.

 

I just discovered this.

I declare several variables in this MEL file.and then have a procedure with the SAME name as the file.

I run the file name, but the globals are not loaded.

 

Should I call source with the file name inside this procedure to be able to get the globals? 

I thought when you run a file it was sourced by default.

0 Likes
1,221 Views
4 Replies
Replies (4)
Message 2 of 5

haggi_master
Advocate
Advocate

Did you declare your variables as global?

 

global int $val = 123;

global proc myscript()
{
    global int $val;
    print("Global int " + $val + "\n");    
}

The global declaration in the function body is the most important one.

0 Likes
Message 3 of 5

Anonymous
Not applicable

Yes I did. It's all good. But somehow if I don't run a source on the file it doesn't recognize the variables running the script from a mel file using the name of the file command (so that Maya finds the file with the same name and the procedure inside). I thought maya already sourced the file before finding the procedure inside.

0 Likes
Message 4 of 5

haggi_master
Advocate
Advocate

Usually it does if it knows that the script exists. e.g. if you start maya and create a new script, maya does not know anything about the script. In this case you have to do a "rehash" to let maya know that something has changed. But if you start Maya with an exsiting script it should work exactly as you say.

0 Likes
Message 5 of 5

Anonymous
Not applicable

I understand that rehash is only to add files, not to "reload" the files. But well, thanks!

0 Likes