PDA

View Full Version : [HELP] about Import / Sourcing / maya environment script


ginanjarlilLuNaTiC
11-03-2012, 04:22 AM
hey anybody know how to sourcing or importing MEL script on maya when startup ?

i'm already try sourcing script with local folder like "C:/scripts/script.mel" and its work
but its just one script.
in case when i have alot of scripts,is it not efficient for sourching every scripts...


than i just look at another tutorial.. working with maya.env with add

"MAYA_SCRIPT_PATH= //server/scriptLib/ "

than i trying it and run the script ie. " script(); " but it say error " no procedural found ".
even though the file already exists in the directory...

the question is :
1. how to load another script from server library when startup with address " //server/scriptLib/ " and just call ie. " runScipt(); " or another global procedure on MEL
2. if using source command is it possible ?
3. i'll using another script for hotkey ie. i just add " hotkeySelectALL(); " on the hotkey editor
so it just call a simple script on the hotkey editor and all .mel script just saved on server

the main question is run MEL script on the "//server/scriptLib/" when maya startup and just call the global proc on the MEL script

thanks..
sorry about my english and sorry if my question is to long

djx
11-03-2012, 05:31 AM
Sourcing a script and running a script is not the same thing. But it is confusing because some scripts need to be sourced to make them run, and others do not. It depends on how the script was written.

Setting MAYA_SCRIPT_PATH in Maya.env is a good start. Maya will "see" all the scripts in those folders.

There is a special script called userSetup.mel that maya will run when it starts up. You can put mel commands in userSetup.mel and they will run at startup. For example you could source other scripts. Or you could run other scripts. Or both.

If a script called myScript.mel contains a global procedure called myScript() then you do not need to source it, as long as it is in the MAYA_SCRIPT_PATH. When a script is written like this you can just run it using its name (without the .mel) because it matches the name of the global proc. So you can put "myScript;" (no quotes) in userSetup.mel and maya will run it at startup.

If another script called myOtherScript.mel does NOT have a global proc called myOtherScript() then you can NOT run it by simply typing its name. You need to source it first. Depending on how that script was written, sourcing it may also run it or it may not (this is why it is confusing). If you wrote the script yourself then you probably know what to expect. If you downloaded it, then you will either need instructions on how to run it, or you will need to inspect the code and work it out for yourself.

David

ginanjarlilLuNaTiC
11-03-2012, 06:53 AM
thanks djx...
but it still error.

i'm already add MAYA_SCRIPT_PATH = \\server\scriptLib\

than i've script and naming it with hotkeySelectAll.mel inside \\server\scriptLib\
and inside hotkeySelectAll.mel i'm writing this code

global proc hotkeySelectAll(){
string $sel[] = `ls -sl`;
string $tokenized[];
for($selection in $sel){
tokenize $selection "_" $tokenized;
}
selectAll($tokenized[0]);
}
global proc selectAll(string $characterName){
switch ($characterName){
case "BrockBadger" :
select -r blablabla....
break;
case "MrTod" :
select -r blablabla....
break;
case "Peter" :
select -r blablabla....
break;
case "Lily" :
select -r blablabla....
break;
case "Benjamin" :
select -r blablabla....
break;
case "JeremyFisher" :
select -r blablabla....
break;
case "Cottontail" :
select -r blablabla....
break;
}
}

than i'm try to call the script with write this code hotkeySelectAll;
but why i'm got # Error: NameError: name 'hotkeySelectAll' is not defined
or i've wrong step ?

thanks
ginanjar

djx
11-03-2012, 12:02 PM
Those details do look ok to me.
After you load maya, can you verify that the script path is what you expect it to be.

getenv "MAYA_SCRIPT_PATH";

Do you see the path to your scriptLib ?

David

ginanjarlilLuNaTiC
11-05-2012, 03:35 AM
Those details do look ok to me.
After you load maya, can you verify that the script path is what you expect it to be.

getenv "MAYA_SCRIPT_PATH";

Do you see the path to your scriptLib ?

David

yup i see it..

i'm already solve it.
i don't know why it happen...
i just try to move //server/scriptLib/ to the first line...
and the script are working...


because on the MAYA_SCRIPT_PATH i've many addres . maybe 5 address there..

this the first script before move //server/scriptLib/

MAYA_SCRIPT_PATH = //server/address1/;//server/address2/;//server/address3/;//server/address4/;//server/scriptLib/

and this is the script now and its working,and i don't know the problem... and why it working

MAYA_SCRIPT_PATH = //server/scriptLib/;//server/address1/;//server/address2/;//server/address3/;//server/address4/

thanks djx for your time..

Azrail
11-05-2012, 09:07 AM
You can't have more than one assignment to your environment variables inside Maya.env. Only the first one works, the others don't get evaluated at all. So you'll have to stick everything into a single line.

ginanjarlilLuNaTiC
11-05-2012, 11:15 AM
You can't have more than one assignment to your environment variables inside Maya.env. Only the first one works, the others don't get evaluated at all. So you'll have to stick everything into a single line.

owh... so i've wrong script on those maya.env ?

the script should like this maybe ?

MAYA_SCRIPT_PATH = //server/scriptLib/;
MAYA_SCRIPT_PATH = //server/address2/;
MAYA_SCRIPT_PATH = //server/address3/;
MAYA_SCRIPT_PATH = //server/address4/;

djx
11-05-2012, 12:03 PM
No. Multiple lines is NOT correct.
All on a single line is correct.

And the order is only important if you have different versions of a script in more than one place.

David

CGTalk Moderation
11-05-2012, 12:03 PM
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.