Reading and Displaying Picture Window TagPrefix in WinCC Graphic Objects - VBScript and C-Script Workflows
In SIMATIC PCS 7 v8.2 and WinCC v7.4, dynamically copying and displaying the 'TagPrefix' of an active Picture Window into a static text or header object inside the embedded graphic (e.g., extracting 'Valve1/Ctrl' from the parent window and displaying it as title text) can be implemented via VBScript or ANSI-C script on the picture's open event. In VBScript, the object accesses the property traversing the object hierarchy using 'StaticText.Text = StaticText.Parent.Parent.TagPrefix'. In ANSI-C, the standard API function 'GetTagPrefix(lpszPictureName, lpszObjectName)' retrieves the string, which is then assigned to the static text's 'Text' property, eliminating the need to hardcode tag paths across reusable faceplate templates.
Table of Contents
- The TagPrefix Architecture in Reusable WinCC Faceplates
- Method 1: VBScript Hierarchical Parent Traversal
- Method 2: ANSI-C Script Using GetTagPrefix()
- Method 3: Direct Connection and Dynamic Dialog Alternatives
- Comparative Scripting Matrix: TagPrefix Retrieval Methods
- Step-by-Step Implementation Procedure in Graphics Designer
- Verification
- Limitations and Operational Precautions
- Engineer FAQ
- Technical References
- Related Articles
- Related Tags
The TagPrefix Architecture in Reusable WinCC Faceplates
In SIMATIC PCS 7 and WinCC, Picture Windows (PictureWindow) represent the standard mechanism for modular faceplate visualization:
- A single generic process screen (e.g., Faceplate_Motor.pdl or Faceplate_Valve.pdl) is authored once.
- When an operator clicks a block icon in runtime, a Picture Window opens, loading Faceplate_Valve.pdl and assigning a TagPrefix: e.g., Plant1/UnitA/Valve101..
- All dynamic tag links inside the child picture (e.g., .PV_Out, .Command, .Status) automatically prepend the TagPrefix, binding dynamically to the specific field device.
However, graphic designers frequently need to display the device's technological tag name (the TagPrefix string itself) inside a static text label or title banner. Because the child picture does not inherently know which parent Picture Window loaded it without querying runtime properties, a script must bridge the container boundary.
Method 1: VBScript Hierarchical Parent Traversal
In modern WinCC (v7.0 through v7.5 and PCS 7 v8.x/v9.x), the VBScript object model provides direct access to hierarchical parent containers:
- Inside the child .pdl picture, place a Static Text object named txt_TagName.
- On the Picture Open event of the child screen (or an event on the text object itself), execute:
```vbscript
Sub OnLoaded()
Dim objText, strPrefix
Set objText = ScreenItems("txt_TagName")
' Traverse from child object -> child screen -> parent Picture Window
On Error Resume Next
strPrefix = objText.Parent.Parent.TagPrefix
' Strip trailing dot or delimiter if present
If Right(strPrefix, 1) = "." Then
strPrefix = Left(strPrefix, Len(strPrefix) - 1)
End If
objText.Text = strPrefix
End Sub
```
- This method executes instantaneously in local memory without consuming WinCC tag communication channels.
Method 2: ANSI-C Script Using GetTagPrefix()
In classic C-scripting architectures:
- On the Text property of the static text object, attach an ANSI-C action triggered by Picture Name:
```c
char _main(char lpszPictureName, char lpszObjectName, char lpszPropertyName)
{
static char szPrefix[128];
char* pPrefix = NULL;
// Acquire the TagPrefix of the container picture
pPrefix = GetTagPrefix(lpszPictureName, lpszObjectName);
if (pPrefix != NULL)
{
strncpy(szPrefix, pPrefix, sizeof(szPrefix) - 1);
szPrefix[sizeof(szPrefix) - 1] = '';
return szPrefix;
}
return "NO_PREFIX";
}
``
- The functionGetTagPrefix()` is a native WinCC C-API call that resolves the active prefix assigned to the parent container.
Method 3: Direct Connection and Dynamic Dialog Alternatives
For engineers seeking zero-code configurations:
- Direct Connection: A Direct Connection cannot traverse up the container hierarchy to read a parent property.
- Dynamic Dialog: Dynamic Dialogs evaluate tags and expressions, but cannot access parent window attributes directly.
- Therefore, VBScript or ANSI-C remains mandatory for dynamically copying TagPrefix to visual text properties inside child windows.
Comparative Scripting Matrix: TagPrefix Retrieval Methods
The table below compares methods for reading TagPrefix:
Parent.Parent.TagPrefixGetTagPrefix()Step-by-Step Implementation Procedure in Graphics Designer
Follow this procedure in WinCC Graphics Designer:
Step 1: Prepare the Child Picture
- Open the child screen (e.g.,
Faceplate_Valve.pdl). - Insert a Static Text object from the standard palette; rename it to
txt_HeaderTag. - Set default text to
[TagPrefix].
Step 2: Implement VBS Script on Picture Open
- Right-click the background of the screen (empty area) and select Properties.
- Switch to the Event tab.
- Under Picture Object > Miscellaneous, locate the event Open picture.
- Right-click the light bulb icon and select VBS Action.
- Paste the traversal script:
vbscript Dim objText Set objText = ScreenItems("txt_HeaderTag") objText.Text = objText.Parent.Parent.TagPrefix - Click Compile (
Ctrl+F9) and save the picture.
Step 3: Test Runtime Behavior
- In the parent picture, insert a Picture Window.
- Set
Picture Name:Faceplate_Valve.pdl. - Set
Tag Prefix:FIC_101.. - Activate WinCC Runtime; verify that
txt_HeaderTagdisplaysFIC_101.automatically.
Verification
To confirm that the TagPrefix is accurately copied:
1. Dynamic Text Verification: In WinCC Runtime, open multiple instances of the faceplate for different valves (e.g., Valve_101, Valve_102); verify that each faceplate header accurately reflects its unique tag name.
2. Error-Free Execution: Open C:\Program Files (x86)\Siemens\WinCC\diagnose\WinCC_Sys_01.LOG; confirm that no VBS runtime error 424 ('Object required') is logged.
3. Container Resizing Test: Minimize and restore the Picture Window; confirm that text remains properly anchored and does not revert to placeholder text.
Limitations and Operational Precautions
Engineering teams must observe the following precautions:
- If the child .pdl picture is opened directly in Graphics Designer test mode without an enclosing Picture Window, Parent.Parent will evaluate to Nothing; always incorporate error handling (On Error Resume Next).
- Nested picture windows (a picture window inside another picture window) require traversing additional hierarchy levels (e.g., Parent.Parent.Parent.Parent.TagPrefix).
- Always validate that tag prefixes match the exact case-sensitive naming configured in the S7-400 symbol table and WinCC Tag Management.
Engineer FAQ
Can I strip the trailing dot '.' from the TagPrefix in VBS?
Yes. Use string manipulation: If Right(strPrefix, 1) = '.' Then strPrefix = Left(strPrefix, Len(strPrefix) - 1) before assigning it to the static text.
Why does my VBScript return an error when opening the picture?
If the picture is opened as the root desktop screen rather than inside a Picture Window, Parent.Parent does not exist. Wrap the code in If Not (objText.Parent.Parent Is Nothing) Then ....
Can I use this method to set the title bar text of the Picture Window itself?
Yes. To set the Picture Window caption bar, set objText.Parent.Parent.CaptionText = strPrefix directly from the script.
Technical References
- WinCC Scripting: VBS, ANSI-C, VBA Reference Manual (A5E37536450)
- SIMATIC PCS 7 OS Process Control System Manual (A5E36987024)
- Siemens Support: Working with Picture Windows and TagPrefix in WinCC (Entry ID: 109740190)
Related Articles
- Automating Runtime Screen Captures Across the WinCC Picture Tree in SIMATIC PCS 7
- Configuring SCL Attributes and WinCC Block Icons for Custom Technological Blocks
- Troubleshooting Dial Gauges and Display Controls Not Rendering on WinCC Web Navigator
Related Tags
- WinCC
- TagPrefix
- Picture Window
- VBScript
- Faceplates