MaxScript Objects and Modifiers

MaxScript gives you script access to pretty much everything you can do using max's interactive ui. There are many builtin objects and it is important to find out how to access it or find more information on it. This chapter will cover a few objects but more importantly it will show you how to find more information about objects.

The Macro Recorder

One of the easiest ways to find the script code needed to create an object is to use the MaxScript macro recorder. This is the area that is in pink at the top of the listener window

If you don't see pink, it is because the divider is right at the top of the window so pull it down.

Make sure the macro-recorder is enabled (in the Macro Recorder menu of listener or in the MaxScript menu of the main window). Once you have enabled it, try drawing an object in the viewport. You will see the MaxScript code in the macro recorder area

One thing to note about the macro recorder is that it records not only creation and changes to object but also changes to things like selection states or the UI. It also operates based on selection and this is not always useful when you actually have to write code as it can have undersirable results.

For example, create a cone with 5 height segments and apply the bend modifier to it and change the bend angle to 45 degrees If you do this, your macro recorder will show something like the following:

Cone smooth:on heightsegs:5 capsegs:1 sides:24 height:24.6557 radius1:10.6764 radius2:-4.67522 mapcoords:on pos:[2.98523,0.427261,0] isSelected:on
modPanel.addModToSelection (Bend ()) ui:on
$.modifiers[#Bend].BendAngle = 45

So the above tells you a few things:

  1. Cone is the name of the cone object, it shows you the parameters that you can set to create the object.

  2. the second two llines adds the modifer Bend() then changes the angle of that modifier.

Unfortunately the way this is done is how it is done interactively. The modPanel.addModToSelection has to do with accessing the modifier from the modifier panel in the UI. Similarly the $ refers to the selected object.

If we applied the script exactly as our results would be very slow and behave wierdly.

The following snippet will cause our ui to flicker as it runs and it would be much slower than it needs to be:

for i = 1 to 100 do(
    x = random -100 100
    y = random -100 100
    c = cone heightsegment:5 pos:[x,y,0]
    select c
    modPanel.addModToSelection (Bend ()) ui:on
    $.modifiers[#Bend].BendAngle = 45
)

Observe how the ui flashes as it plays through the loop.

A much better solution is as follows:

for i = 1 to 100 do(
    x = random -100 100
    y = random -100 100
    c = cone heightsegment:5 pos:[x,y,0]
    addModifier c (Bend angle:45)
)

As you can see the second version is much faster and doesn't cause ui to flicker.

However, the macro recorder does give us hints as to things like names of modifiers and their arguments. This makes it useful.

Showclass

Showclass is a function you can call to find the poperties of an object as well as objects with a certain name

showclass <string>

the string is allowed to include the wildcard (*) character and behaves as you would expect a wildcard character to behave.

For example, if you want to find all objects with the word "material" in it, you can use:

showclass "*material*"
-- note the double quotes is necessary and won't work without it.

If you want to find the members of a specific classs, you can do the following:

showclass "cone.*"

This will give you the name of the data members of the object.

Last updated