Calling MAXScript from C++

Executing String Expressions

The global function ExecuteMAXScriptScript() can be used to execute MAXScript from C++. This function has the following signature:

BOOL ExecuteMAXScriptScript(MCHAR *s, BOOL quietErrors = FALSE, FPValue *fpv = NULL);

This takes a maxscript expression in the form of a string. It does not take a filename. If the string is successfully compiled and executed by the MAXScript script engine, and a pointer to an FPValue is provided, any value returned from the script is converted to an FPValue and returned through the fpv parameter.

If the string is not successfully compiled and evaluated, error messages are written to the MAXScript listener or logged using LogSys. If net rendering, or the quietError argument is TRUE, error messages with only be logged using LogSys.

This function returns TRUE if the script was compiled and executed successfully.

Executing Script Files

3ds Max 2013 now exposes two functions for executing maxscript files from C++ code. These two methods are detailed below:

void filein_script(const MCHAR* filename = NULL);

This takes a string containing the fully qualified path to a maxscript file. If the filename parameter is NULL, then a dialog will open prompting the user to select a file.

BOOL filein_script_ex(const MCHAR* filename, MCHAR* error_message);

This is similar to the method above, and in fact is called by filein_script. This file can handle maxscript files (*.ms), macroscript files (*.mcr), maxscript zip files (*.mzp) and encrypted maxscript files (*.mse). This method takes an extra out parameter which will contain an error message if one should occur.

Note all methods described here are found in maxscript.h and are exported from the maxscript dll file.