PDA

View Full Version : Help needed - sourcing/referencing file location


ctb
10-10-2006, 11:12 AM
Hi,

I have many MEL scripts that all refer to this variable:
string $dir = "W:/3D/test/"; //directory path

I want to place this path in a separate file (eg. "path.mel") so that if it changes (eg. all MEL files been moved to different location), I don't have to change every individual MEL file.
How do I reference this "path.mel" from all the individual scripts?

Thanks here.

cheers.





The following are my script files:

global proc simpleWindow()
{
string $dir = "W:/3D/test/"; //directory path

string $print_A = "source \"" + $dir + "PRINT_A.mel\";PRINT_A";
string $print_B = "source \"" + $dir + "PRINT_B.mel\";PRINT_B";
string $print_C = "source \"" + $dir + "PRINT_C.mel\";PRINT_C";
string $print_D = "source \"" + $dir + "PRINT_D.mel\";PRINT_D";

window -width 150;
columnLayout -adjustableColumn true;
button -label "button A" -command $print_A;
button -label "button B" -command $print_B;
button -label "button C" -command $print_C;
button -label "button D" -command $print_D;
showWindow;
}
--------------------------------------------------------------
global proc PRINT_A()
{
string $dir = "W:/3D/test/"; //directory path
string $A = ("MEL file for button A can be found in " + $dir);
print ($A+"\n");
}
--------------------------------------------------------------
global proc PRINT_B()
{
string $dir = "W:/3D/test/"; //directory path
string $B = ("MEL file for button B can be found in " + $dir);
print ($B+"\n");
}
-------------------------------------------------------------
global proc PRINT_C()
{
string $dir = "W:/3D/test/"; //directory path
string $C = ("MEL file for button C can be found in " + $dir);
print ($C+"\n");
}
----------------------------------------------------------------
global proc PRINT_D()
{
string $dir = "W:/3D/test/"; //directory path
string $D = ("MEL file for button D can be found in" + $dir);
print ($D+"\n");
}
-----------------------------------------------------------

animationrigs
10-12-2006, 10:07 PM
two options for you

1. You can declare a global variable in your userSetup.mel file that is the directory and then ref that variable in your scripts
Since some people look down on global variables
2. Declare a procedure something like this in your userSetup.mel file
global proc string getScriptDir()
{
return "c:/my script/dir/";
}

then in your procedures you would just get the script dir at the top

string $mydir=getScriptDir;

Hope that helps.

ctb
10-19-2006, 02:21 AM
Thanks animationrig.com!

I had tried your second option. The error keeping poping up:
// Error: string $mydir=getScriptDir; //
// Error: Invalid use of Maya object "getScriptDir". //

After that I add
string $mydir=getScriptDir();
the problem been sloved.

Anyway thank very much here.

cheers.

CGTalk Moderation
10-19-2006, 02:21 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.