Complex visibility with scripts

<< Click to Display Table of Contents >>

Navigation:  Examples > Object visibility >

Complex visibility with scripts

Previous pageReturn to chapter overviewNext page

If you have to change visibility depending on several tags you need to use scripts. For example you have 2 tags for every Pump object - State and Speed:

complexwithscriptstags

Depending on tag's values every Pump object make visible or not:

State

Speed

Visibility

0

Any

Not visible

1

0...500

Visible

1

500...1000

Visible

1

>1000

Not visible

Let's create Motor graphical object for our example:

motorexample

We need intermediate tags to enable or disable object's flashing - Visible1, Visible2 and Visible3:

visibletags

 

Let's open Object properties window by double clicking on it:

motorpropertieswindow

And let's create user-defined property - Number and make it's equal 1:

complexudp

 

Close Collection window and click OK to Object properties window. Now reopen Object properties of the Motor and setup its Visibility property. First we need to setup tag and bind it to Visible tag dependent on the User-defined property - Number. To do this click "..." and setup Tag name - Visible{Number}:

visibletagchoose

Visibility property looks like this:

visibleproperty

Now we have to create Object type ST script with Execution type - OnDataChange:

stscriptforcomplexscript

Now open Object properties for our Motor object and click Script's collection and add our script:

stcollection

Now close Collection window and Object properties by clicking OK to confirm our changes. And now we can write our script:

visiblescript

Now we have Motor with setup fill property by script. To copy this Motor and bind fill color property to tags - State2, Speed2 and State3, State3 you no need to setup script for every Motor you only have to duplicate Motor:

 

complexduplicate

And change Number property of the new Motor in the Property sheet:

complexpropertysheet

Click OK to confirm your changes and Run simulation to check your settings:

visiblescript