Complex visibility with scripts

<< Click to Display Table of Contents >>

Navigation:  Examples > Object visibility >

Complex visibility with scripts

Previous pageReturn to chapter overviewNext page

Let's assume that in our project we have many Motor objects of the same type, each of which has several State and Speed parameters, and depending on their values, we want the objects to be visible/not visible on the screen. Since in this case there is a dependence of Visibility on several tags, it is necessary to use scripts. And since we have several objects of the same type in our project, it is more convenient to use indirect names to bind tags to an object.

 

1. Let's create tags for each object - State and Speed (use grouping):

 

complexwithscriptstags

 

2. In this case, we need intermediate tags to enable or disable the visibility of an object - Visible1, Visible2 and Visible3, let's create them:

 

clip0035

3. Create a Motor object:

motorexample

 

Let's create a user-defined property - Number and set its value to "1", because We will bind the first object to the Visibility1 tag:

 

clip0027

complexudp

 

4. Close the "Collections" window and click "OK" in the Object Properties Window to save the changes. Now let's open the Object Properties again and set up the Visibility property: enable the property, set the value = 1, type "Tag.PV==value", bind the tag by specifying an indirect name: Visible{Number}:

 

visibleproperty

visibletagchoose

 

5. We will set visibility depending on the tag values for each Motor object:

 

State

Speed

Visibility

0

Any

Not visible

1

0...500

Visible

1

500...1000

Visible

1

>1000

Not visible

 

6. Now let’s create a script with type "object" in the ST language with the execution type - OnDataChange:

 

stscriptforcomplexscript

Let's write a script:

 

visiblescript

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

 

7. Now let’s bind the script to the object - open the properties of the object, select the “General” tab and fill in the “Collection” in the “Scripts” field:

 

motorpropertieswindow

stcollection

 

So, we have a Motor with the visibility property set by script.

 

8. Now we need to duplicate the created Motor object as many times as needed in the project, and in each newly created object correct the value of the "Number" user-defined property in the Property Sheet:

 

 

complexduplicate

 

 

complexpropertysheet

 

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

 

visiblescript

 

You can download this project here.