Eplan Platform API
EPLAN API / User Guide / API Framework / Scripts / Event handling in scripts
In This Topic
Event handling in scripts
In This Topic

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;
    }
}

 

 

See Also

API Framework

Events