You can register one or more functions to be called whenever the 3ds Max viewports are redrawn. The following methods let you register and unregister these callbacks:
You can register as many functions as you like. Each one is individually called whenever the viewports are redrawn. The functions you register must take no arguments.
fn redrawviews_p = print "Viewports Redrawn"
In the above example, the registered function causes the string "Viewports Redrawn" to be printed in the Listener window whenever the 3ds Max viewports are redrawn.
If a runtime error occurs in a callback function while it is being executed, an error message is displayed and that callback function is permanently disabled.
The registered function is executed in a special context and not in the context of the code that created it. This means that the function cannot contain references to local variables in outer code nestings surrounding the function definition since those variables are on an execution stack that does not exist at the time the function is called. An important exception to this is utility and rollout panel locals, such as local functions, rollout variables and nested rollouts. You can refer to them in change handler code inside rollout code as they are associated directly with their rollout or utility object.
Note that it is the function value that is being registered, not the function name or global variable. This means that redefining the same-named function after registering it does not change the callback. You either need to unregister, re-define the function and then register it again, or make the registered function an intermediary which calls another function,
fn redrawviews_cb = print currentTime
fn rvcb = redrawviews_cb()
In this case, the registered callback function, rvcb, calls the real call back, redrawviews_cb, (by referencing the global variable it is defined in), meaning you can redefine redrawviews_cb() as often as you need and the callback will always invoke the latest definition. This is a useful technique to employ while you are developing and debugging a callback.
Callback functions remain registered after loading a new file or performing a 3ds Max reset.
Change Handlers and Callbacks
Change Handlers and When Constructs
Time Change Callback Mechanism
General Event Callback Mechanism