How To ... Call a MAXScript Function Periodically using DotNet

How To > Use DotNet > Call a MAXScript Function Periodically

The following tutorials demonstrates the use of the System.Windows.Forms.Timer dotNetObject as alternative to the MAXScript Timer UI Control. Other than the latter, the DotNet object version does not require a MAXScript User Interface to be created and open in order to run a MAXScript function at given time intervals.

Related topics:

DotNet In MAXScript

dotNetObject

dotNetObject:System.Windows.Forms.Timer

NATURAL LANGUAGE

Create a DotNet Timer Object.

Define a MAXScript function to be called periodically by the timer.

Register an Event Handler to call the function

Start the Timer.

EXAMPLE

theTimer = dotNetObject "System.Windows.Forms.Timer"
fn printTime = (print localTime)
dotnet.addEventHandler theTimer "tick" printTime
theTimer.interval = 1000
theTimer.start()
--theTimer.stop()

SAMPLE LISTENER OUTPUT:

dotNetObject:System.Windows.Forms.Timer 
printTime() 
OK 
1000 
undefined 
"10/20/2007 1:11:28 PM" 
"10/20/2007 1:11:29 PM" 
"10/20/2007 1:11:30 PM" 
"10/20/2007 1:11:31 PM"
theTimer = dotNetObject "System.Windows.Forms.Timer"

Create a Timer

fn printTime = (print localTime)

Define a MAXScript function to be called by the Timer.

dotnet.addEventHandler theTimer "tick" printTime

Add ON TICK event handler to call the function

theTimer.interval = 1000

Set the tick interval to 1 second (1000 milliseconds)

theTimer.start()

Start the Timer

--theTimer.stop()

Remove the remark and call this method to stop the Timer!