How do you use scripts to dynamize objects in WinCC Comfort and WinCC Advanced?
Accessing object properties via a script serves as an alternative to configuring object properties from the Properties dialog box.
Some objects cannot be changed in SIMATIC WinCC (TIA Portal) using the available options, resizing rectangles in runtime, for example. These attributes or properties can be changed or dynamized with the aid of scripts.
At the end of the entry is a PDF document and the described sample project ready for downloading.
The PDF document contains a list of objects included by default in WinCC Comfort and WinCC Advanced. In addition, there is a list of all the properties (attributes) of the objects and the type of access to the properties which can be called using a script statement.
All the properties and methods of an object which can be dynamized are available in the manual under "Visualize processes > Working with system functions and Runtime scripting > Reference > VB Scripting > VBS Object Model" in the sections entitled "Properties" und "Methods".
In the example below we show how you can change the width and height of a rectangle using a script in Runtime.
The names used for the tags and the objects can be changed separately as required.
The tags do not need a controller connection (only if you want to assign the width and height of the rectangle via the controller).
For better understanding it is useful to open the attached configuration.
|1||Add a rectangle |
The width and height of the rectangle are to be changed using a script. For this you create two internal tags named "RectangleHeight" and "RectangleWidth".
(Project navigation > Operator panel > HMI tags > Default tag table).
The tags are assigned a start value. In this case, "100" for the width and "50" for the height (Properties > Values > Start value). The reason for this measure is described further on (see Step 8).
Two scripts are used in the configuration.
(Project navigation > Operator panel > VB Scripts > Add new VB functions").
You can specify the names of the scripts as required.
In this example:
Below we describe the two scripts used in more detail.
Using the "Script_01_Rectangle" script you can change the size of the rectangle.
Create an internal script tag
Define the object
Assign to the object (rectangle) the attributes and tags for "Height" and "Width" .
In this example:
Using the "Script_02_Init_Rectangle" script you can change the size of the rectangle to a size defined in the script (reset to "initial size").
It is only for resetting the rectangle to the "original size", for example, without having to enter a value beforehand using the IO fields.
The script has exactly the same structure as the "Script_01_Rectangle" script. The only difference is that fixed values are given for the width ("200") and height ("100") of the rectangle.
|6||Tips for creating the script |
|7||Add buttons and IO fields|
To specify the width and height of the rectangle you need two IO fields. Two buttons are used to run the scripts.
The internal tags for "width" and "height" are configured respectively at the IO fields
The "Change size" button calls the "Script_01_Rectangle" script
The "Standard size" button calls the "Script_02_Init_Rectangle" script
|8||This example is executed using the "Screen_01" screen. |
If the size of the rectangle is changed, then this is only present temporarily. If the page is called again, the rectangle resumes the size of the configuration.
If you wish to retain the changed size after a page change, call the "Script_01_Rectangle" script when the "Screen_01" screen is loaded (Properties > Events > Loaded).
The first time the page is called or if no values have been defined yet for the size of the rectangle, then the rectangle is not visible on the page (width and height have the value "Zero").
|9||Notes and tips on configuring |
Further Information (not relevant for this example)
The Help system of WinCC (TIA Portal) provides all the objects in relation to VBS. The entry entitled "Relationship between Object and Object Type" (Entry ID: 108893939) gives you a list of the objects and their associated object types. In the manual or information system (TIA Portal Help), via the object types you can call - language independent - an overview of the searched objects.
In the information system, for example, or in the manual (Entry ID: 109091876) you enter "Rectangle" as the keyword to be found under Index. You get an overview of the object displayed. The description includes the properties and methods of the object.
Bear in mind that not all objects are available in all operator panels.
Attachment 1 contains a list of objects included by default in WinCC Comfort
and WinCC Advanced. In addition, there is a list of the properties (attributes) of the objects and the type of access to the properties which can be called via the script statement of "HmiRuntime.Screens" and "ScreenItems".
53752382_object_attributes_en.pdf (73,5 KB)
The packed file contains the described sample project in the version SIMATIC WinCC (TIA Portal) V13 SP1.
TIA_Project_V13_SP1 (2.6 MB)