<< Click to Display Table of Contents >> Complex text change with scripts |
|
If you need to change text depending on multiple tags, you need to use scripts. Assume we have several objects of the same type (Pump), each of which has two parameters (tags) - State and Speed, and we want to display text about the operation of the pump depending on tags' values.
1. Create tags for each object - State and Speed:
2. Create a Text/EditField object:
3. Create a user-defined property - "Number" and set its value to "1", because we will bind to the State1 and Speed1 tags:
4. Let the Text/EditField object display texts depending on the tag values::
State |
Speed |
Text |
---|---|---|
0 |
Any |
Pump off |
1 |
0...500 |
Pump speed within normal limits: PV |
1 |
500...1000 |
Pump speed is high: PV |
1 |
>1000 |
Attention! Pump speed too high! |
Next, we will create a script with type "object" in the ST language with the execution type - OnDataChange:
And let's write a script::
After you have recorded the script, be sure to launch it by clicking the button on the toolbar:
5. Now let’s bind the script to the object - open the Object Properties, the “General” tab, the “Scripts” field and fill in the “Collections”:
6. So, we have a Text object with the Text Input property set by script . To copy this object and bind the Text Output property to the tags - State2, Speed2, State3, Speed3, State4, Speed4, we don't need to set up a script for each Text object, we only need to duplicate the object and change the user-defined Number property of the new object on the Property Sheet:
7. Let's Run simulation to check the settings:
You can download this project here.