WinCC Action Scripts: Switching Pictures via Tag Trigger

David Krause10 min read
SiemensTutorial / How-toWinCC
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

1. Overview

Siemens WinCC runtime supports automatic screen (picture) navigation driven by process values. When a tag changes state—e.g., a mode selector bit, a recipe phase, or a fault flag—the HMI should switch to the matching process picture without operator intervention. The mechanism for this in WinCC V7.x, WinCC Professional (TIA Portal), and the legacy WinCC flexible runtime is the Global Action (or Scheduled Task) executed by the C-Editor scripting engine.

This reference covers three production-proven methods:

  • SSMChangeWorkField – for Split Screen Manager (base picture switching in WinCC V7.x).
  • OpenPicture – the standard picture-change call for permanent area, work area, or modal dialogs.
  • Picture Window attribute write – for TIA Portal WinCC and embedded Picture Window objects whose PictureName property can be driven by a tag or by C action.

All three approaches share the same first step: configure a trigger on the C action. The trigger tells the WinCC scripting runtime when to evaluate the script. Without a properly configured trigger the script will not fire and the picture will not change.

Trigger is everything. A correct C function call inside an action will never execute if the action's trigger is missing, misconfigured, or pointing at the wrong tag. Open Info/Trigger (or press Ctrl+I) inside the C-Editor before debugging any "the script does nothing" symptom.

2. Prerequisites

Item Requirement Notes
WinCC version WinCC V7.0 SP3 or later, or WinCC Professional V13+ (TIA Portal) C-Editor is bundled; VBS and C are both available.
Project state Open in WinCC Explorer / TIA Portal with the runtime deactivated Editing scripts in running runtime is blocked.
Process tag Internal or external tag of type BOOL, INT, or WORD used as mode selector Must be in the project tag management; external tags require the configured channel/connection.
Target pictures Both pictures must exist in Graphics Designer / TIA HMI screens Picture names are case-sensitive.
User rights Local administrator or member of SIMATIC HMI group Actions modifying pictures require write authorization on the runtime.

For the full WinCC V7.x scripting API see the SIMATIC HMI WinCC V7.5 Scripting (C) manual. For TIA Portal see the SIMATIC WinCC Professional V17 Programming and Operating Manual.

3. Method 1 – Global Action with OpenPicture (C-Editor)

The OpenPicture function is the workhorse for picture changes. It opens a picture in a target work area defined by the runtime configuration.

3.1 Create the global action

  1. Open WinCC Explorer.
  2. Right-click Global Scripts → C-Editor and select New Action (or open an existing one).
  3. Name the action descriptively, e.g. ac_ModePictureSwitch.
  4. Paste the C function call into the editor.

3.2 C source for a binary mode tag

// ac_ModePictureSwitch.c
// Triggered cyclically or on @ModeSelector change
// @ModeSelector = 0 → Picture_Manual.pdl
// @ModeSelector = 1 → Picture_Automatic.pdl

if (GetTagBit("ModeSelector") == 0)
{
    OpenPicture("Picture_Manual.pdl");
}
else
{
    OpenPicture("Picture_Automatic.pdl");
}

3.3 Function reference

Function Syntax Description
GetTagBit BYTE GetTagBit(LPCTSTR lpszTagName) Returns 0/1 for a BOOL tag.
GetTagWord WORD GetTagWord(LPCTSTR lpszTagName) Use for multi-state mode selectors (0, 1, 2, 3…).
OpenPicture BOOL OpenPicture(LPCTSTR lpszPictureName) Opens the named PDL in the configured work area. Returns 0 on failure.
SetTagByte BOOL SetTagByte(LPCTSTR lpszTagName, BYTE bValue) Writeback to acknowledge a transition (optional).

4. Method 2 – Split Screen Manager (SSM)

The Split Screen Manager (SSM) is a WinCC V7.x component that allows a base picture to be subdivided into up to four fields (top, bottom, left, right). To swap one of those fields from C, call SSMChangeWorkField.

4.1 SSM configuration

  1. Open Computer → Properties → Split Screen Manager in WinCC Explorer.
  2. Define the layout: e.g., 1 row, 1 column → single work field.
  3. Assign the field index (typically '1' for the primary work field).
  4. Activate the SSM checkbox in the startup list of the WinCC runtime.

4.2 C source for SSM

// Field index '1' = primary work field (top-left in a 2x2 layout)
if (GetTagBit("ModeSelector") == 0)
{
    SSMChangeWorkField('1', "Picture_Manual.pdl", TRUE);
}
else
{
    SSMChangeWorkField('1', "Picture_Automatic.pdl", TRUE);
}

4.3 SSMChangeWorkField parameter matrix

