Notifications
Clear all

[Closed] Include() doesen't remove "include"

I’m trying to learn how to use the include() function in Maxscript, for the purpose of allowing me to compile long macroscripts from small, easy to edit source files. My problem is that when using include <scriptFileName.ms>, the resulting compiled script (the one stored in the UI/Macroscripts folder) not only has the referenced file embeded, but it STILL has the include statement right before it! This then kicks a compile error the next time I start Max since I’m not keeping all the small referenced source files in the 3dsmax7/scripts folder (and I don’t want to have to keep them there, either.)

Am I not understanding the purpose of the include function?

Thanks in advance!

4 Replies

I think that max script always uses just-in-time compiling, and just stores the compiled version of your code in memory when you try to run it…so since you are re-compiling it every time you run it, you would always need to have the referenced included files available.

Theres still some benefit to using include files, which is that your individual files are not as long and are easier to program with. This would probably become a real pain if you wanted to encrypt your scripts though!

Thanks for your input. But I’m still confused about something, and here’s why:

Let’s say you’re developing a macroscript, and you’re saving your working copy on a seperate drive/folder than Max’s installation. However, as soon as you evaluate the script, max creates a new version of that script and stores it in its own 3dsmax/UI/MacroScripts folder with a slightly different name, which then allows the script to be registered as a macroscript. So far, so good.

But now you use an include file in your working script, and you have the refereced file in the same folder as your working copy. You evaluate the main script, and again Max makes a copy of the script and stores it in 3dsmax/UI/MacroScripts to be registered as a macroscript. However this time the entire contents of the refereced include file are now stored in the evaluated file, but the “include” statement is still present one line above it!!

There’s no need for max to reference the include file in this evaluated version of the script, because it already contains the full text of the include file. So why would it STILL need to link to redundant information?

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

Sounds pretty obvious: Don’t use include in MacroScripts

Here is why: The include() function has been around since the first MAXScript release with Max 2.0. The MacroScripts were added to Max 3.0 and were intended to be automatically generated by the MacroRecorder (which would never use include() anyway), and to create relatively short UI scripts. So MacroScripts never worked well with, say, encypting or include, because they were supposed to be machine-generated, short, or both.

Normally, when you write a MacroScript, your best strategy is to package the UI in the Macro definition and put any extensive functions into a separate file (probably defining a structure of functions?) which is loaded from \StdPlugs\StdScripts folder before the UI\Macroscripts directory has been scanned.
This makes it possible to keep UI and functions separated. You can freely use include() in your functions .ms file if it is too large. Just don’t use it in .mcr files…

I would still consider the fact that the include statement is left in the final .mcr file a bug, but there might be technical reasons for it we don’t know. The only reasons I know are historical ones…

Bobo,

Thanks for the information. It’s unfortunate that the “bug” exists, but at least I know better how to deal with it.

By the way, I’m really enjoying going through yours and Laszlo’s Maxscripts DVDs. They’re giving me just enough of a nudge to delve in deeper and do some effective stuff. Thanks so much for your work on that!