TimerEvent

Object Hierarchy | Related C++ Class: TimerEvent

Inheritance

SIObject

EventInfo

TimerEvent

Introduced

v5.1

Description

A TimerEvent represents a system timer and allows you to specify the interval and the delay time at which a timer elapses. Timers in Softimage are independent of the timeline clock and can be used to produce recurrent work accurately. For example, you can implement an autosave mechanism with a TimerEvent.

The TimerEvent object derives from EventInfo and can be managed like a regular Softimage event. Use PluginRegistrar.RegisterTimerEvent to register them and XSIApplication.EventInfos to access them. Timer events can be suspended with muting and resumed by un-muting (see EventInfo.Mute). You can reset a timer with TimerEvent.Reset.

Note: Timer events are based on Windows timers and are processed by Softimage with a low priority. Although they can be set with milliseconds accuracy, timer events can sometimes be delayed due to the current activity of Softimage.

Methods

IsClassOf operator IsEqualTo operator Reset  
       

Properties

Application Attributes Categories CustomData
Delay FileName FullName operator Handler
Help Interval Language Mute
Name operator NestedObjects Origin OriginPath
Parent Type operator    
       

Examples

JScript Example

/*
	This example demonstrates how to register a timer event and to change its
values.
	To try out this example save it into the Plugins directory 
	(User, Factory or Workgroup). Once you have restarted Softimage, the current 
	scene will be saved automatically every 15 secs.
	( You can also load the plug-in without restarting Softimage - see
	XSIApplication.LoadPlugin )
*/
function XSILoadPlugin( in_reg )
{
	in_reg.Author = "Softimage SDK Team" ;
	in_reg.Name = "SDK Example - Save scene timer" ;
	in_reg.Major = 1 ;
	in_reg.Minor = 0 ;
	// Register the save scene timer. The timer elapses every 15 secs. (0==no delay)
	in_reg.RegisterTimerEvent( "AutoSaveSceneTimer", 15000, 0 );
	in_reg.RegisterProperty( "AutoSaveProp" );
	in_reg.RegisterMenu( siMenuMainTopLevelID, "Auto Save Demo", true, false );
	return true ;
}
function AutoSaveSceneTimer_OnEvent( ctxt )
{		
	// Save current scene
	Application.SaveScene( );
	// Log time
	var strFileName = ActiveProject.ActiveScene.Parameters("Filename").Value;
	var today = new Date();
	var strTime = today.toDateString();
	strTime += ", " + today.toTimeString();
	Application.LogMessage( "<"+strFileName+">" + " saved on " + strTime );
	// Do not mute the timer
	return false;
}
function GetAutoSaveProp( )
{
	var strName = "AutoSaveProp";
	var root = ActiveSceneRoot;
	var prop = root.Properties.Item( strName ) ;
	if ( prop == null )
	{
		return root.AddProperty( strName );
	}
	else
	{
		return prop ;
	}
}
function AutoSaveDemo_Init( in_ctxt )
{
	var menu = in_ctxt.source;
	menu.AddCallbackItem( "Launch Auto Save Demo", "ShowAutoSaveProp" );
	return true;
}
function ShowAutoSaveProp( )
{
	InspectObj( GetAutoSaveProp( ), "", "", siLock );
}
function AutoSaveProp_Define( ctxt )
{
	var pset;
	pset = ctxt.Source;
	pset.AddParameter2("Auto_Save_Interval",siInt4,15,0,50,null,null,0,siPersistable);
	pset.AddParameter2("Auto_Save_Delay",siInt4,0,0,50,null,null,0,siPersistable);
	pset.AddParameter2("Auto_Save_Scene",siBool,true,null,null,null,null,0,siPersistable);
	return true;
}
function AutoSaveProp_DefineLayout( ctxt )
{
	var layout,oItem;
	layout = ctxt.Source;
	layout.Clear();
	layout.AddGroup();
	layout.AddItem("Auto_Save_Interval", "Interval (secs)" );
	layout.AddItem("Auto_Save_Delay", "Delay (secs)" );
	layout.EndGroup();
	layout.AddGroup();
	layout.AddRow( );
	layout.AddButton( "Auto_Save_Reset","Reset Timer" ) ;
	layout.AddGroup();
	layout.EndGroup();
	layout.AddItem( "Auto_Save_Scene", "Enable" );
	layout.EndRow( );	
	layout.EndGroup();
	return true;
}
function AutoSaveProp_OnInit( ctxt )
{
	var evTimer = Application.EventInfos( "AutoSaveSceneTimer" );
	var p = PPG.Auto_Save_Interval;
	p.Value = evTimer.Interval / 1000;
	p = PPG.Auto_Save_Delay;
	p.Value = evTimer.Delay / 1000;
}
//--------------------------------------------------------------------------
// Reset Timer button callback to restart the Auto Save timer with new values
//--------------------------------------------------------------------------
function AutoSaveProp_Auto_Save_Reset_OnClicked()
{
	var p = PPG.Auto_Save_Interval;
	var interval = p.Value * 1000;
	p = PPG.Auto_Save_Delay;
	var delay = p.Value * 1000;
	var evTimer = Application.EventInfos( "AutoSaveSceneTimer" );
	evTimer.Reset( interval, delay );
	// update the UI
	PPG.Auto_Save_Scene.Value = true;	
} 
//--------------------------------------------------------------------------
// Start/Stop the AutoSaveSceneTimer timer.
//--------------------------------------------------------------------------
function AutoSaveProp_Auto_Save_Scene_OnChanged( )
{
	var paramVal = PPG.Auto_Save_Scene.Value;
	var evTimer = Application.EventInfos( "AutoSaveSceneTimer" );
	evTimer.Mute = paramVal==false;
}