04-23-2009, 09:02 AM
You can split your code in several files and use the function fileIn() to call them in your general script ;)
I am working on a script that outputs RGB channels for each object based on materials. in the begining it was easy to scroll and work within one single file but now as I am working further it is becoming very difficult to work within one single file.
Is there anyway I can split my code in multiple files but will be able to execute all files at ones?
Please suggest. thanks in advance
There are several approaches, including include(), filein() and simply splitting the source into a startup folder.
The include() command is a COMPILE-TIME statement which simply puts the sources together. It is almost equivalent to Copy&Paste source code from one file into another at compile time. So it is designed to do exactly what you want, but has one drawback - since it is used by the compiler and not at run time, you cannot use variables as names or any other computed file names. This can be a problem if you want to SWITCH which file will be loaded depending on some condition like what OS or Max build is running (32/64) or what version of Max etc.
The fileIn() does not have this limitation - it is a run time function and performs the same as MAXScript>Load Script menu item - it opens and evaluates the code. It also has a drawback - that code is ALWAYS evaluated in GLOBAL scope, whereas include() can concatenate files at any place and the included source becomes part of whatever scope it is placed in. Thus, if you have some global functions or a global struct of functions the rest of the script is using, you could split them into a separate files and load them all via fileIn().
The last approach would be to save the multiple files into startup folders (e.g. the global function definitions in Stdplugs\Stdscript and the UI code in UI\usermacros or \Scripts\Startup and let Max load them as it boots up. The drawback here is that you have less control over what is loaded when. The \Stdscripts and its subfolders will be loaded first, but you cannot tell which file will be loaded first within that folder, so predeclaring variables might be necessary.
Plase read the MAXScript Help on filein() and include() to see which one works for you...
04-23-2009, 06:06 PM
Thanks Bobo and IkerCLoN.
filein() works for me because I only have seperate my global functions.
04-23-2009, 06:06 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.