How to Dynamically Control Graphic Layer Visibility in WinCC Runtime and WebNavigator

How to Dynamically Control Graphic Layer Visibility in WinCC Runtime and WebNavigator

In SIMATIC PCS 7 and WinCC, dynamically showing or hiding graphic layers based on operating modes (scrObj.Layers(x).Visible = True/False) frequently exhibits erratic behavior or fails to refresh because the WinCC graphical rendering engine (PDLRT.exe) does not automatically trigger an asynchronous repaint when layer properties are changed via script. Furthermore, on WebNavigator clients, evaluating screen objects in the OnOpen event fails because the script context references the parent picture window rather than the called picture. The robust, Siemens-recommended solution is grouping related objects and dynamically binding the group's 'Visible' property to an internal mode tag.

Table of Contents

WinCC Graphic Layer Architecture and Scripting Model

In SIMATIC WinCC Graphics Designer, process pictures (.pdl) are structured into 32 graphical layers (Layers 0 through 31). Layers are primarily designed as engineering layout aids to allow engineers to separate background graphics, piping networks, instrumentation, and cabling conduits during design time.

WinCC exposes layers to the runtime VBScript object model:

Dim scrObj
Set scrObj = HMIRuntime.ActiveScreen
scrObj.Layers(5).Visible = True  ' Show Layer 5
scrObj.Layers(5).Visible = False ' Hide Layer 5

Engineers frequently attempt to use this VBScript interface to dynamically alter operational graphics based on operating modes (e.g., hiding slurry pipelines during chemical cleaning mode, or showing bypass valves only during startup) to prevent cluttering operator displays.

Root Cause Analysis for Inconsistent Layer Toggling and WebNavigator Failures

While layer toggling works intermittently, engineers encounter severe operational inconsistencies in production environments:

1. The Rendering Asynchrony and Missing Repaint

  • When a picture loads, the graphics rendering engine (PDLRT.exe) and the VBScript runtime engine (CCVBS.exe) execute in separate operating system threads.
  • If a script in the picture's OnOpen (Picture Open) event executes scrObj.Layers(x).Visible = False, the memory property changes, but PDLRT does not trigger a window redraw event. Consequently, both layers remain visually rendered until an operator manually triggers a redraw (such as resizing the window or navigating away and back).

2. WebNavigator Context Resolution Failure

  • On WinCC WebNavigator thin clients running inside browser sandboxes, calling HMIRuntime.ActiveScreen within the OnOpen event returns a handle to the calling parent picture window, NOT the newly loaded child picture.
  • The script modifies the layer visibility of the wrong picture context, leaving the active process picture completely unaffected.
  • In contrast, calling the same script from a button's OnClick event works because user interaction provides an explicit focus context.

Step-by-Step Implementation of Robust Dynamic Visibility

To achieve 100% reliable dynamic visibility across standard OS Clients and WebNavigator without rendering glitches:

Method 1: The Group Object Visibility Architecture (Siemens Recommended)

Instead of manipulating entire layers, organize mode-dependent graphic elements into named Group Objects:
1. In Graphics Designer, select all pipes, instruments, and text labels relevant to the specific operating mode.
2. Right-click and select Group -> Group.
3. In Object Properties, rename the group: e.g., grp_Mode_Cleaning.
4. Navigate to Properties -> Miscellaneous -> Display (Visible).
5. Attach a Dynamic Dialog or Direct Connection:
* Tag: Operating_Mode_Tag (Integer or Binary).
* Expression: Operating_Mode_Tag == 2 (Visible = Yes; otherwise No).
6. Save the picture. The WinCC graphics engine evaluates object visibility at the native C++ level during every scan cycle, guaranteeing instantaneous, flicker-free rendering on all clients.

Method 2: Scripted Refresh Workaround (If Layers Must Be Used)

If structural complexity forces the use of layers:
1. Do not execute layer toggling directly in OnOpen.
2. Insert an invisible static text object or dummy rectangle named txtLayerTrigger.
3. Configure an internal tag trigger on property Output Value or use a delayed C-action:
c // Force asynchronous repaint of picture window SetVisible(lpszPictureName, "txtLayerTrigger", GetVisible(lpszPictureName, "txtLayerTrigger"));
4. On WebNavigator, always resolve picture handles explicitly using HMIRuntime.Screens("@1001.Workspace:PictureName") rather than ActiveScreen.

Layer Toggling vs Group Visibility Architectural Comparison Matrix

The following table compares runtime layer toggling against group visibility binding:

Architectural MetricLayer Scripting (Layers(x).Visible)Group Object Visibility (Group.Visible)Implementation MethodProcedural VBScript (OnOpen)Declarative Dynamic Dialog / Tag ConnectionRepaint ReliabilityUnreliable (Prone to missing redraws)100% Deterministic (Instantaneous redraw)WebNavigator Client CompatibilityFails in OnOpen (Context lost)100% Compatible across all Web clientsEngineering MaintenanceHigh (Hardcoded script layer indexes)Low (Self-documenting object groups)Runtime CPU OverheadModerate (Interpreted VBS thread)Negligible (Native C++ display evaluation)

Adopting declarative group visibility guarantees universal compatibility across all workstation types.

Verification

To verify dynamic visibility behavior:
1. In WinCC Runtime, open the modified process picture.
2. In the AS or via Tag Simulator, toggle the operating mode tag:
* Mode = Normal: Confirm mode-specific pipes and instruments disappear immediately.
* Mode = Cleaning: Confirm the group renders cleanly without requiring manual window resizing.
3. Open the identical picture on a WinCC WebNavigator client:
* Verify that initial opening immediately renders only the active mode objects.
4. Open the WinCC_Sys_01.log diagnostic file; confirm zero VBScript context or property errors.

Limitations and Operational Precautions

  • Avoid nesting more than 5 levels of Group Objects in Graphics Designer, as deep grouping hierarchies increase memory parsing times during picture loads.
  • Modifying ActiveScreen in global scripts executed on the OS Server can corrupt client display queues; client scripts must remain strictly local to client execution.
  • Ensure all graphic elements inside a group have unique object names if they contain dynamic tag connections.
  • Test all dynamic graphic scripts on both native WinCC desktop clients and WebNavigator thin clients prior to site commissioning.

Engineer FAQ

Why does HMIRuntime.ActiveScreen return the wrong picture in WebNavigator?

In WebNavigator, the browser control instantiates picture windows asynchronously; during the OnOpen event, focus has not yet fully shifted to the child picture, causing ActiveScreen to point to the parent window.

How many layers does WinCC Graphics Designer support?

WinCC Graphics Designer supports 32 layers (Layer 0 to Layer 31). Layer 0 is typically used for background templates, and Layer 31 for top-level system dialogs.

Can I hide block icons by making their layer invisible?

Yes, but if the block icon contains an active alarm frame, hiding the layer suppresses the icon while the alarm remains active in the alarm logging subsystem.

Technical References

Related Articles

Related Tags

  • WinCC_Graphics
  • Layer_Visibility
  • VBScript
  • WebNavigator
  • Dynamic_Dialog
6 respuestas