Script Window
The script window in Experior allows you to call the Experior API, within an instance of Experior.
It allows you to interact with Experior and e.g. stimulate the active model. An example usecase could be running a model without being connected to a physical PLC.
The shown model below has been set up through scripting, so that the first motor starts when a load activates the first sensor and a new load will be created when the load activates the second sensor.
The script window could contain following code:
using System;
using System.Numerics;
using System.Windows.Media;
using System.Linq;
using Experior;
using Experior.Core;
using Experior.Interfaces;
using Experior.Core.Loads;
using Experior.Core.Routes;
using Experior.Core.Communication.PLC;
public partial class Main
{
public void On(object trigger, string symbol)
{
if (symbol == "SENSOR1")
{
Experior.Core.Motors.Motor.Get("MOTOR1").Start();
}
if (symbol == "SENSOR2")
{
Experior.Core.Assemblies.Assembly.Get("FEEDER1").Activate();
}
}
public void Off(object trigger, string symbol)
{
}
}
For pre-defined script helper methods, you can right-click within the script window to insert the following methods:
- Initialize
- On (default inserted)
- Off (default inserted)
- Motor Started
- Motor Stopped
- Input Changed
- Output Changed
- Message Received
- Telegram Received
- Step
- Activation
- Arrived
- Enter (Action Point/Sensor)
- Leave (Action Point/Sensor)
- Elapsed
- Reset
- Pause
- Continue
- Dispose
Dispose:
When you press the “Compile” button in the top left of the script window the Dispose() method is called. You can use this method to unsubscribe from events and perform other clean-up actions.
Note: Since the Dispose() method is called before the compilation happens, it will not be the current version of the Dispose method as that one has not been compiled yet. It will be the Dispose method from the last time you compiled.
To make sure the Dispose method that is called matches the most recent implementation, it is best to compile every time you make changes to your Dispose method.
Initialize:
The Initialize method, runs as soon as compiling the script finishes.
On:
This method is called when:
- Receiving input through a connection and the incoming data is of the type bool and its value is “True”.
- When a button is pressed in the “Control Panel” window.
- When a sensor is activated by a load.
Off:
Same as On, but the value is “False”.
Motor Started:
Is called when a motor is started.
Motor Stopped:
Is called when a motor is stopped.
Input Changed:
This is called when the input changes.
Output Changed:
This is called when the output changes.
Message Received:
Called when a message is received.
Telegram Received:
Called when a telegram is received.
Step:
Called at every frame update.
Activation:
Called when an SRM is created.
Arrived:
Called when a load arrives at a node.
Enter:
Called when a load enters a sensor or actionpoint.
Leave:
Called when a load leaves a sensor or actionpoint.
Elapsed:
Called when a timer elapses.
Reset:
Called when the scene is being reset.
Pause:
Called when the scene or model gets paused.
Continue:
Called when the scene or model gets unpaused.