Complex color change

<< Click to Display Table of Contents >>

Navigation:  Examples > Change the color of an object >

Complex color change

Previous pageReturn to chapter overviewNext page

Consider the following example: you have large number of objects of the same type (motor), which have several operating modes (State), and you need to display the motor on the screen with color depending on the set operating mode.

Because we have many objects of the same type, we will use indirect names to bind tags based on user-defined properties.

 

1 . First, let's create tags (by the number of objects).

 

tagsforcomplexexample

 

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

 

clip0026

 

3. In the Object properties, set up the user-defined property "Number: and set its value “1”, because We will bind Motor1 to State1:

 

clip0027

complexudp

 

Click "OK" to save this user-defined property.

 

4. Next, bind the object to State1. Open the Object properties window again and select the “Fill Color” tab. Then in the “Tag” field (click on the “..." button) and in the window that opens in the “Tag Name” field we set State{Number} , where "Number" is our user-defind property (the value of which we set to “1” for the first object ):

 

clip0028

choosetagcomplex

 

5. Let's make sure that our object is bound to State1 (save the Object Properties by clicking "OK") and open the "Object Properties" window again.

 

6. So, the "Fill Color" property is bound to the State1 tag. Now let's set the Color of the object depending on the value of this tag:

 

State1

Color

0

RED

1

GREEN

2

YELLOW

 

Select the Type "TagPV in range" and set the colors for the tag values:

 

complexfilltab2

rangecomplesflash

 

Now we have a Motor -object with the Fill Color property set.

 

7. Now we need to create the same objects with the same settings. Because We used indirect names based on user-defined properties to bind tags, we do not need to set the Fill Color property for each new object (there is no need to set ranges for each object). We just need to duplicate the Motor (“Duplicate”) and bind it to the tag by specifying the value of the Number user-defined property that corresponds to the tag. The fastest way to do this is in the Property Sheet

 

Confirm the changes and close the object properties window by clicking OK. .o copy this motor and bind the fill color property to the tags - State2 and State3 you don't need to configure the fill color property for each Motor, you only need to duplicate the Motor:

 

 

complexduplicate

 

And change in the Property Sheet: the value of the user-defined property "Number" depending on which tag you want to bind the object to:

 

complexpropertysheet

 

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

 

complexrunsim

 

You can download this project here.