MAXScript Tools and Interaction with 3ds Max > Creating MAXScript Tools > Scripted Utilities and Rollouts >

# Accessing Locals and Other Items in a Rollout from External Code

| Creating User Interfaces - Quick Navigation

The local components defined in a scripted utility or rollout are accessible to external code as properties of the utility or rollout object. Recall that the rollout object is assigned to a new global variable (or local variable if a nested rollout) named on the utility or rollout definition.

EXAMPLE:
    utility foo "Utility"
    (
      local var1, var2
      checkbox enable "Enable"
      rollout setup "Setup" -- local rollout
      (
        local var3
        button doit "Execute" enabled:false
        on doit pressed do
        (
          var3 = var1 + var2
        )
      ) --end rollout
      function frab a b = (var1 = b-a; var2 = a*b)
      on enable changed state do
      (
        frab 10 20
        if state then
        (
          addRollout setup
          setup.doit.enabled = true
        )
        else
          removeRollout setup
      ) --end on enable handler
    ) --end utility

The example defines the utility and places the utility object in a global variable named foo . You can access components in the utility from the Listener or other code as properties of that object, using the name of the variable or item as the property name. Any event-handler functions supplied for user-interface items can also be accessed as sub-properties of the item, using the event name as the property name.

EXAMPLE:
     -- Gets and prints foo's local variable, var1
    print foo.var1
     -- test foo's enabled checkbox state:
    if foo.enable.state then print "ON!" else print "OFF"
     -- Sets the foo's enabled checkbox state to false. -- This will change the checkbox, but not execute the event handler -- which deals with the adding/removing the local rollout
    foo.enable.state = false
     -- Calls the 'changed' handler function of the enable checkbox -- This will call the handler with a value of false, but will NOT -- change the checkbox's state itself.
    foo.enable.changed false
     -- This willbothcall the handler with a value of false -- AND change the checkbox's state, mimicking a checkbox change -- via the UI and the mouse:
    foo.enable.changed (foo.enable.state = false)
     -- Calls its 'frab' function local to the foo utility:
    foo.frab 100 200
     -- Sets foo’s setup rollout local variable, var3
    foo.setup.var3 = 42
     -- Calls the change handler function for doit button in the -- setup rollout of the foo utility:
    foo.setup.doit.pressed()

The local variables, functions, and structures in scripted utilities and rollouts are initialized as soon as the utility or rollout is first defined, rather than when the utility or rollout is first displayed. This allows other code to use local functions and access local values at any time after definition.

Note

Whenever a utility or rollout is opened, all local values will be reinitialized and any values set before opening will be lost!

FOR EXAMPLE:
     -- define a test rollout with a spinner UI element -- initialized to value of 50.0 and two local variables:
    rollout test "Test"
    (
      localtestValue1
      localtestValue2 = 10
      spinner testSpinner "Spinner" range:[0.0,100.0,50.0]
    )
    --> Rollout:test
    test.testSpinner.value --peek into the spinner's value
    --> 50.0 --it is 50 as expected
    test.testValue1 --get the first local variable's value
    --> undefined --it is set implicitly to undefined
    test.testValue2 --get the other local variable's value
    --> 10 --it is set to 10 as expected
    test.testSpinner.value = 60.0 --change the spinner's value to 60.0
    --> 60.0
    test.testSpinner.value --get the value back to see if it worked
    --> 60.0
    test.testValue1 = 20 --set the first local's value to 20
    --> 20
    test.testValue1 --get the first local's value
    --> 20 --now it is initialized to 20
    test.testValue2 = 40 --set the second local's value to 40
    --> 40
    test.testValue2 --get the second local's value
    --> 40 --now it is 40 --now create a dialog with the rollout -
    createDialog test 100 40
    --all variables will be reset!
    --> true
    test.testSpinner.value --get the spinner value again
    --> 50.0 --it is back to the default value of 50.0
    test.testValue1 --get the first local's value again
    --> undefined --it is back to undefined
    test.testValue2 --get the second local's value again
    --> 10 --it is back to 10