February 12, 2012

Dynamic UI creation with MaxScript

There are 3 ways to dynamically modify a MaxScript UI.

One way to to create all the UI elements you need in order to disable and enable them as needed. (This is the most common method)

A similar method is to use their visible property to turn them off and on.

The most complex way is to generate a maxscript on the fly and use the execute command to create the UI elements.

This script has an example of each method: Martinez_DynamicUI.ms


  1. also do not forget to mention the "rolloutCreator", this is a standard maxscript structure of functions for dynamically creating rollouts.

    the system behind it is identical as executing a string that describes the rollout.

    example :

    rci = rolloutCreator "myRollout" "My Rollout"


    rci.addControl #button #myButton "My Button"

    rci.addHandler #myButton #pressed filter:on codeStr:"MessageBox @Isn't this cool@ title:@Wow@"

    createDialog (rci.end())

    1. Wow thanks, I actually never used that method. Thanks for the tip!

  2. hi, great tips, this what i'm exactly looking for. But when i try to implent this i cannot reach dynamicaly created ui elements. the code is below it throws out an error when i try to reach dropdown list. And it sees everyting dynamicaly created as undefined.

    DynamicUIRollout = newRolloutFloater "Dynamic UI" 200 300

    rollout UIDialogTest "Submaterial Instancer" width:200 height:300
    local UInum = 1
    local multiMat
    local nameArray = #(#(),#())

    button btnExecute "Pick Material" pos:[5,5]
    button btnStart "Start Instancing" pos:[90,5]

    on btnExecute pressed do
    if classof $.mat == multimaterial then
    multiMat = $.mat
    for i = 1 to multiMat.count do
    nameArray[1][i] = multiMat[i].name
    nameArray[2] = copy nameArray[1] #nomap
    sort nameArray[1]
    print nameArray[1]


    UIcode = "rollout subRoll" + UInum as string + " \"Choose Materials to instance" + "\"\n"
    UIcode += "("

    UIcode += "dropdownList drop" + i as string + "\"" + "Base Mat" + "\"width:165 height:15 border:false \n"

    for i=1 to multiMat.count do
    UIcode += "checkbox btnMat" + i as string + "\"" + nameArray[1][i] + "\"width:165 height:15 border:false \n"
    UIcode += ")"
    UIcode += "addRollout UIDialogTest" + UInum as string + " DynamicUIRollout"
    execute UIcode

    UInum += 1

    drop.items = nameArray[1]


    on btnStart pressed do
    print UIDialogTest.controls[i]

  3. Good work, Thanks to share your nice information and the blog. Please keep sharing.

  4. informative method.


  5. This is really informative post.


  6. This is very helpful thanks for sharing this. http://www.clippingserviceindia.com/

  7. So useful and effective blog you have published . Its also informative . Thank you for shared this well blog . Clipping Path | Remove White Background | Product Photo Editing