Complex flashing with scripts

<< Click to Display Table of Contents >>

Navigation:  Examples > Object flashing >

Complex flashing 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 (Motor) to flash/not flash on the screen. Since in this case there is a dependence of flashing 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. First, let’s create tags for each object - State and Speed (we’ll arrange them as a group):

 

complexwithscriptstags

 

2. In this case, we need intermediate tags to enable or disable the flashing of an object. - Flash1, Flash2 and Flash3, let's create them:

 

clip0032

 

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

 

motorexample

 

In the Object properties in the "General" tab, create a user-defined property "Number" and set its value "1", because we will bind this object to the Flash1 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 configure the Flash property: bind the tag by specifying the indirect name: Flash{Number}:

 

clip0033

flashchoosetag

 

5. Depending on the tag values for each Motor object, we will use the frequency:

 

State

Speed

Flash frequency

0

Any

Not flashing

1

0...500

1000

1

500...1000

500

1

>1000

250

 

6. Let's create a script for an object in the ST language with the execution type - OnDataChange:

 

stscriptforcomplexscript

 

Let's write a script:

 

flashscript

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 “Main” tab and fill in the “Collection” in the “Scripts” field:

 

motorpropertieswindow

stcollection

 

So, we have a Motor with the Flash property set according to the 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 user-defined property "Number" ((most quickly, on the Property Sheet):

complexduplicate

 

complexpropertysheet

 

 

 

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

 

commonmulflashscript

 

You can download this project here.