MAXScript Tools and Interaction with 3ds Max > Creating MAXScript Tools > Scripted Utilities and Rollouts > Rollout User-Interface Controls > Rollout User-Interface Controls Types >

# Radiobuttons UI Controls

User Interface Controls > Common Properties > Layout > Types > Radiobuttons

| Creating User Interfaces - Quick Navigation

A radiobuttons control is used to place a set of radio buttons on the rollout, only one of which can be checked at a time. The user can click different buttons in the set to change states.

The syntax is:

    radiobuttons <name> [<caption>]	labels:<array_of_strings> \
    [tooltip:{<string>|<array_of_strings>}] \
    [default:<number>] [columns:<number>] [offsets:<array_of_point2s>]

The default alignment of radiobuttons items is #center .

EXAMPLE:
     --Create some scene objects. Select them, then run the script:
    (
    local obj_array = selection as array
    local obj_name_array = for o in obj_array collect o.name
    rollout CloneObject "Clone Object" (
    radiobuttons copy_type labels:#("copy", "instance", "reference")
    radiobuttons which_obj labels:obj_name_array -- computed label array
    button do_it "Copy Object"
    fn updateButton = (
    do_it.text = case copy_type.state of (
    1: "Copy "
    2: "Instance "
    3: "Reference ")
    do_it.text += obj_name_array [which_obj.state]
    )--end fn
    on copy_type changed state do updateButton()
    on which_obj changed state do updateButton()
    on CloneObject open do updateButton()
    on do_it pressed do (
    copyfn = case copy_type.state of (
    1: copy
    2: instance
    3: reference)
    if which_obj.state > 0 do copyfn obj_array[which_obj.state]
    )--end on pressed
    )--end rollout
    if obj_array.count > 0 do createDialog CloneObject
    )--end script

Parameters:

    labels:<array_of_strings>

An array of strings that specifies the number of radio buttons and the text label for each one.

    default:<number>

The number of the radio button initially selected. Default is 1.

When set to 0, none of the radio buttons will be selected.

    columns:<number>

Number of columns across in which to arrange the buttons. By default, MAXScript will attempt to lay out all the radio buttons side-by-side on one line, and if they won't fit, vertically in a single column. You can force the layout system to array the buttons in multiple columns using this parameter. Each column is given the same width, which is the width of the widest label in all columns and it left-adjusts the radio buttons in these columns.

EXAMPLE:
     --create radio buttons with two columns:
    rollout testRollout "Test Size"
    (
    radiobuttons rad_buttons "Size:" labels:#("Big", "Bigger", "Biggest", "Huge") columns:2
    )
    createDialog testRollout

    tooltip:{<string>|<array_of_strings>}

Provides optional tooltip or tooltips for the radio buttons.

If string is specified, that string is used as tooltips for all radiobuttons.

If an array of strings is specified, the array size must be the same as the labels array size and the corresponding array element is used for each radiobutton.

Available in 3ds Max 2012 and higher.

Example script:

EXAMPLE:
    rollout MyRollout "Untitled" width:162 height:300
    (
    radioButtons rdo1 "RadioButtons" tooltip:"Test Tooltip 1" labels:#("Button1", "Button2")
    radioButtons rdo2 "RadioButtons" tooltip:#("Test Tooltip 2","Test Tooltip 3") labels:#("Button1", "Button2")
    radioButtons rdo3 "RadioButtons" labels:#("Button1", "Button2")
    -- radioButtons rdo4 "RadioButtons" tooltip:#("Test Tooltip 4") labels:#("Button1", "Button2")
    button btn1 "Button" tooltip:"Test Tooltip 5"
    )
    createdialog MyRollout

    --Enabling the remarked rdo4 will cause
    --an error because the number of tooltip items
    --does not match the number of labels items

    offsets:<array_of_point2s>

Provides optional radiobutton offsets to adjust the labels layout within the control.

The array size must be the same as the labels array size and the corresponding array element is used for each radiobutton.

The offsets are set once at creation time and cannot be modified later.

Available in 3ds Max 2013 and higher.

Example scripts:

EXAMPLE:
    rollout testRollout "Big Deal Script"
    (
     radiobuttons rad_buttons "Deal:" columns:1 \
       labels:#("Big", "Bigger", "Biggest", "Huge") \
       offsets:#([0,0], [10,0], [20,0], [30,0])
     button btn_dosomething "Do Something..."
    )
    createDialog testRollout
The left screenshot shows the same dialog without the offsets: parameter. Note that the default #center alignment takes into account the new width of the control's bounding box, and the offsets are relatively to the original position of the radiobutton item.

EXAMPLE:
    rollout testRollout "Big Deal Script"
    (
     radiobuttons rad_buttons "Deal:" columns:1 \
       labels:#("Big", "Bigger", "Biggest", "Huge") \
       offsets:#([0,0], [0,0], [10,5], [10,5])
     button btn_dosomething "Do Something..."
    )
    createDialog testRollout
Note that the offsets are NOT cumulative when using one column - offsetting the 3rd label horizontally by 10 does not affect the 4th item - it also needs a horizontal offset of 10 to stay in line. Similarly, to offset the last two labels vertically as a block, both need the same vertical offset of 5, otherwise they would overlap.

EXAMPLE:
    rollout testRollout "Big Deal Script"
    (
     radiobuttons rad_buttons "Deal:" columns:2 align:#left \
       labels:#("Big", "Bigger", "Biggest", "Huge") \
       offsets:#([30,-16], [0,-16], [30,-16], [0,-16])
     button btn_dosomething "Do Something..."
    )
    createDialog testRollout
Note that the horizontal offsets are cumulative when using more than one column - offsetting the first and third items by 30 also shift the horizontal position of the second column, so we don't need to offset its labels. At the same time, all 4 labels need a vertical offset of -16 to move up together as a block - the vertical offset is not cumulative. We use align:#left to anchor the control in the same place in the dialog.

Properties:

    <radiobuttons>.state Integer

The number of the currently selected radio button in the order specified in the labels: array, or 0 if none is selected.

EXAMPLE:
    rollout testRadioButtons "Test RadioButtons"
    (
    -- Define 2 radio buttons with the first button selected
    radiobuttons radButtons labels:#("First","Second") default:1
    -- When the button is pressed, clear the radio buttons selection!
    button setToNone "Clear Buttons Selection"
    on setToNone pressed do radButtons.state = 0
    )
    createDialog testRadioButtons

Events:

    on <radiobuttons> changed <arg> do <expr>

Called when the user clicks one of the radio buttons in the set. The <arg> argument will contain the new state of the radio buttons array, which is the 1-based number of the newly selected button.

    on <radiobuttons> rightClick do <expr>

Called when the user right-clicks the Radiobuttons control.

Available in 3ds Max 2010 and higher.

#### See Also

- Rollout User-Interface Items Common Properties

- Rollout User-Interface Items Common Layout Parameters

- Rollout User-Interface Control Types

- Similar Controls

- Listbox

- Dropdownlist

- Combobox

- MultiListBox

- PopupMenu