Notifications
Clear all

[Closed] FileIn versus Include

Hi, I wrote a custom attribute in which in have a button.

When i press this button it runs a function that i wrote. Kinda like this…

rollout MyRollout “My Rollout”
(
button BLABLA “”

 on BLABLA pressed do
  (
        include "myFunction.ms"
        myFunction()
   )

)

This represents pretty much the set up that i have. My problem is that i would like to be able to do modification on myFunction.ms and have those modification appear when i press my BLABLA button. So far it’s not working. I have to delete the custom attribute, apply a new one and apply my rollout again. Then when i press BLABLA i’ll see the changes i made to my function at work.
It kinda ruins my goal where i was expecting my button BLABLA to re-evaluate myFunction.ms everytime i press it. It seems like it’s baked in the custom attribute.
I tried using FileIn but it hasn’t worked so far. Anybody knows how to get the results that i want?

Thanks for your time and have a good week

6 Replies

I use FileIn to execute changing maxscript files, i mean, i change dinamically the maxscript files that i execute, so i use FileIn in the code to execute it, i think that with include what you do is load the maxscript file the first time, and after that it is in memory, so it will not change even if you change the ms file becuase it’s in memory.

I’m not sure about that, i’m telling that because of what happends to you and what i do in my code.

Cheers.

EDIT: Also whe you use FileIn you don’t need to use the “myFunction()” command, because what FileIn does is execute the ms file, it does not load it in memory, so maybe what you need is to execute this function inside your myFunction.ms file (the one you want to load).

Hi CerberusC,
Thanks for your response. I tried fileIn and it works fine, but as soon as i close max then open my file again i get a problem. When i press my button i get an error message saying:
– Runtime error: fileIn: can’t open file – “myFunction.ms”

Do you know how come i get this error.

Thanks again for your time

FileIn() has to know the location of the file, not just the file name.
When you try to open a file without a path, Max looks in the current directory which changes all the time as you open and close file dialogs. So when you restart Max, the current directory changes to something else and the file cannot be found.

You can either provide the absolute path to the script (bad idea), provide a procedural path based on the current settings, e.g. (GetDir #scripts+”\myFunction.ms”), or set the current directory using sysinfo.currentDir and then call the fileIn without providing a path.

This is another good thing about fileIn() – you can actually build the directory dynamically, while include() cannot use computed directories since it is evaluated at compile time – the only way to set a search path for include() is by using the sysinfo.currentDir property.

Remember that fileIn() is like MAXScript>Run Script – it opens the file and evaluates it in global scope. So if myFunction.ms contains something like ‘fn myFunction = (…)’, myFunction will end up in the global scope (which is good in this case).

If you were using include() though, the code would end up in the scope of the Custom Attribute.
Think of Include() as a Copy&Paste in the editor, but at compile time. It does not run the included code, it inserts its stream of characters into the source code you are compiling, then the resulting code is evaluated. Thus, you can do some crazy things with Include(), but it does not reload dynamically unless you reevaluate the whole code (as you found out in the original post).

Hope this helps.

I was going to say:

“You need to define the path where the script is”

But Bobo explained it a lot better than me

Cheers.

That’s an awesome explanation. Thanks a lot both of you. I’m on my way again now

Have a good week and thanks again for your time!

One advice.

This is the very best and active forum that i’ve seen all over cgtalk, and all over the internet 3d related sites, so when you have a problem or a question, just come here and ask, it will help others in the future and here are some really great people that helps you a lot, i didn’t know absolutly nothing about scripting and all that i’ve learned is thanks to the maxscript help file (thanks bobo) and the people on this forum, this community is really great.

Cheers.