Simple multiple color change with scripts

<< Click to Display Table of Contents >>

Navigation:  Examples > Change the color of an object >

Simple multiple color change with scripts

Previous pageReturn to chapter overviewNext page

If you need to change the color depending on several tags, you need to use scripts. For example, you have a Motor object that has 2 parameters - State and Speed, and you want to use fill color depending on the State and Speed values:

 

State

Speed

Fill color

0

Any

RED

1

0...500

GREEN

1

500...1000

YELLOW

1

>1000

BLUE

 

1. Create tags: Speed (set the data type - Short(16bit), initial PV - 0) and State (set the data type - Byte(8bit), initial PV - 0):

 

commonmultiplewithscripts

 

2. Let’s create a graphical object - Motor for our example:

 

motorexample

 

3. Create a script with the name stMotorFill, type - Object and execution type - OnDataChange:

 

stscriptforcomplexscript

 

4. Let's write the script::

 

commonmulcolorwithscript

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 our Motor object, go to the object’s properties (General tab) and add our script to the “Scripts” field:

 

motorpropertieswindow

stcollection

 

 

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

 

commonwithscript

You can download this project here.