Complex text change with scripts

<< Click to Display Table of Contents >>

Navigation:  Examples > Change the text of an object >

Complex text change with scripts

Previous pageReturn to chapter overviewNext page

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:

 

clip0040

 

 

2. Create a Text/EditField object:

 

textexcomplex

 

3. Create a user-defined property - "Number" and set its value to "1", because we will bind to the State1 and Speed1 tags:

 

clip0041

complexudp

 

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:

 

stscriptforcomplexscript

 

And let's write a script::

 

clip0002

 

After you have recorded the script, be sure to launch it by clicking the button on the toolbar: runsimulation

 

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”:

 

clip0042

stcollection

 

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:

 

textduplicate

 

 

clip0043

 

7. Let's Run simulation to check the settings:

 

textcomplexex

 

You can download this project here.