- Open a command prompt window.
- Change directory to the location where 3ds Max is installed. The default is C:\Program Files\Autodesk\3ds Max <version#>.
- Enter the following:
3dsmaxbatch.exe <script_file> [options]
In this syntax, <script_file> is the name of a MAXScript or Python script, and is a required parameter. 3ds Max Batch automatically detects the script type. It can run all MAXScript extensions, and .py, .pyc, and .pyw Python files.
3ds Max Batch starts and loads the specified 3ds Max scene file (if one is provided - this is an optional parameter). It then executes the script_file and any additional inputs if any are provided. It then exits.
3ds Max Batch Options
You can pass one or more of the following as options to 3dsmaxbatch.exe.
- -help
- Show all options.
- -v arg
-
System log verbosity level. Valid arguments are:
- 0 - fatal errors
- 1 - errors
- 2 - warnings
- 3 - process information messages
- 4 - all informational messages
- 5 - debug level messages.
The default is 2.
Note: This parameter only affects messages generated by 3ds Max Batch, not 3ds Max itself. For example, a setting of 5 will not display all messages generated by 3ds Max. See the section below. - -dateFormat arg
-
Date format string for the console log. For example, "yyyy-MM-dd" or "ddd, MM/dd/yyyy"
See https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings for a description of date and time string formats.
- -timeFormat arg
-
Time format string for the console log. For example, "hh:mm:ss" or "ss : mm"
See https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings for a description of date and time string formats.
- -i arg
-
The 3ds Max config file (.ini). Defaults to the per-user default config file (3dsmax.ini).
- -p arg
-
The 3ds Max Plugin config file (.ini). Defaults to the per-user default plugin config file (Plugin.UserSettings.ini)
See the "Plugin.ini" topic in the 3ds Max Developer's Guide for more information
- -listenerlog arg
-
The 3ds Max Listener log file to capture output from the listener. No listener log is created by default.
See the "Turning On the Listener Log" topic in the MAXScript Guide for more information.
- -log arg
-
The 3ds Max system log file. Script errors and exceptions are logged to this file. Defaults to the per-user system log file (Max.log)
- -dm arg
-
Dialog Monitor state. When on, the dialog monitor watches for dialogs from plug-ins, and closes them. Valid choices are: 'on|off', 'yes|no', '1|0' and 'true|false'.
Defaults to off.
For more information about the Dialog Monitor, see the "Interface: DialogMonitorOPS" topic in the MAXScript Guide.
- -mxsString arg
-
MAXScript String Parameter option, where arg = <key>:<value> .
<value> is accessible as a MAXScript string in <script_file> through the maxOps.mxsCmdLineArgs dictionary using <key> as the dictionary key.
The string must be a MAXScript string, meaning it must be enclosed in quotation marks, and any quotation marks or other special characters inside the string must be escaped. The string may be prefixed with an '@' to indicate that it is a verbatim string. See the "String Literals" topic in the MAXScript Guide for more information.
Can be specified multiple times.
- -mxsValue arg
-
MAXScript Value Parameter option, where arg = <key>:<value>.
<value> will be accessible as a MAXScript value in <script_file> through the maxOps.mxsCmdLineArgs dictionary using <key> as the dictionary key.
The <value> parameter must be enclosed in quotation marks.
Can be specified multiple times.
- -sceneFile arg
-
The input 3ds Max scene file to be loaded before <script_file> is executed.
- -safescene <ON|OFF>
- Specifies whether to enable or disable the Safe Scene Script Execution feature for this 3ds Max session. This setting overrides the setting on the Security Preferences tab.
Paths passed as arguments are relative to the current directory, unless fully qualified.
Passing information to the 3ds Max Batch Script
Two command-line options allow you to pass information to the executed MAXScript file, -mxsString and -mxsValue, which pass strings and values respectively. The values are accessible inside MAXScript in the maxOps.mxsCmdLineArgs dictionary as key/value DataPairs.
For example, consider the following command-line invocation:
<3dsmaxpath>3dsmaxbatch demo_mxscmdline.ms -mxsString string1:"Hello" -mxsValue value1:"[3,12,22]" -mxsValue value2:"Point3 3 8 2.3" -listenerLog "test.log"
And demo_mxscmdline.ms script:
opts = maxOps.mxsCmdLineArgs for k in opts.keys do ( format "% == % class: %\n" k opts[k] (classOf opts[k]) )
The listener log test.log will contain the output:
#string1 == Hello class: String #value2 == [3,8,2.3] class: Point3 #value1 == [3,12,22] class: Point3
Python scripts can also access these values through the pymxs.runtime object.
The same script written in Python would look like this:
# demo using pymxs from pymxs import runtime as rt opts = rt.maxops.mxsCmdLineArgs for k in opts.keys: print "{} == {} class: {}\n".format(k, opts[k], rt.classof(opts[k])) # you can also get dict values using runtime.name, for example: # value1 = opts[rt.name('value1')] # or using runtime.execute to run MAXScript code # value1=rt.execute("GetDictValue maxops.mxsCmdLineArgs #value1")
Getting Information About Your 3ds Max Batch Job
- The MAXScript Listener Log captures your commands and all printed output in a text file. By default, 3dsmaxbatch does not create a listener log, but you can specify one by specifying the -listenerlog option.
- The 3ds Max Session Log captures your session to %LOCALAPPDATA%3dsMax\<version#>-64bit\<lang>\network\Max.log by default. You can change the file path using the -log command line option. MAXScript and Python script errors are logged to this file
You can also add messages to the log file via MAXScript. Use the logsystem.logEntry <string> broadcast:true function in MAXScript to log script progress. The broadcast:true parameter indicates that 3ds Max should broadcast this log message to 3ds Max Batch.
You can load a 3ds Max scene file as an argument to 3ds Max Batch (-sceneFile) or in your script with loadMaxFile(). The method you choose depends on how you wish to react to missing plug-ins and xrefs. The loadMaxFile() method provides arguments for dealing with missing plug-ins, xrefs, etc, so your script can react accordingly (see the "Quite Mode" topic in the MAXScript Guide). Loading a file via -sceneFile will print missing plug-in and xref information to the console, so the automation script calling 3ds Max Batch can deal with this information.
Your script can use the maxops.isInNonInteractiveMode() MAXScript method to determine if it is running in a 3ds Max session that has a UI, or in 3ds Max Batch. See the "Interface: maxops" topic in the MAXScript Guide for more information.
Exit Codes
3ds Max Batch will report a non-zero exit code when 3ds Max logs an error.
In addition, 3ds Max Batch will also report the exit code of 3ds Max if it is not success (0).
Your automation tool can check the exit codes from 3ds Max Batch and 3ds Max to determine whether the job was successful, and if not, what caused the issue. On success, 3ds Max Batch exits with exit code 0. 3ds Max Batch will report these exit codes if there was an error with the parameters passed to it or with communication with 3ds Max:
Exit Code | Meaning |
---|---|
0 | Success |
-100 | Missing arguments, or the specified arguments are invalid. |
-110 | The 3ds Max process cannot be started; the specific reason is logged in the console. |
-120 | Communication cannot be established or maintained with the 3ds Max process. |
-130 | 3ds Max reported an error while executing the commands. |
Additional crash codes: | |
-1 | Generic failure, handled exception |
-2 | Unhandled exception |
-3 | Process crashed processing WM_CLOSE |
-4 | Process crashed processing WM_DESTROY |
-5 | Process crashed before the end of WinMain() |
-6 | Out of memory |
-7 | Could not create a valid graphic device |
-8 | License error |
-9 | Could not create the application |
MAXScript also allows you exit 3ds Max with a user-defined exit code. To do this, call quitMax with the exicode argument. For example, this MAXScript:
quitMAX quiet:true exitCode:-314159
This will print the exit code -314159 to the console:
6/12/2018 15:46:05 PM; Specified option script: testscript.ms 6/12/2018 15:46:05 PM; Defaulted option dm: 0 6/12/2018 15:46:05 PM; Defaulted option li: 0 6/12/2018 15:46:05 PM; 3ds Max Install Location: C:\Program Files\Autodesk\3ds Max 2019\ 6/12/2018 15:46:05 PM; 3ds Max Executable: 3dsmax.exe 6/12/2018 15:46:05 PM; Secure Mode: 'OFF' 6/12/2018 15:46:05 PM; Dialog Monitor: Off 6/12/2018 15:46:05 PM; Script command: " -mxs "(filein @\"C:\Program Files\Autodesk\3ds Max 2019\testscript.ms\")"" 6/12/2018 15:46:06 PM; Product version: 3ds Max 2019.2 Update (21.2.0.2095) 6/12/2018 15:46:06 PM; Data collection and use is 'OFF'. 6/12/2018 15:46:30 PM; 3ds Max Exit Code = -314159
C:\Program Files\Autodesk\3ds Max 2019>3dsmaxbatch.exe testscript.ms -v 5