Drawing a Box with MAXScript

In the previous lessons you have seen some of MAXScript's useful capabilities; however, nothing that is visible in the interface. MAXScript is also useful for working with regular objects, such as boxes or cylinders. You can draw a box in MAXScript just by entering the box() command:

box()

This creates a box with the default parameters. It is generally better practice to assign an object to a variable, so you can later refer to it by name and manipulate it using that name:

mybox = box()

When you use MAXScript to create an object without specifying any parameters, it is important to use empty parentheses, "()". This tells MAXScript to use the default parameters for the object. If you want to specify any of the parameters during creation, such as the size or location of the object, you do not need parentheses. For example:

mybox = box length:20 width:20 height:20

MAXScript returns the box object name and the position of the box:

This example creates a box, and supplies three parameters: the length, width, and height of the box. The parameter names are followed by a colon and then by the value for that parameter. You can enter all parameters, without any punctuation between them. MAXScript returns the following statement:

$Box:Box01 @ [0.000000, 0.000000, 0.000000].

The first part of the statement is called a pathname. A pathname in MAXScript is similar to a pathname in Windows, such as c:\3dsmax\examples\file.max, which represents a path through a hierarchy of directories pointing to a particular file. In MAXScript, a similar path concept is used. However paths in MAXScript end up pointing to objects, not files. Pathnames in MAXScript always begin with the "$" character. For more information on Pathnames, see the Pathname Literals topic in the MAXScript reference.

The second part of the statement is the object name: Box01, in this case. This name appears in the Select Object dialog when you use the Select by Name toolbar button in 3ds max. It is not the name of your box variable, which is mybox. This variable is merely a placeholder that points to the object, Box01.

The values inside the brackets represent the x, y, and z coordinates of the center of the box.

MAXScript also draws the box in the viewports, as shown in this perspective viewport:

Notice that you can use Undo (as you can with most MAXScript creation and modification commands) to remove the box from the scene.

Next Topic

Modifying the Box