Source A Script?

ok....i am trying to use that cool Wire Jumbler mel script that was recently posted. However, i guess, the mel needs to sourced in maya.

could somebody please give me a very dumbed down version on how to get this working?

i had it working one day...but when i closed maya and re-opened....it couldn't find the procedure again.

how do i source this script so it works everytime i launch maya?

thanks for all help.

casey

Hi

Simple answer is ensure you have put it in a Folder that is on Maya's Script patch. e.g My Dcoumnets\Maya\scripts or My Documents\maya\8.5\scripts.
Then set up a button on a shelf by typing command used to call script in command line and then middle mouse dragging it onto a shelf of your choice. The important thing is to ensure script is in Maya's script path to call it with no issues.

If you want to source if it before calling it then go to shelf editor and edit the command to call the script

Example
Current command would be something like

Myscript;

Change this to

source Myscript;
Myscipt;

But if it is on Maya script path you shouldn't need to source it

thanks for the reply davvey! is there any chance you could look at that FBWireJumbler script and try it? i am having problems......i'm sure it just because it is something on my end....

i have it in the proper directory....try to source....sometimes it works sometimes it doesn't.

if you don't have time to mess with it....no problem.

casey

QUOTE(Davvey @ 04/09/07, 03:06 AM) [snapback]263762[/snapback]
Hi

Simple answer is ensure you have put it in a Folder that is on Maya's Script patch. e.g My Dcoumnets\Maya\scripts or My Documents\maya\8.5\scripts.
Then set up a button on a shelf by typing command used to call script in command line and then middle mouse dragging it onto a shelf of your choice. The important thing is to ensure script is in Maya's script path to call it with no issues.

If you want to source if it before calling it then go to shelf editor and edit the command to call the script

Example
Current command would be something like

Myscript;

Change this to

source Myscript;
Myscipt;

But if it is on Maya script path you shouldn't need to source it

Hi

Download page appears to be corrupted and I am only getting a file header so could you e-mail a copy at davvey@ntlworld.com and I will have a look at it.

Its OK I got a copy off his own website to try. The only way I could get it to work everytime is to do what I said above and I also commented out a line at Line No. 55 which seems to call the script as soon as it is sourced. You need to contact the writer of the script to ask him to review it.

Commented this out //FBwireJumbler();

and called script as above and it works OK.

thanks for taking the time to look at it.

i commented out line 55, too....was wondering about that.

i also think i have it working correctly. i renamed the mel file to be just FBwireJumbler.mel.....sourced it in maya.....and then ran it.

i quit out of maya and re-launched and just typed FBwireJumbler w/out sourcing and it worked just fine.

casey

QUOTE(Davvey @ 04/09/07, 03:40 AM) [snapback]263768[/snapback]
Hi

Download page appears to be corrupted and I am only getting a file header so could you e-mail a copy at davvey@ntlworld.com and I will have a look at it.

Its OK I got a copy off his own website to try. The only way I could get it to work everytime is to do what I said above and I also commented out a line at Line No. 55 which seems to call the script as soon as it is sourced. You need to contact the writer of the script to ask him to review it.

Commented this out //FBwireJumbler();

and called script as above and it works OK.

Hi

That would make sense as I seem to remember reading somewhere that when Maya loads it "reads" all files in the script path to source them and "stops" at the first global proc it finds in a file. It does check rest of file for errors so that maybe the issue.

No, it sources nothing. It takes note of what it has, in sense it builds up a inventory of what it has. Originaly maya cheeked this like a operating system every time does but now it does it once on start in a process known as hashing.

maya only sources only one file on startup (well it will source a few others later)! But however this file needs other files so they get sourced by this file or because theres a command maya knows is in repository. So it goes ahead and sources quite a number of files as a result of on source.

You can define which file this is but unless you do its going to be mayadir/startup/initialLayout.mel (so if you wish you could construct the entire sequence by reading forward from there, you can set the file with env var MAYA_OVERRIDE_UI)

So if you ask maya for a generalProc maya checks its inventory to see if it has something called generalProc if it does it sources it AND runs any proc inside it called generalProc, unless it already had a proc named generalProc loaded.

Whan it sources the file it executes everything in that file, thus aso errors there (no it does not run too the firts proc it runs them all. but see proc definitions dont run procs, it just defines them you still need to call them)

Hi Jooja

Thanks for that as I was never exactly cler how Maya actually processed scripts (or procedures really). I just knew about script paths etc and the start up directory etc but was not sure about rest i.e. building a sort of inventory of calls it could run makes more sense really.

Thought I would tag in on the end of this thread. I am having a problem with dynamically launching all the scripts in the user scripts directory.

In theory this should work. Why it's not, I have no idea. The following is my userSetup.mel file

CODE
// Source all user files in userEnv scripts directory

// Files to be removed from sourcing list
        string $exemptFiles[] = {"userSetup.mel"};
// Type of files to source. MEL of course!
        string $fileType = "*.mel";
// User Script Directory Path
        string $scriptPath = internalVar -usd;
// List of all files in User's Script Directory
        string $allFiles[] = getFileList -folder $scriptPath -filespec $fileType;
// Remove specified files from the list of files to be sourced
string $sourceList[] = stringArrayRemove($exemptFiles, $allFiles);

for($file in $sourceList)
{
    string $filePath = ($scriptPath + $file);
    source $filePath;
}

Feedback is appreciated.

QUOTE(kurokawa @ 05/15/07, 07:48 AM) [snapback]266125[/snapback]
I am having a problem with dynamically launching all the scripts in the user scripts directory.

Why would you even want to do that? Anyway you do understand you must do a loop with in a loop for this to work! And secondly you'd need to know ahead of time if a duplicate file exist in the following path (otherwise youd source something you weren't supposed to).

Anyway internalVar -usd poins to a folder with no mel scripts. Also source is a directive so if you want t call it dynamically you need to eval it

this would do it on windows (note i don't use explicit path to ensure maya sources only the valid version of the file, also why i do it in reverse).
CODE
{//dont run this it will take forever and eat all your memory
// (all my scripts ate 500 megs)
// WARNING THIS WILL KILL YOUR PREFERENCES
string $buffer[];

$env=getenv MAYA\_SCRIPT\_PATH;
$numTokens = tokenize $env ";" $buffer;
for ($i=($numTokens-1);$i>-1;$i--){
  print ("doing: "+$buffer[$i]+"\n");
  $files=getFileList -folder ($buffer[$i]+"/") -filespec "*.mel";
  for ($file in $files) eval ("source "+ $file);
}

}

PS because theres bound to be a error somewhee down the line its probably better to catch the eval

Ok joojaa, you are correct. I do not want to source all the scripts in all the user scripts directories. I want to source only the files in the root -usd (I happen to put my scripts in this directory). I agree I would need to make sure that there were no duplicate files.

Because I am only getting the files from this one directory, I do not believe I need a nested loop.

Either way, the eval statement worked. Thank you for your feedback Joojaa