Parameter Type Meaning Typical values
szField char SSM field index in single-quote literal '1', '2', '3', '4'
szPicture LPCTSTR Target picture file name (string literal) "Main.pdl"
bFocus BOOL Give the new picture input focus TRUE / FALSE
In C-Editor the field index is a character literal — single quotes only: '1', not 1. Using a double-quoted string here is a common typo that compiles but silently fails at runtime.

5. Method 3 – Picture Window (TIA Portal WinCC)

In WinCC Professional / Comfort Panels the Picture Window object is the modern equivalent of an SSM field. Its PictureName property accepts both a static string and a dynamic tag-driven expression. Either drive it from a tag or set it from a C action via SetProperty / SetTag.

5.1 Drive PictureName from a tag (no script)

  1. Create a string tag PictureTarget of type WSTRING[80].
  2. PLC writes the picture name (e.g., "Screen_Manual") into that tag.
  3. In the HMI screen, select the Picture Window → Properties → PictureName → set dynamization to the tag.

5.2 Drive PictureName from a C action

// C action in TIA WinCC Professional
if (GetTagBit("ModeSelector") == 0)
{
    SetPropertyByTagName(lpszPictureName:="PictureWindow_1",
                         lpszPropertyName:="PictureName",
                         lpszValue:="Screen_Manual");
}
else
{
    SetPropertyByTagName(lpszPictureName:="PictureWindow_1",
                         lpszPropertyName:="PictureName",
                         lpszValue:="Screen_Automatic");
}

Refer to the SIMATIC WinCC Professional V17 Programming Manual for the full SetPropertyByTagName signature and supported property names.

6. Configuring the Trigger (Ctrl+I)

This is the part that catches every new WinCC scripter. Inside the C-Editor, every action has an Info dialog that controls execution frequency.

6.1 Open the trigger dialog

Use either:

  • The action toolbar button Info/Trigger (in the action bar of the C-Editor), or
  • Menu Edit → Info, or
  • Keyboard shortcut Ctrl+I.

6.2 Trigger options

Trigger type Behavior When to use
Standard cycle (e.g., 250 ms, 1 s, 2 s) Fires periodically regardless of tag changes Mode selectors that toggle quickly, or when you want sub-second response.
Tag trigger (single tag) Fires when the named tag changes value Bit-style mode selector; efficient CPU usage.
Tag trigger (multiple) Fires when ANY of N tags changes Combined condition ("mode OR fault").
Event-driven Fires on a WinCC event (alarm, archive, login) Alarm-driven screen change to a fault faceplate.

6.3 Recommended trigger for picture switching

Use a tag trigger on the mode tag with a 1-second standard cycle fallback enabled. This guarantees a periodic re-evaluation that catches any missed edge in case of bounce or lost trigger (e.g., after a tag gets its initial value when the runtime starts).

// Trigger configuration dialog (C-Editor Info / Ctrl+I)
//  Trigger:    @ModeSelector
//  Cycle:      1 s
//  Cold restart: TRUE
Enable Run on cold restart for picture-switching actions. When the WinCC runtime starts, you almost always want the picture to be set to the current mode value, not the previous one from the last session.

7. Multi-State Mode Selector (INT / WORD Tag)

A 1-bit mode selector is rarely enough. Real machines have Manual, Auto, Setup, Service, Cleaning and Fault modes. A single WORD tag plus a switch statement is cleaner than chained if/else.

// ac_ModePictureSwitch_Word.c
WORD wMode = GetTagWord("ModeSelector");

switch (wMode)
{
    case 0:  OpenPicture("Screen_Manual.pdl");    break;
    case 1:  OpenPicture("Screen_Automatic.pdl"); break;
    case 2:  OpenPicture("Screen_Setup.pdl");     break;
    case 3:  OpenPicture("Screen_Service.pdl");   break;
    case 4:  OpenPicture("Screen_Cleaning.pdl");  break;
    case 99: OpenPicture("Screen_Fault.pdl");     break;
    default: OpenPicture("Screen_Manual.pdl");    break;
}
Mode value Picture Description
0 Screen_Manual.pdl Operator-controlled hand jogs
1 Screen_Automatic.pdl Production auto-cycle
2 Screen_Setup.pdl Tool teach / recipe parameters
3 Screen_Service.pdl Maintenance / I/O forcing (auth-gated)
4 Screen_Cleaning.pdl CIP / wash-down recipe
99 Screen_Fault.pdl Alarm summary + acknowledge

8. Verification Procedure

