Running Scripts from the Command Line

You can launch 3ds Max from a DOS command line and have it run a specified launch script, which is useful for tasks such as unattended batch-rendering. This capability uses the existing- U command line switch that names a utility to be run when 3ds Max is started. The- U switch allows an optional extra argument which, for MAXScript, is taken to be the name of the launch script to run. The case of MAXScript must be as shown in the following example:

c:\3dsmax\3dsmax -U MAXScript rendercams.ms

This example command line would launch the 3ds Max executable in c:\3dsmax, start MAXScript, and then have it run the launch script rendercams.ms.

The following example launch script loads two scenes, renders frames from each of the cameras in them, and then quits 3ds Max:

loadMaxFile "foo.max"
for c in cameras do render camera:c outputfile:("foo_"+c.name+".bmp")
loadMaxFile "baz.max"
for c in cameras do render camera:c outputfile:("baz_"+c.name+".bmp")
quitMax #noPrompt

This example makes use of the quitMax() method to exit 3ds Max (see Exiting and Resetting3ds Max) when the script is finished. Launch scripts need not be batch scripts as in this example, but may be used to condition 3ds Max for interactive use, for example by loading a scene file and setting some user-interface options.

The normal startup scripts, startup.ms and those in the Startup Scripts directory, are run before the launch script.

It is also possible to install scripts into individual scene files that run automatically when that scene is open or closed or at certain other events (see General Event Callback Mechanism).

NOTE:Command line -U MAXScript startup scripts are run *after* 3ds Max has completely booted and the standard MAXScript stdscripts and scripts\startup scripts have been run.