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.
Set scrObj = HMIRuntime.Screens("@Screen.@win12:@1001.@Desk:screen_name")
Set Tag = HMIRuntime.Tags("Tag")
If Tag.Value = 0 Then
scrObj.Layers(screen_layer).Visible = False
scrObj.Layers(screen_layer).Visible = True
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 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. More information about the addressing of different monitors is available in Entry ID: 831486.