UI

3DS Max allows for the creation of user interface elements. These elements can be hooked up to your other functions to supply data to them interactively.

This section will look at the general method for setting up UI and introduce a few of the controls that are possible. For a full listing of UI controls that are possible please see:

UI dialogs

To illustrate how to create a custom UI lets use an example.

Suppose I had a function that took in a numeric parameter and colour. The function will draw boxes across the x-axis centred at the origin in the colour specified. Each box is a 10 unit cube and there are 10 units separating the boxes. The number of boxes drawn are determined by the numeric parameter.

The code for this function is below:

fn drawBoxes numBoxes boxColour = (
    xLoc = -((numBoxes * 10) + (numBoxes-1)*10)/2 + 5
    for i = 1 to numBoxes do (
        box length:10 height:10 width:10 pos:[xLoc,0,0] wirecolor:boxColour
        xLoc +=20
    )

)

We can obviously run this function by calling it in the script. However, sometimes it is good to create a UI for our functions.

This function accepts 2 values, the number of boxes and the colour. Our dialog will therefore use a simple spinner and a colour picker.

try(destroyDialog myUIExample )catch()
rollout myUIExample "Awesome Box Drawer" (
    group "Controls" (
        spinner numBoxSpinner "Number of Boxes:" type:#integer
        colorpicker boxColourPicker "Box Colour:"
        button createBoxButton "Generate"
    )
    on createBoxButton pressed do(
        drawBoxes numBoxSpinner.value boxColourPicker.color
    )
)
createDialog myUIExample 200 300

The first try/catch line destroys the dialog if it is currently up. This ensures only 1 copy of the dialog is ever shown.

The rollout specifies the look and feel of the UI. Each line specifies a UI element that should be in the dialog.

The group command places all contained UI elements in a labelled box; this helps orgranize and separate controls.

As with all UI, the code is executed based on events. So, depending on the job of the UI, what happens next is dependent on user interaction. In this case, only when the createBoxButton is pressed does anything occur.

The createDialog line brings up the rollout as a window. In the example, the window is specified to be 200 pixels wide and 300 pixels in height.

Running the script will create the following popup:

Last updated