Reading and Displaying Picture Window TagPrefix in WinCC Graphic Objects - VBScript and C-Script Workflows

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

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:

Scripting LanguageAPI MechanismCode ComplexityPerformance ImpactRecommended Use CaseVBScriptParent.Parent.TagPrefixVery Low (4 lines)Negligible (< 1 ms)Standard PCS 7 FaceplatesANSI-C ScriptGetTagPrefix()Moderate (Memory buffer)Very LowLegacy WinCC C-Script librariesGetLink() APIParses linked dynamic tagModerateLowExtracting tag from dynamic propertyDirect ConnectionN/AUnsupportedN/ANot feasible across containers

Step-by-Step Implementation Procedure in Graphics Designer

Follow this procedure in WinCC Graphics Designer:

Step 1: Prepare the Child Picture

  1. Open the child screen (e.g., Faceplate_Valve.pdl).
  2. Insert a Static Text object from the standard palette; rename it to txt_HeaderTag.
  3. Set default text to [TagPrefix].

Step 2: Implement VBS Script on Picture Open

  1. Right-click the background of the screen (empty area) and select Properties.
  2. Switch to the Event tab.
  3. Under Picture Object > Miscellaneous, locate the event Open picture.
  4. Right-click the light bulb icon and select VBS Action.
  5. Paste the traversal script:
    vbscript Dim objText Set objText = ScreenItems("txt_HeaderTag") objText.Text = objText.Parent.Parent.TagPrefix
  6. Click Compile (Ctrl+F9) and save the picture.

Step 3: Test Runtime Behavior

  1. In the parent picture, insert a Picture Window.
  2. Set Picture Name: Faceplate_Valve.pdl.
  3. Set Tag Prefix: FIC_101..
  4. Activate WinCC Runtime; verify that txt_HeaderTag displays FIC_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

Related Articles

Related Tags

  • WinCC
  • TagPrefix
  • Picture Window
  • VBScript
  • Faceplates
6 respuestas