View Full Version : script too long!?
04-03-2003, 02:03 PM
my small script is now about 1300 lines long, so if i paste it into the maya script editor it dos'nt paste everything. Is it possible to increase the max number of lines for the script editor or dir ih have to split the script into smaller parts ...
btw. is it a sizelimit for a script? ... or can it be endless?
04-03-2003, 02:12 PM
due to an earlier thread we think that scripts and expressions are unlimited in length..
but the script editor is..
but you can use the "source" menu command to load the long scripts.. that works
04-03-2003, 02:54 PM
hmm, that oculd maybe work, but i thnik i must mak all my procedures global .. is it right? .. and then when my script is done i dont want that everybody must source the script everytime he start maya ...
04-03-2003, 09:48 PM
have you tried saving a mel file with the code, from a text editor and then opening it in Maya?
just a suggestion, since I haven't been in this situation :shrug:
04-03-2003, 10:55 PM
Why in the world would you try pasting a 1300 line program into the MEL script window?!??!?! I usually never work with more than about 10-15 lines at a time in the script editor.
If you name your .mel script the same as the routine to run in your script file, and you put your file in the /scripts directory, then simply typing the routine name will run it. For example, you have a file named "MyRoutine.mel" and in it you have
global proc MyRoutine ()
print ("Hello, I'm in MyRoutine now\n");
Then when you type "MyRoutine" in the MELScript window, it will fine MyRoutine.mel and run the MyRoute () script. If you are developing the script, then you'll create a button (or keep this text in your MELScript window) that runs:
source MyRoutine.mel; MyRoutine ();
And when you run that, then your script will be freshly sourced (to get your most recent changes) and your routine run.
Pasting a 1300 line program into the MEL window is just silly
Hope this helps,
04-04-2003, 08:08 AM
it IS silly. And there is nothing wrong with making your procs global as needed. Just name them in such a way as to guarantee reasonable uniqueness, such as:
global proc silly_pasteBigScript ()
04-04-2003, 08:47 AM
i know how to make global procedures, but i had read that it is not always good make global procedures, thats because i asked.
and @MDuffy ... my script has more then 1 procedure ... so how i make it that every procedure inside it get so registerd by maya ... must everybody who wants to use it , source it?
or how i can make it that maya register all procedures inside the script?!
04-04-2003, 08:55 AM
All procs and globals will be "registered" when you source the file that contains them. If you want a group of people to always have your files sourced, do this with a userSetup.mel.
The reason for not making globals has only to do with the possibility that you might trample over other globals by not naming yours uniquely, hense my example on how to make sure your globals are always unique.
04-04-2003, 08:58 AM
so i must only put "source myscript.mel;" into the usersetup.mel ? .. and then all procedure (global or not global) get "registerd" by maya?
04-04-2003, 09:06 AM
04-04-2003, 09:34 AM
ok .. thanx ;) ... and my script is not 1300 lines long ... its about 1943 and it is still not ready :rolleyes:
04-04-2003, 06:17 PM
What's it do that it's so ginormous?
I've written a few monsters myself. UltraPose is about 2000 all together, tho a lot of that is the result of coding style.
04-04-2003, 06:23 PM
You should never have to put source statements in your userSetup.mel file.
Either your "script" is a collection of related procedures that you want to use in other scripts (a library) or it's a script that has a well-defined entry point, usually a user interface procedure that then calls other code to do things.
If you're writing a library, the appropriate thing to do is define the procedures in the library as global and then source the file in the script where you want to use the procedures. This will help you remember where all the library procedures came from when you're later editing that script.
If you're writing a long standalone script, you probably only have one or two well-defined entry points. An entry point might be the procedure that creates a user interface or it might be a procedure that does the actual work of the script. Usually, even if I'm building a UI I try to make sure that there's an entry point to my UI that collects a bunch of information, and a separate entry point that does the work of the script without actually building user interface elements. (The latter can be important if you're ever going to run Maya in batch mode.)
Each of these entry points goes in its own file, named for the entry point.
For example, if I wanted to make a sphere in my script, I'd first make a global proc called makeSphere that took relevant parameters as arguments, like radius:
global proc makeSphere (float $radius)
sphere -r $radius;
I'd put this into a file called makeSphere.mel in my script path (and when I do this, Maya's smart enough to AUTOMATICALLY source the MEL script when I try to run makeSphere somewhere. I don't have to source it in the userSetup.mel.)
Alongside this file I'd make a user interface procedure that just collects the data needed to run the script that does the work. This goes into a file called makeSphereUI.mel:
global proc makeSphereUI()
promptDialog -title "Make Sphere"
-message "radius?" -button "OK";
float $input_radius = `promptDialog -q`;
Note that since I put makeSphere.mel in my script path, makeSphereUI doesn't have to source anything to get at the makeSphere global proc -- it can just use it.
Now, my shelf button or whatever can simply execute this global procedure:
If I had a library of primitive-making functions collected into a MEL file that's not named for the function I'd want to call, I could always add
(or whatever the library file is called) to the beginning of my makeSphereUI file.
See? No editing of userSetup.mel and no hassles. The keys are (1) make one file per entry point in your script path and (2) if you have a library of functions that you don't want to treat as a general entry point, use an explicit source statement to bring them into the script file.
04-04-2003, 06:44 PM
oh, one thing though: if you're using an external text editor to edit a file that's in your script path, if you want to pick up your changes in a session of Maya where you've already run the script you'll have to source the file again by hand. Maya's automatic sourcing of appropriately-named files only happens the first time a script is run in a given Maya session.
04-04-2003, 07:00 PM
Thanx for the great answer Mark! :thumbsup:
01-14-2006, 08:00 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.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.