Updated 3ds Max Batch - 3

By Nicolas Holst - 8 Dec, 2017 - 3ds Max

So the python hinted at in the Updated 3ds Max Batch - 1 post is:

import MaxPlus
from pymxs import runtime as rt

# get hold of the parameters
# 1. the filename of the file to load, from the filename mxsString
# 2. the name of the box, from the boxname mxsString
filename=rt.execute("GetDictValue maxops.mxsCmdLineArgs #filename")
rt.execute("logsystem.logEntry (\"Filename: \"+(GetDictValue maxops.mxsCmdLineArgs #filename)) broadcast:true")

boxname=rt.execute("GetDictValue maxops.mxsCmdLineArgs #boxname")
rt.execute("logsystem.logEntry (\"Boxname: \"+(GetDictValue maxops.mxsCmdLineArgs #filename)) broadcast:true")

# first load the max file
# original maxscript code = loadmaxfile "\\\\\\\\fara06253\\\\backburner\\\\scenes\\\\myfile.max"
fm=MaxPlus.FileManager
fm.Open(filename)
rt.execute("logsystem.logEntry \"file was opened\" broadcast:true")

# now create the box
# original maxscript code = b=box name:"test"
box = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Box)
node = MaxPlus.Factory.CreateNode(box)
# and change the name
node.Name=boxname
rt.execute("logsystem.logEntry \"box object was created\" broadcast:true")

# and save the file under a new name
#savemaxfile "\\\\\\\\fara06253\\\\backburner\\\\scenes\\\\myfile.max"
filename=filename[:-4]+"_py_boxed"+".max"
fm.Save(filename)
rt.execute("logsystem.logEntry \"file was opened\" broadcast:true")


# and we exit Max Batch
# original maxscript code = --quitMax #noPrompt
# no need to do this anymore, 3ds Max Batch will exit at the end of the script
rt.execute("logsystem.logEntry \"job done\" broadcast:true")

Quick explanation: in order to get the command line parameters we use the rt.execute("GetDictValue maxops.mxsCmdLineArgs #parameter_name"). So that uses MaxScript to get the value from the dicotrionary that gets pased on the command line. To print information to the logfile we use the MaxScript logsystem.logEntry "string" broadcast:true calls.


Running the following on the command line:

E:\d\backburner>"c:\Program Files\Autodesk\3ds Max 2018\3dsmaxbatch.exe" add_a_box.py -mxsString filename:"//fara06253/backburner/test.max" -mxsString boxname:"test" -log "//fara06253/backburner/max_py.log"


The output is:

12/8/2017 15:44:59; 3ds Max Install Location: c:\Program Files\Autodesk\3ds Max 2018\
12/8/2017 15:44:59; 3ds Max Executable: 3dsmax.exe
12/8/2017 15:44:59; Secure Mode: 'OFF'
12/8/2017 15:44:59; 3ds Max Log File: "\\fara06253\backburner\max_py.log"
12/8/2017 15:44:59; Script command: " -mxs "((maxOps.mxsCmdLineArgs = dictionary #name 'filename':\"//fara06253/backburner/test.max\" 'boxname':\"test\"); python.ExecuteFile @\"E:\d\backburner\add_a_box.py\")""
12/8/2017 15:45:00; Product version: 3ds Max 2018.4 Update (20.4.0.4254)
12/8/2017 15:45:00; Data collection and use is 'ON'. Change your participation anytime in the Help menu of 3ds Max.
12/8/2017 15:45:48; Task Completed Successfully


Checking what the exit code was:

E:\d\backburner>echo %ERRORLEVEL%
0


And the contents of the log file is:

2017/12/08 15:45:00 INF: [144244] [81928] Application started with secure mode state 'OFF'
2017/12/08 15:45:00 INF: [144244] [81928] Product version: 3ds Max 2018.4 Update (20.4.0.4254)
2017/12/08 15:45:00 INF: [144244] [81928] Data collection and use is 'ON'. Change your participation anytime in the Help menu of 3ds Max.
2017/12/08 15:45:01 DBG: [144244] [81928] Could not find the specified file in DefaultSettingsParser::parse()
2017/12/08 15:45:11 DBG: [144244] [81928] Graphics driver requested by the user : Nitrous
2017/12/08 15:45:11 DBG: [144244] [81928] Graphics driver actually created in the viewports : Nitrous DX11 SW
2017/12/08 15:45:20 DBG: [144244] [81928] At Nitrous init, the OGS graphics device requested is : Nitrous DX11 SW
2017/12/08 15:45:20 DBG: [144244] [81928] At Nitrous init, the OGS graphic device actually created is : Nitrous Software (= Direct3D 11 WARP )-
2017/12/08 15:45:25 DBG: [144244] [81928] Starting network
2017/12/08 15:45:43 DBG: [144244] [81928] Filename: //fara06253/backburner/test.max
2017/12/08 15:45:43 DBG: [144244] [81928] Boxname: //fara06253/backburner/test.max
2017/12/08 15:45:43 DBG: [144244] [81928] Interface8::LoadFromFile(//fara06253/backburner/test.max)
2017/12/08 15:45:43 INF: [144244] [81928] Starting to load file: //fara06253/backburner/test.max
2017/12/08 15:45:44 INF: [144244] [81928] SYSTEM: Production renderer is changed to Scanline Renderer. Previous messages are cleared.
2017/12/08 15:45:44 DBG: [144244] [81928] WARNING: The Populate data is missing on your system.
2017/12/08 15:45:44 INF: [144244] [81928] Done loading file: //fara06253/backburner/test.max
2017/12/08 15:45:44 INF: [144244] [81928] SYSTEM: Production renderer is changed to NA. Previous messages are cleared.
2017/12/08 15:45:44 INF: [144244] [81928] SYSTEM: Production renderer is changed to Scanline Renderer. Previous messages are cleared.
2017/12/08 15:45:45 DBG: [144244] [81928] file was opened
2017/12/08 15:45:45 DBG: [144244] [81928] box object was created
2017/12/08 15:45:45 INF: [144244] [81928] creating file //fara06253/backburner/test_py_boxed.max.sv$
2017/12/08 15:45:46 INF: [144244] [81928] deleting backup file C:\Users\40578\Documents\3dsMax\autoback\MaxBack.bak
2017/12/08 15:45:46 INF: [144244] [81928] renaming //fara06253/backburner/test_py_boxed.max to C:\Users\40578\Documents\3dsMax\autoback\MaxBack.bak
2017/12/08 15:45:46 INF: [144244] [81928] renaming //fara06253/backburner/test_py_boxed.max.sv$ to //fara06253/backburner/test_py_boxed.max
2017/12/08 15:45:46 DBG: [144244] [81928] file was opened
2017/12/08 15:45:47 DBG: [144244] [81928] job done
2017/12/08 15:45:47 INF: [144244] [81928] StartupTemplate factoryTemplateFolder: c:\Program Files\Autodesk\3ds Max 2018\en-US\StartupTemplates
2017/12/08 15:45:47 INF: [144244] [81928] StartupTemplate userTemplateFolder: C:\Users\40578\Documents\3dsMax\startuptemplates
2017/12/08 15:45:47 INF: [144244] [81928] StartupTemplate appdataTemplateFolder: C:\Users\40578\AppData\Local\Autodesk\3dsMax\2018 - 64bit\ENU\en-US\StartupTemplates
2017/12/08 15:45:49 DBG: [144244] [81928] Stop network

Posted By
Published In
Tags
  • 3ds Max
  • Film & VFX
  • Games
  • Design Visualization
0 Comments
To post a comment please login or register