Back

Tricks with Scripts

The primary focus of this month’s article will be to provide users with a few tricks using the MAXScript language that might save time.  MAXScript is the built-in scripting language constructed to assist users with manipulating 3ds Max® and objects within it. The goal of this article is to show how simple it can be to use scripts I’ve created for various tasks, but if you’re interested in learning the MAXScript language there is a ton of material available in the forums, 3DS Max help files, and the web.

To use the scripts provided, users need to be familiar with the MAXScript Listener, which is an interpreter for the MAXScript language.  Basically it processes what we type, similar to a calculator. In fact, we could simply type 2 + 2 then press Enter and the Listener would display 4 as a result.  There are a few ways to open the Listener. The default key is F11. Users can also navigate to the MAXScript menu and select it or they can right-click over the white and pink bars on the lower left of the screen and select it there. 

To use a script provided, copy them into the Listener window and then press Enter.

Script 1: Replace Objects

This first script replaces multiple selected objects and converts them to another object the user selects. First, select the objects you wish to change, then enter the script into the Listener window (don’t forget to press the Enter key when done). Next select a source object to convert them to, as shown in Figure 1.

Enter this script into the Listener:

Figure 1: Replacing objects with a script

Script 2: Assign Random Materials

This script assigns random materials to objects from material in your editor slots. I’ve found it useful for everything from wood floors and block walls to candy in candy jars.  First create the materials you wish to use, then select your objects and enter the following script into your Listener window:

The numbers one and five in the script represent the first and fifth slots in your material editor. The script will randomly assign materials in slots one, two, three, four, and five to your selected objects as shown in Figure 2.

Figure 2: Assign random materials with a script

If you’d like to create random materials quickly, you can use the script below: 

To create 100 teapots to test it these on, such as those in Figure 3, use the following script:

Figure 3: 100 teapots with a script

Script 3: Move Objects Randomly

This script is extremely useful for tiling objects randomly and can make very interesting animations.

Enter this script into the Listener:

The values in the brackets represent the x, y, and z values. With the example provided, we are moving the objects randomly between negative three units to positive three units as shown in Figure 4.

Figure 4: Move objects randomly with a script

Script 4: Scripting with a User Interface

This next example will need to be created in the MAXScript editor in order to create a user interface box like the one shown in Figure 5. 

Figure 5: UI created from example script

The editor can be opened from the Scripting menu. Once the script is typed in, save it to a location on your computer. After the file is saved, select “Run Script” in the script menu to load your new file. The script we are using is shown below:

This script demonstrates how simple it is for a user to create an interface like that shown in Figure 5 with buttons that will create a box, sphere, or anything else we would want. For example, if I wanted to change the “Box” button to use the script that randomly assigns materials to selected objects, I’d simply have to replace that portion of code as shown in Figure 6. (insert Figure 6 – Altered Interface with Modified Script.jpg)

Figure 6: Altered interface with modified script

Appears in these Categories

Back