IMDTouchKnowledge BaseShop main store

How-to

WinCC Professional VBScript to show and hide screen layers

HMI and touchscreens Published 8 min read By IMDTouch engineering team

Short answer

In WinCC RT Professional, toggle any of a screen's 32 layers from a button Click VBScript with Layers.Item(n).Visible = Not Layers.Item(n).Visible, where n equals the configured layer number plus 1. Keep the toggle button on a separate visible layer so clicking it does not hide the control itself. For WinCC Advanced and Comfort Panels, layers are design-time only, so bind a shared Boolean tag to each object's Visibility animation instead.

A desktop engineering workstation running an operator screen: monitor, keyboard, mouse and tower PC
On this page
  1. Which WinCC products support runtime screen layer VBScript?
  2. How does WinCC Professional map screen layer numbers to VBScript indexes?
  3. How do you configure a button Click VBScript to toggle a layer?
  4. What does a worked layer toggle script look like for Layer 3?
  5. How do you toggle a layer inside a WinCC ScreenWindow or named screen?
  6. Which objects ignore screen layer visibility and how should you group details?
  7. How do you verify a WinCC Professional layer toggle before deploying to a machine?
  8. Questions asked

In WinCC RT Professional, you show or hide an entire group of screen objects from a button Click event by inverting that layer's Boolean Visible property in VBScript: Layers.Item(n).Visible = Not Layers.Item(n).Visible, where n equals the configured layer number plus 1. Because the VBS Layers collection uses 1-based indexing while the editor numbers 32 screen layers from 0, omitting that offset toggles the wrong group without raising an error. Keep the toggle button on a separate visible layer, and use Visibility animations instead on WinCC Advanced or Comfort Panels.

Which WinCC products support runtime screen layer VBScript? #

Only WinCC RT Professional exposes the screen Layers collection to runtime VBScript (demonstrated on V13 SP1 in Siemens WinCC Professional documentation), whereas WinCC Advanced and Comfort Panels restrict layers to engineering time only. Check the configured HMI runtime device in your TIA Portal project tree first, because WinCC Professional, WinCC Advanced (including Runtime Advanced V14), Comfort Panels, and SIMATIC WinCC Unified use distinct runtime object models.

HMI runtime target Runtime layer scripting API Documented group-visibility method
WinCC RT Professional VBScript Layers collection (1-based index) Toggle Layers.Item(n).Visible on a button Click event
WinCC Advanced / Comfort Panels None (layers are engineering-time only) Bind a Bool or Int Process tag to each object's Visibility animation
SIMATIC WinCC Unified JavaScript Screen.Layers (named lookup) Write Screen.Layers("Layer_0").Visible = false; or true;

Your decision follows that target device. On WinCC RT Professional, use the VBScript Layers collection below so one click switches an entire layer without tagging every symbol. On WinCC Advanced or Comfort Panels, select the target objects, open Properties > Animations > Add new animation > Visibility in the Inspector window, bind a Bool or Int Process tag (for example, visible when the tag equals 1), and flip that tag via a button event or system function, following the guide on hiding WinCC Advanced layers at runtime in TIA Portal. For per-object switching instead of layer-wide toggling, configure WinCC visibility animations for showing and hiding objects at runtime.

How does WinCC Professional map screen layer numbers to VBScript indexes? #

Every WinCC screen contains 32 consecutive layers numbered 0 at the background through 31 at the foreground, and you add 1 to the configured layer number to obtain the 1-based VBScript collection index from 1 to 32. In the editor, each object's layer appears under Properties > Miscellaneous > Layer and inside Layout > Layers. The Siemens WinCC VBS Object Model exposes Layers as a 1-based list on the screen, accessed via Layers.Item(n) or shorthand Layers(n) with each layer's Boolean Visible property.

Configured layer (Properties > Miscellaneous > Layer) Index arithmetic VBScript expression
0 (background) 0 + 1 = 1 Layers.Item(1).Visible
1 1 + 1 = 2 Layers.Item(2).Visible
3 3 + 1 = 4 Layers.Item(4).Visible
31 (foreground) 31 + 1 = 32 Layers.Item(32).Visible

An off-by-one error compiles cleanly whenever the argument stays inside the valid collection range, silently toggling the adjacent layer instead of your target objects. Always check Properties > Miscellaneous > Layer rather than screen proximity: neighboring symbols can sit on separate layers, while objects across the screen toggle together when assigned the same layer.

How do you configure a button Click VBScript to toggle a layer? #

Assign every detail object to the same target layer, place the toggle button on a separate permanently visible layer, and attach a Boolean negation statement to the button's Click event using that layer's incremented collection index. Negating the current Visible state with Not handles both hide and show transitions without an extra direction tag:

  1. Confirm that the project targets WinCC RT Professional and open the screen in the editor.
  2. Select every object in the detail group and set Properties > Miscellaneous > Layer to one shared target layer number.
  3. Place the toggle button on a different layer that stays visible and is not hidden by any other screen script.
  4. Open the button's Properties > Events > Click and add a VBScript function.
  5. Inside Sub OnClick(ByVal item), invert Layers.Item(n).Visible with the same 1-based index on both sides of the assignment.
  6. Compile the HMI project and resolve any script errors before launching runtime.

