Automating Output with MAXScript

One of the advantages of using Autodesk VIZ is the potential to use its powerful scripting language called MAXScript to reduce repetitive tasks. I'd like to give you a script that I've written to help with the more complex scenes you may be creating in your own projects. What if there are a few hundred objects in your 3D scene? Who would want to manually repeat the object-rendering steps that many times? In fact, by itself this MAXScript is worth the price of this book when you consider how much time it can save you.

Fortunately, you don't have to learn any MAXScript to take advantage of an automated object-rendering pipeline; you can just run my script. However, the script provided in the Chapter 7 folder on the companion CD is commented and easy to understand. If you have any interest in programming, this script might be an entry point for you to explore the benefits of solving tedious tasks with code.

1. Close the Selection Floater and/or Material Editor dialog boxes if they are still open from the previous section.

2. Click the Utilities tab of the Command Panel.

3. Click the MAXScript button to display a new rollout.

4. Click the Open Script button to open the Choose Editor File dialog box.

5. Navigate to the companion CD and open the file A MAXScript window appears with color-coded text (see Figure 7.15). A version of this image appears in the color section.

Figure 7.15

RenderMatte MAXScript


Ectt 5earch Hdp

dedne acclans


—Get Path button

on pathco pressed do (

--get selected path as string

global new_path - getSavePath()

—Statu Rendering button

on tiowgo pressed do [

—get ail objects in an array

scene_nodes - geometry as array

—loop through all objects

for i in scene_nodes do (

—select the ith object in the scene

select i

—select inverse

actionHan.executeAction 0 "40044"

--turn undo recording on so that we can restore the original material later

undo cm [

—assign material to selection

S.naterlal = HatteShsdou opaqueAlphajfalse affectAlpha:false receiveShadous


bac&groundColor - color 0 0 0

| - end undo control

--set Targa format to 32 bits/pixel, coapreased, not split, store alpha

targa. itgaio.setColorDepth(32>

targa. i tgai o - se tC ofcpr essed (true)


targa.itgal tP reHultAlpba(true)

-render as tga to chosen path

render outputFile: (new_path + + i,naae +■ Ir.tga"} v£b:o£f

—undo the natte Material application

nax undo

]—end Cor

—select none

actionHan.executeAction 0 "40043"

--notify user oE completion

messageBox "Done" title;"Render Matte"

]—entf on


-end utility




Read through the code and notice what is happening. The script starts by defining the user interface. An output path is then recorded, and the Start Rendering button starts looping through all the objects in the scene. Within the loop, an object is selected, and then the selection is inverted. Undo recording starts, and the Matte/Shadow material is assigned to the selection. The background color is set to black, the Targa options are set, and the file is saved as an RGBA image. An Undo restores the original materials. The next object is then processed in exactly the same way, and so on. At the end of the loop, the user is notified that the processing is done.

The script executes the same steps you performed manually in the last section. The great benefit is that now you merely have to start the processing and you can walk away from the computer while the processing takes place.

6. To interpret the code, choose File > Evaluate All from the MAXScript window, and then close the MAXScript window. On the Utility tab of the Command Panel, click the Utilities drop-down list box in the MAXScript rollout and select Render Matte to display a new rollout.

7. You may have to scroll the panel upward to see the Render Matte rollout if your screen is set to a low resolution. You'll see a Render Matte rollout (see Figure 7.16) at the bottom of the Utility panel; inside this rollout, click the Get Path button.

Figure 7.16

The Render Matte rollout

Hmda HdltE

Ctrcese Otilpw: Prfh F:tst

Mends tech Ubpcl Shalt Render tie T Ns coijd teke e ft+ile...

Renders each ob.efi to T GA "hi fi ee! ese Is matted ttlp:^Sccltarritc(Lcctn tkise |

WARNING Choose the output path before starting the rendering process. If you don't, the script will not save your renderings. Note that the renderings use the output size settings in the Render Scene dialog box.

8. Select a folder on your hard drive to save the renderings in the Browse For Folder dialog box and click OK. Then click the Start Rendering button once. When the renderings are completed, a small dialog box informs you that the processing is complete.

Figure 7.17 shows the Targa files output by the MAXScript in Windows Explorer; there will be one file per object in the 3D scene. Be patient while the renderings are processed; there is no progress bar to indicate how long it might take. The high-rise project should only take about a minute (there are nine objects), but complex projects can take much longer.

Figure 7.17

Rendered Targa files output from MAXScript

to Output


1 Fie Edit View Favorites Tods Hefc fl^jjjj

+-ri: l • 4 ' a ^Search -_^jFddcrs


>< tti m*

Mn r^ j




1 Type


248 KB



438 KB

TC-A Fie

62 KB


Glass Rioht.tga

304 KB



213 KB



341 KB



55 KB



94 KB



41 KB





11.75 MB

My Computer


In your own projects, do a few test renders using the procedure in the earlier "Rendering Matted Objects with Alpha Channels" section. This will give you a sense for how long an average object takes to render. Multiply the number of objects in your scene by your best guess for an average frame time, and you'll have an idea how long the entire process will take. Then use the RenderMatte MAXScript to automate the process while you make better use of your time.

0 -1

Post a comment