Init (Operator)


Description

For custom operators, this callback is fired when an instance of the operator is instantiated. Unlike Define, Init is called both for newly created operators and for operators loaded from a file.

User data can be stored in the operator context of the Init callback and then retrieved later in the Update and Term callbacks. Data can be stored as simple numerical or strings values as well as COM or C++ objects.

Note While you can also initialize cached operator data the first time update is called, it is strongly suggested to perform data initialization in Init.


Applies To

Custom Operators


Syntax

public class <operator_name>

{

	public bool Init( Context in_context )

	{

		...

	}

}
CStatus <operator_name>_Init( CRef& in_context )

{ 

	... 

}
function <operator_name>_Init( in_context )

{ 

	... 

}
def <operator_name>_Init( in_context ):

	...
Function <filter_name>_Init( in_context )

	...

End Function
sub <operator_name>_Init 

{ 

	my $in_context = shift; 

}

<operator_name> is the name specified in the call to PluginRegistrar.RegisterOperator, with any spaces converted to underscores.


Parameters

Parameter Language Type Description
in_context Scripting and C# Context Context.Source returns the CustomOperator.
C++ CRef& A reference to the Context object. Context::GetSource returns the CustomOperator.


Examples

// Basic example

SICALLBACK CppOp_Init( CRef& in_ctxt )

{

 Context ctxt( in_ctxt );



 CustomOperator op( ctxt.GetSource() );

 CString strOpNameAsUserData = op.GetUniqueName();



 ctxt.PutUserData( strOpNameAsUserData ) ;



 return CStatus::OK ;

}
// Object Data

class CData

{

 LONG data;

};



SICALLBACK CppOp_Init( CRef& in_ctxt )

{

 Context ctxt( in_ctxt );



 CData* p = new CData;

 p->data = 123;

 CValue val = (CValue::siPtrType) p;



 ctxt.PutUserData( val ) ;



 return CStatus::OK ;

}



// Time to release memory

SICALLBACK CppOp_Term( CRef& in_ctxt )

{

 Context ctxt( in_ctxt );



 CValue val = in_ctxt.GetUserData();  

 CData* p = (CData*)(CValue::siPtrType)val;

 delete p;



 return CStatus::OK ;

}


See Also