For objects on the background layer (configured Layer 0, collection index 1) with the button on another visible layer, the minimal documented handler is:

Sub OnClick(ByVal item)
    ' Documented WinCC VBS API: Layers.Item(index).Visible
    Layers.Item(1).Visible = Not Layers.Item(1).Visible
End Sub

Putting the toggle button on the hidden layer removes the button on the first click, preventing the operator from restoring the group. Layer visibility is strictly a display function for decluttering screens, never an operator authorization control or a machine safety interlock.

What does a worked layer toggle script look like for Layer 3? #

To toggle diagnostic indicators placed on configured Layer 3 while keeping the toggle button accessible on Layer 0, add the 1-based offset to get collection index 4 and invert Layers.Item(4).Visible inside the button's Click event. Compute both indexes before coding:

  • Detail objects: configured Layer 3 + 1 = collection index 4 (Layers.Item(4).Visible).
  • Toggle button: configured Layer 0 + 1 = collection index 1 (Layers.Item(1).Visible, kept True).

Because index 4 differs from index 1, toggling the detail layer leaves the button visible. The worked example below separates illustrative local variables (configuredLayer, collectionIndex, and nextVisibleState, declared as VBScript Variant variables with explicit initial values) from documented WinCC VBS API members (OnClick, Layers.Item, and Visible):

Sub OnClick(ByVal item)
    ' Illustrative local variables (VBScript Variant types, explicitly initialized)
    Dim configuredLayer
    Dim collectionIndex
    Dim nextVisibleState

    configuredLayer = 3
    collectionIndex = configuredLayer + 1 ' Arithmetic: 3 + 1 = 4

    ' Documented WinCC VBS API: Layers.Item(index).Visible
    nextVisibleState = Not Layers.Item(collectionIndex).Visible
    Layers.Item(collectionIndex).Visible = nextVisibleState
End Sub

When the detail layer starts visible (True), the first click computes Not True (False) to hide every object on that layer, and the second click computes Not False (True) to restore them. Keep the explicit offset variable for maintainability or condense the body to Layers.Item(4).Visible = Not Layers.Item(4).Visible. Never read one index and write another, because that copies visibility between layers instead of toggling one layer.

How do you toggle a layer inside a WinCC ScreenWindow or named screen? #

Bare Layers.Item(n) addresses only the screen containing the button, so toggling a layer on another screen or inside a picture window (ScreenWindow) requires specifying the full hierarchical path starting from HMIRuntime.Screens or HMIRuntime.ActiveScreen. Siemens TIA Portal WinCC RT Professional documentation defines two qualified access patterns beyond an unqualified local call:

  • Active screen scope: HMIRuntime.ActiveScreen.Layers(index).Visible targets the active screen when the script executes outside that screen's direct scope.
  • Named or nested screen scope: HMIRuntime.Screens("screen_name").Layers(index).Visible addresses a specific loaded screen by name; when that screen resides inside a ScreenWindow, specify the full hierarchical screen path from HMIRuntime.Screens down to the target screen before calling .Layers(index).Visible.

Using an illustrative screen name "PumpOverview" and an illustrative local variable targetIndex initialized to 2 (for configured Layer 1), bind the reference once with Set so the read and write target the exact same screen layer:

Sub OnClick(ByVal item)
    ' Illustrative local variables (VBScript Variant types, explicitly initialized)
    Dim screenName
    Dim targetIndex
    Dim targetLayer

    screenName = "PumpOverview" ' Example loaded screen name
    targetIndex = 2             ' Arithmetic: configured Layer 1 + 1 = 2

    ' Documented WinCC RT Professional API: HMIRuntime.Screens(...).Layers(index).Visible
    Set targetLayer = HMIRuntime.Screens(screenName).Layers(targetIndex)
    targetLayer.Visible = Not targetLayer.Visible
End Sub

Use unqualified Layers.Item(n) when the toggle button resides directly on the target screen. Switch to a qualified HMIRuntime.Screens path whenever a persistent navigation header controls detail layers inside a child ScreenWindow.

Which objects ignore screen layer visibility and how should you group details? #

Active controls, specifically alarm views, trend views, .NET controls, and screen windows, render in separate runtime windows that do not strictly follow screen layer ordering, so reserve layer toggling for standard graphical objects aligned with ANSI/ISA-101.01 progressive disclosure. Because those four active controls draw in independent window handles, a foreground graphic layer will not reliably obscure an alarm or trend view. Group standard shapes, labels, symbols, and I/O fields onto toggled layers, and manage active controls or nested screen windows through their own visibility controls or dedicated popups.

Use ANSI/ISA-101.01 to decide which elements belong on an operator-toggled layer. The standard organizes HMI displays into four hierarchy levels—Level 1 (Overview/Facility), Level 2 (Unit/Area Control), Level 3 (Equipment Detail), and Level 4 (Diagnostic/Maintenance)—to prevent cognitive overload. Keep normal running process graphics and the toggle button on always-visible lower layers, and place Level 3 equipment details or Level 4 diagnostics on dedicated upper layers that appear only on request.

