maersk Member 3


Joined: 17 Aug 2014 Posts: 891
|
Posted: 05/06/2015 18:20 Post subject: How can you display/hide a layer in a screen depending on a |
|
|
How can you display/hide a layer in a screen depending on a tag?
You can use the VBS script below, in which you only have to change the screen name, the layer, the tag and its value (for example, in a global VBS script or in a VBS action of an event of a button etc.).
This script functions only if the relevant screen is also open.
| Code: | Dim Tag
Dim scrObj
Set scrObj = HMIRuntime.Screens("@Screen.@win12:@1001.@Desk:screen_name")
Set Tag = HMIRuntime.Tags("Tag")
Tag.Read
If Tag.Value = 0 Then
scrObj.Layers(screen_layer).Visible = False
Else
scrObj.Layers(screen_layer).Visible = True
End If |
Note (taken from the WinCC Online Help)
Upon access, the layers are counted in VBS starting with 1. Thus layer "0" in the WinCC Graphics Designer must be addressed with layers(1).
For example, if you want to address screen layer 10 in a screen, you must enter 11 for
| Code: | | scrObj.Layers(...).Visible. |
If you have opened a screen on anther monitor, you must address it accordingly, "@Screen.@win22:@1001.@Desk:screen_name", for example.
What should I watch out for with actions when using a Multi VGA card?
One problem with actions is that when using a function (e.g. SetBackColor) only the picture name (lpszPictureName) and the object name (lpszObjectName) are specified. Thus, if you are using numeroase screens, there is no unambiguous assignment of the function and therefore the picture to a specific monitor screen.
| Code: | #include "apdefap.h"
void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
SetBackColor("system.pdl","storage_tank",CO_RED); // background color
}
|
Now, if you want the action to be executed on all the screens, you must enter the following C action:
| Code: | #include "apdefap.h"
void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
SetBackColor("@SCREEN.@WIN12:@1001.@DESK:system.pdl","storage_tank",CO_RED); // background color
SetBackColor("@SCREEN.@WIN22:@1001.@DESK: system.pdl","storage_tank",CO_RED); // background color
}
|
By entering the two lines (for 2 screens) you ensure that the function SetBackColor is executed on both screens. @WIN12 stands for Monitor1 and @WIN22 stands for Monitor2.
In this way the image "system.pdl" and thus the function is assigned to a specific monitor.
If you want to use more than two screens in WinCC Runtime and want to have the same pictures open on two screens, it might happen that C actions that you trigger, e.g. by mouse click, on one screen are executed on the other screen.
If, for example, you execute the C function SetVisible and transfer the picture name absolutely (e.g. "Picture1.PDL",...), the function will always refer to the picture that was opened first in the case of multiple screens. If you wish to address the current picture, then you must use the pointer on the current picture:
| Code: |
SetVisible(IpszPictureName,...);
|
If you wish to close a picture window yourself by pressing an Exit button in the picture, then you must program the following C action:
| Code: |
SetVisible(GetParentPicture(IpszPictureName), "picture_window_xyz", 0); |
You will find the GetParentPicture function under STANDARD functions\GRAPHICS\GetParentPicture in the GlobalScript. |
|