Running Scripts
To run an existing script file, press the "Run Script" button on the MAXScript utility rollout, File > Run Script in the Listener menu bar, or MAXScript > Run Script in the 3ds Max menu bar. This opens a common File Open dialog for choosing the script. MAXScript then reads and executes the selected script. Any output is printed to the Listener output pane.
You can also run a script from Listener or from within other scripts using fileIn()
or executeScriptFile()
.
fileIn
fileIn <filename_string> [ quiet:<boolean> ]
where <filename_string>
is a string literal or an expression that evaluates to a string, and specifies the name of the script file whose content is executed. The script file content is executed one expression at a time, and halts processing if an error is encountered at any point. By default, the file is not listed as it is loaded; use quiet:false
to have the file contents printed to the Listener.
See File Access Function Search Behavior for a list of directories the filename_string
is searched for if the full path is not specified.
EXAMPLE USAGES ARE:
fileIn "my_script.ms"
or
scriptfile="my_script.ms"
fileIn scriptfile
The script file content is compiled in a global scope context, as opposed to the scope in effect when the filein()
method is executed. For more information, see Scope_of_Variables.
The fileIn()
method looks for scripts in the specified directory if <filename_string>
contains a path as part of the file name. If no matching file is found, it then looks in the following locations, in order:
- The current MZP package (if applicable)
- The directory where the currently running script is located.
- The user scripts directory
- The 3ds Max system scripts directory
As of 3ds Max 2022.1 Update, fileIn()
no longer searches the following locations:
- The current working directory
- The 3ds Max main directory
- The Windows system32 directory
- The Windows system directory
- The Windows directory
- Directories in the PATH environment variable.
executeScriptFile
<boolean>executeScriptFile <filename_string> [errormessage:<&variable>]
The executeScriptFile()
function is similar to fileIn()
, and takes the following parameters:
Available in 3ds Max 2021.1 Update and higher.
- filename_string: a fully qualified file path and filename. This function does not search in 3ds Max and system directories for a file, the filename cannot be relative.
- errormessage: specifies an optional by-reference parameter that will contain any errors generated by the script, or undefined if there are none.