After deployment, validate the script with this checklist:

  1. Compile check. In the C-Editor, compile the action. The status bar must show 0 errors, 0 warnings. Warnings about implicit casts from WORD to int are common and harmless; warnings about undeclared identifiers are not.
  2. Trigger visibility. Open Info/Trigger (Ctrl+I) and confirm the configured trigger tag and cycle are present.
  3. WinCC diagnosis files. Activate the runtime, toggle the mode tag from the PLC or the WinCC tag simulator, and inspect WinCC_SStart_xx.log and APLOG*.txt in the WinCC project \Diagnostics\ folder.
  4. Picture change confirmation. Watch the title bar / current picture name in Tools → Runtime Diagnostics → Picture Tree. The active PDL should change within one cycle after the tag flips.
  5. Cold restart test. Stop the runtime, leave the mode tag at value 2, restart. The startup picture must be Screen_Setup.pdl, not the last-shown picture.

9. Troubleshooting Matrix

Symptom Likely cause Remedy
Script compiled, but picture never changes Trigger not configured; Info/Trigger is empty Open Ctrl+I, add the mode tag and a 1 s cycle, recompile.
Picture changes randomly Trigger is set to a 250 ms standard cycle with no tag trigger Add the mode tag as a tag trigger; keep cycle as a fallback only.
OpenPicture returns 0 every call Picture name misspelled or in wrong folder Confirm the PDL is in the project \GraCS\ directory; names are case-sensitive.
SSM call compiles, no picture change Field index passed as string ("1") instead of char literal ('1') Use single-quoted char literal for the field argument.
TIA Picture Window stays blank Tag written to PictureName has wrong data type Use WSTRING matching the configured length; do not pass BOOL.
Picture change works at design, fails in runtime Action has no runtime license activated Check Computer → Properties → Runtime → Scripts in WinCC Explorer.
Initial picture wrong on startup Cold restart trigger not enabled Tick Run on cold restart in the trigger dialog.
Mode change flashes through every state briefly PLC program is dithering the mode tag during HMI scan Debounce the tag on the PLC side (e.g., 200 ms low-pass) before exposing it to HMI.

10. Performance and Safety Considerations

Picture-change actions are cheap, but in a 50,000-tag project with hundreds of actions the cumulative trigger load matters.

  • Cycle cost. A 250 ms global action consumes roughly 0.5 % CPU per script on a typical WinCC server. Prefer tag triggers (edge-triggered) over tight cycles.
  • Trigger granularity. One action with a multi-tag trigger beats ten single-tag actions. The runtime fires once when any listed tag changes.
  • Auth gating. Picture change to a Service or Setup faceplate does not replace the authorization system. Apply User-Change visibility logic on top.
  • Audit trail. Capture the mode tag in an archive so post-incident analysis can replay the picture transitions.
  • Redundancy. On a redundant WinCC pair, replicate the C-Editor project by exporting/importing the entire script directory; do not copy single C files by hand.

11. Migration Notes: WinCC V7 → TIA WinCC Professional

WinCC V7.x TIA WinCC Professional Notes
C-Editor global action C-Editor scheduled task Same API surface; trigger dialog identical.
SSMChangeWorkField SetPropertyByTagName on Picture Window SSM not available in TIA; use Picture Window.
VBScript HMIRuntime.BaseScreenName Item-based PictureName dynamization Newer projects prefer tag dynamization over scripts.
ApDiag / APCDiag Trace + ProDiag Diagnostic tooling rebuilt in TIA.

When migrating, export global C actions from the V7 project, then import them in TIA via Scripts → Import/Export. Verify triggers, because the cycle dropdowns use slightly different default values between V7.4 and V17.

12. Frequently Asked Questions

Where exactly is the Trigger dialog in the C-Editor?

Open the action in the C-Editor and either click the Info/Trigger button on the action toolbar, choose Edit → Info, or press Ctrl+I. The dialog lists the trigger tag, cycle time, and the Run on cold restart flag.

What is the difference between a global action and a local action?

A global action runs in the background WinCC process and is available to all process pictures; picture-change logic belongs here. A local action is bound to a single picture or object event (e.g., a button click) and runs only while that picture is loaded.

Why does my picture change fire repeatedly while the mode tag is steady?

If the trigger is configured with a 250 ms standard cycle and no tag trigger, the action re-evaluates on every cycle and re-issues the OpenPicture call. This is harmless for the screen itself but burns CPU. Add the mode tag as a tag trigger and keep only a slow cycle (1–2 s) as fallback.

Can I switch pictures on alarm acknowledgment or on a logged-in user?

Yes. In the C-Editor Info/Trigger dialog, switch the trigger source to an event instead of a tag. WinCC exposes alarm, archive, and user-change events; pick the relevant one and the script will fire on the event edge.

Does SSMChangeWorkField exist in TIA Portal WinCC Professional?

No. The Split Screen Manager was retired in TIA Portal. Use a Picture Window object and dynamize the PictureName property with a tag, or set it from a C action via SetPropertyByTagName. The behavior is functionally identical.

Back to blog