Event handling in scripts
You can write a script to react on EPLAN events. Therefore you need to declare at least one function of the script as event handler using the [DeclareEventHandler()] attribute and load the script.
It is even possible to handle event parameters. However you need to know the event parameters in advance.
The following two example show scripts, which --when loaded -- react on events.
The script in the first example reacts the "onMainStart" event. The function MyEventHandlerFunction in the class SimpleEventHandler is registered as event handler for the "onMainStart" event. When this event is raised in EPLAN, the function is called.
The second example shows an event handler script, which catches any "onActionStart.String" event. There is one event parameter for the action's name.
public class SimpleEventHandler
{
[DeclareEventHandler("onMainStart")]
public void MyEventHandlerFunction()
{
new Decider().Decide(EnumDecisionType.eOkDecision, "MyEventHandlerFunction was called!","SimpleEventHandler", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK);
return;
}
}
public class SimpleEventHandler
{
[DeclareEventHandler("onActionStart.String.*")]
public long MyEventHandlerFunction2(IEventParameter iEventParameter)
{
try
{
EventParameterString oEventParameterString= new EventParameterString(iEventParameter);
String strActionName= oEventParameterString.String;
new Decider().Decide(EnumDecisionType.eOkDecision, "Action " + strActionName + " was started!","MyEventHandler", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK);
}
catch (System.InvalidCastException exc)
{
String strExc= exc.Message;
new Decider().Decide(EnumDecisionType.eOkDecision, "Parameter error: " + strExc, "MyEventHandler", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK);
}
return 0;
}
}
Public Class SimpleEventHandler
<DeclareEventHandler("onMainStart")> _
Public Sub MyEventHandlerFunction()
Dim dec As Decider = New Decider
dec.Decide(EnumDecisionType.eOkDecision, "MyEventHandlerFunction was called!", "SimpleEventHandler", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK)
End Sub 'MyEventHandlerFunction
End Class 'SimpleEventHandler
Public Class SimpleEventHandler
<DeclareEventHandler("onActionStart.String.*")> _
Public Function MyEventHandlerFunction2(iEventParameter As IEventParameter) As Long
Dim dec As Decider = New Decider
Try
Dim oEventParameterString As New EventParameterString(iEventParameter)
Dim strActionName As [String] = oEventParameterString.String
dec.Decide(EnumDecisionType.eOkDecision, "Action " + strActionName + " was started!", "MyEventHandler", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK)
Catch exc As System.InvalidCastException
Dim strExc As [String] = exc.Message
dec.Decide(EnumDecisionType.eOkDecision, "Parameter error: " + strExc, "MyEventHandler", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK)
End Try
Return 0
End Function 'MyEventHandlerFunction2
End Class 'SimpleEventHandler