How do you verify a WinCC Professional layer toggle before deploying to a machine? #

Run a two-click runtime acceptance test on an isolated engineering bench before deploying the screen, confirming that the first click flips only the target layer while keeping the toggle button visible and the second click restores the original state. Editor visibility icons never test VBScript execution, 1-based indexing, or runtime screen paths, so run these four bench checks in runtime:

  • Record the starting state before clicking, confirming the toggle button is visible and noting whether the target layer starts shown or hidden.
  • Click once and verify every object on the target layer flips state while unrelated layers remain unchanged.
  • Confirm the toggle button stays visible and clickable after the first transition.
  • Click a second time and verify the target group returns to its recorded starting state.

When commissioning on a touchscreen station after bench-testing with a mouse, verify touch event behavior against the steps for WinCC RT Professional button events on mouse versus touchscreens. Match any failed bench check to the table below:

Bench test symptom Probable cause Corrective action
Target group hides; button stays visible Normal first transition Execute the second click to verify full restoration
Target group and button both disappear Button shares the target layer or another script hides its layer Move the button to a separate visible layer in Properties > Miscellaneous > Layer
Unrelated objects toggle; target group stays fixed Off-by-one collection index Set Layers.Item to configured layer number + 1
Only part of the target group toggles Objects span multiple layers or include an active control Unify object layer assignments or control active views individually
Nothing changes on click Unbound Click event, wrong HMIRuntime.Screens path, or script error Verify Properties > Events > Click, confirm the screen path, and recompile

Questions asked

How do Graphics Designer VBA layer methods differ from runtime VBScript?

Graphics Designer VBA automates engineering tasks rather than live operator clicks and separates Configuration System layers from Runtime layers across the same 1 to 32 one-based index range. You change design-time visibility with SetCSLayerVisible on an HMIView object, whereas ActiveDocument.SetRTLayerVisible sets initial runtime layer visibility with a Boolean True or False argument before deployment.

Can a WinCC Professional VBScript count or loop through all screen layers?

Yes. The WinCC VBS Layers collection provides a Count property returning the total number of screen layers and supports enumeration so a For Each loop can inspect or reset every layer in one routine. Each Layer object accepts standard Boolean True or False values as well as the VBScript constants vbTrue and vbFalse when setting its Visible property.

How does SIMATIC WinCC Unified script layer visibility inside a faceplate?

Starting with TIA Portal V17 Update 1 and continuing through V18 and V19, WinCC Unified replaces numeric one-based VBScript indexes with JavaScript name lookups on a read-only HmiLayerCollection. On full screens you address each layer by its configured name through Screen.Layers, whereas inside a reusable faceplate you toggle the Boolean Visible property through Faceplate.Layers using the configured layer name.

How do objects stack inside the same WinCC screen layer during engineering?

Within any single WinCC layer, graphical objects stack hierarchically in their creation order so newer elements sit in front of earlier ones on that layer. During engineering, one layer always remains active in the Layers task card to receive newly inserted objects, and you can rename or temporarily hide layers there without altering runtime layer numbers.

How do SCADA platforms without fixed screen layers handle display decluttering?

Platforms without fixed numbered layers rely on component properties and zoom thresholds instead of layer collections. Ignition Perspective exposes a Boolean meta.visible property on every component that you bind to zoom expressions or swap with Breakpoint Containers across viewport widths. AVEVA InTouch HMI and OMI use Zoom Layers with configured minimum and maximum zoom percentage limits and a runtime ZoomPercent property, such as revealing high-detail graphics at 200 percent zoom or higher.

Keep reading

  • How-to

    How WinCC visibility animations hide and show objects at runtime

    A layer you hide in the editor stays visible at runtime, because layers are an engineering arrangement, not a runtime command. To hide and show objects while the panel runs, bind a visibility animation to a tag and toggle it with an invert bit button, or flip each object's Visible property from a VB script. For overlapping indicators with priority, the lower-priority object's show range must exclude the value that means the higher-priority condition is active.

    HMI and touchscreens

  • Explainer

    Why WinCC Professional full screen hides a second HMI runtime

    WinCC Professional Runtime in full-screen mode claims the entire work area of the extended desktop by design, so a co-resident Advanced Runtime is hidden behind it, not stopped. Run both runtimes in window mode with one window per monitor, because Advanced Runtime is not released for multi-monitor use and only one Professional Runtime runs in parallel on one operating system.

    HMI and touchscreens

  • How-to

    Delivering WinCC Professional FWx runtime files to a customer PC

    A WinCC Professional PC Station project cannot become a standalone executable: compilation produces FWx runtime files that still need the installed runtime engine. Ship the compiled FWx files only, and the customer starts them through RT Loader on a PC that has WinCC Runtime Professional installed, with no TIA Portal engineering installation and no editable source project in the package.

    HMI and touchscreens