[Closed] Include and script path
Hi,
How to point to a specific script file when using “include” where it’s not allowed to use variables in the script name?
include “script.ms”
where it actually should be something like:
include ((GetDir #maxroot)+”\folder\script.ms”)
The last line is no option since “include” doesn’t allow that.
How can I properly point to a specific file when I don’t know where max is installed?
Thanks,
Davy
actually that should work fine. Check the string you’re getting from the expression, you have a double backslash in the expression, and that will point to an invalid folder:
include ((GetDir #maxroot)+"\\folder\\script.ms")
--equals to: "C:\Program Files\Autodesk\3ds Max 2011\\folder\script.ms"
--that should be:
include ((GetDir #maxroot)+"folder\\script.ms")
…are you sure?
Cause the help file says this about “include”:
“This is a compile-time construct, therefore the file name specification must be a string literal, and not a variable or an expression.”
Davy
you’re right, and checking the mxs help i’ve found that there’s 2 kind of include… one evaluate the script, the other only inserts the file’s content into the listener output pane. Both are named equally, and only the second one accepts expressions. (the joy of maxscript).
Try filein instead of include, that should work
M
Yes but the reason of using “Include” is because it differs from “FileIn” where “Include” does not just read the file at script load but only when the script needs the file, making less code to execute at start.
Unless the help file is not correct
So if “Include” does not allow variables in the string, how can you efficiently load files from different locations?
Davy
Ok, now just guessing, but maybe using execute <string> could work, something like
myString = "include \""+(GetDir #maxroot)+"folder\\script.ms\""
execute myString
Executing will turn “include” into a “filein”.
Isn’t there an option to tell max where to search for scripts?
I know it’s in the max ini file but through command?
Davy
One more things , I want to add . In the Max root directory. A folder called scripts . And when your scripts file in this folder . Just use
include "scripptsfilename"
. It’s works fine for me.
…yep, I know that works since that path is setup by default as your main script path.
So I think it’s only possible to change that in max ini
No other way to load include scripts, or you know the exact path or next to the script that executed it (in my case a macroscript in the ui/macroscript folder) or in default scripts folder.
Davy
There ARE Symbolic Paths that can be used in the include – they start with a $ sign and point at various system directories. The most useful one is $scripts.
include “$scripts\ est\ est.ms”
is equivalent to
include “C:\Program Files\Autodesk\3ds Max 2010\scripts\ est\ est.ms”
on my machine (YMMV).
Alternatively, you can skip the file name completely and make sure the current directory is set to the place where the scripts are located.
For example, I created a test.ms file containing ‘print “Hello World”’ in a test folder under the Scripts folder and run this in the Listener:
sysinfo.currentdir --check the current dir, it was pointing at \Scenes
-->"C:\Program Files\Autodesk\3ds Max 2010\scenes"
include "test.ms" --try to include my script - it wont be found unless it is in \Scripts
-- Runtime error: Include cannot open: test.ms
sysinfo.currentdir = "$scripts\ est" --change the current dir to the \Scripts est\ folder
--> "$scripts est"
sysinfo.currentdir --check to see if it worked - it did!
--> "C:\Program Files\Autodesk\3ds Max 2010\scripts est"
include "test.ms" --include the file now without a path prefix
--> print "Hello World"OK
This of course could get tricky depending on the structure of your code, so using the symbolic paths is probably the best way to go. Check out the “Symbolic Pathnames” topic in the MXS Help.