Bulk Create HMI Logging Tags in TIA Portal V20 with Openness

David Krause12 min read
SiemensTIA PortalTutorial / How-to
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

Bulk Create HMI Logging Tags in TIA Portal V20 with Openness

Overview

Configuring an HMI in TIA Portal V20 with WinCC Professional or WinCC Unified frequently forces engineers into a tedious per-tag workflow. Adding a single logging tag requires a fixed sequence: open the Logging Tags tab, insert a name, select a Data Log, choose a Logging Mode (Cyclic, On Change, On Command), and set the Logging Cycle in milliseconds. For one or two tags this is acceptable; for hundreds or thousands of tags it is unworkable.

The problem scales poorly. A delta-robot platform with 24 legs, 4 chords, and 8 motors, each carrying 4 analog values, requires 3,072 individual logging tag configurations when managed by hand. The HMI Tag editor exposes a partial shortcut for flat tag lists, but it does not reach the deeply nested array structures (HMI_ActVal_Platform.Legs[i].Chords[j].Motors[k].AnalogValues.ActSpeed) that are common in modular machine libraries built on PLC data blocks.

This article documents two production-grade methods to eliminate the manual bottleneck:

  1. The native "Add new logging tag to each logable tag" editor button for flat tag selections.
  2. The TIA Openness API (Visual Basic .NET) for programmatic bulk creation across nested arrays, which is the only practical path for projects exceeding a few hundred tags.

Both methods preserve the WinCC Unified data model: a logging tag is a wrapper around an HMI tag that adds a persistence target (Data Log), an acquisition mode, and a cycle or deadband configuration. Logging settings are not stored inside the HMI tag itself and are not exported via the tag CSV/Excel interchange format, which is why manual editor work cannot be replaced by a spreadsheet find-and-replace operation.

For the official procedure in the WinCC Unified online help, see Configuring multiple logging tags (RT Unified). For the full Openness API contract, see the TIA Portal Openness: Programming and Operating Manual, chapters 5.13.1.8 (LoggingTag properties) and 5.13.1.10 (Creating logging tags).

Prerequisites

Requirement Version Notes
TIA Portal V20 (also valid for V18/V19 with equivalent API) Project must contain a configured HMI device
HMI Runtime WinCC Professional or WinCC Unified Logging Tags feature requires the appropriate HMI license
Microsoft Visual Studio 2019 or 2022 (Community edition or higher) Required for compiling TIA Openness scripts
Siemens TIA Openness SDK Matching the portal version Installed from the TIA Portal installation medium
.NET Framework 4.8 (or .NET 6.0+ for newer SDK builds) Per Openness SDK requirement
Reference Assemblies Siemens.Engineering.dll, Siemens.Engineering.Hmi.dll Located in the TIA Portal PublicAPI folder

Before launching the API script, confirm the following:

  • The target HMI tag exists in the project and is reachable through the tag composition.
  • The HMI device compiles without errors.
  • The TIA Portal project is open and is the only instance running.
  • The data log target (database tag or file-based tag) has already been created on the HMI.
  • The HMI tag's PLC connection is compiled and online-visible (for tags backed by a DB).
Critical: TIA Openness is a stateful COM/.NET interface. Running two TIA Portal instances in parallel, or running a script while the project is being saved, will throw an EngineeringTargetInvocationException. Always run scripts against a single, idle TIA Portal instance.

Understanding the Logging Tag Object Model

A logging tag is not a property of an HMI tag; it is a sibling object that wraps an HMI tag and adds the persistence layer. The object model in TIA Openness is:

Object Namespace Purpose
HmiSoftware Siemens.Engineering.Hmi Entry point for the HMI software container
HmiTagComposition Siemens.Engineering.Hmi.Tag Collection of all HMI tags on the device
HmiTag Siemens.Engineering.Hmi.Tag Single HMI tag instance
HmiLoggingTagComposition Siemens.Engineering.Hmi.Tag LoggingTags property of an HmiTag
HmiLoggingTag Siemens.Engineering.Hmi.Tag Wrapper that holds logging properties
HmiLoggingMode Siemens.Engineering.Hmi.Tag Enum: Cyclic, OnChange, OnCommand

Method 1: Native Bulk Add in the HMI Tag Editor

For projects where all required tags already exist in a single flat table, the fastest approach is the editor shortcut documented in the WinCC Unified online help.

Step-by-step: Native Bulk Add

  1. Open the HMI device in the project tree and select HMI tags.
  2. In the tag table, mark every tag that should be logged. Use Ctrl+A for all visible rows, or Ctrl+Click for non-contiguous selection.
  3. The detail view at the bottom of the editor switches to HMI Tag ParametersLogging Tags tab.
  4. Click the "Add new logging tag to each logable tag" button (pencil-with-plus icon). A logging tag is created for every selected HMI tag simultaneously.
  5. Configure the first row: set Data Log, Logging Mode (Cyclic, On Change, On Command), and Logging Cycle in milliseconds.
  6. Click the small fill handle on the right edge of the configured cell and drag down through the remaining rows. The values replicate across all rows.
  7. Only the Name field must be entered per row because it must be unique within the data log.

Limitations of the Native Method

  • Does not resolve deeply nested tag paths. The selection operates on a single table; arrays of PLC DB members do not appear as separate rows in the HMI tag table.
  • Drag-fill works for individual properties only; mixed configuration profiles require manual grouping.
  • Re-apply is required if tags are added after the initial bulk pass.
  • No undo beyond the standard TIA Portal undo stack; bulk operations may exceed the undo history limit on large selections.

Method 2: TIA Openness API for Nested Tag Arrays

The TIA Openness API exposes the HMI tag composition (HmiTagComposition) and the per-tag logging tag composition (HmiLoggingTagComposition). The pattern documented in the TIA Openness manual (chapters 5.13.1.8 and 5.13.1.10) lets a script generate thousands of logging tags without touching the editor.

Working Visual Basic Code

The following script generates 96 logging tags (4 legs × 3 chords × 8 motors) for the nested path shown in the source example. Each generated logging tag uses a 5-second cyclic interval and is assigned to the ProcessDataLog data log.

Imports System.Text
Imports Siemens.Engineering
Imports Siemens.Engineering.Hmi
Imports Siemens.Engineering.Hmi.Tag

Public Class LoggingTagBulkCreator

    Private Const DATA_LOG_NAME As String = "ProcessDataLog"
    Private Const LOG_CYCLE_MS As Integer = 5000

    ''' <summary>
    ''' Entry point invoked from a TIA Openness host application.
    ''' </summary>
    Public Sub CreateLoggingTags()

        Dim hmiSoftware As HmiSoftware = GetHmiSoftware()
        Dim hmiTags As HmiTagComposition = hmiSoftware.Tags

        For legIndex As Integer = 0 To 3
            For chordIndex As Integer = 0 To 2
                For motorIndex As Integer = 0 To 7

                    Dim tagPath As String = BuildTagPath(legIndex, chordIndex, motorIndex)
                    Dim hmiTag As HmiTag = hmiTags.Find(tagPath)

                    If hmiTag Is Nothing Then
                        Debug.WriteLine("Tag not found, skipped: " & tagPath)
                        Continue For
                    End If

                    Dim loggingName As String = _
                        "Leg " & legIndex & " Chord " & chordIndex & " Motor " & motorIndex & " Speed"

                    Dim loggingTags As HmiLoggingTagComposition = hmiTag.LoggingTags
                    Dim loggingTag As HmiLoggingTag = loggingTags.Create(loggingName)

                    ' Apply logging properties
                    loggingTag.DataLog = DATA_LOG_NAME
                    loggingTag.LoggingMode = HmiLoggingMode.Cyclic
                    loggingTag.LoggingCycle = LOG_CYCLE_MS
                    loggingTag.PersistentName = "L" & legIndex & "C" & chordIndex & "M" & motorIndex & _Speed"

                Next motorIndex
            Next chordIndex
        Next legIndex
    End Sub

    Private Function BuildTagPath(legIdx As Integer, chordIdx As Integer, motorIdx As Integer) As String
        Dim sb As New StringBuilder()
        sb.Append("HMI_ActVal_Platform.Legs[")
        sb.Append(legIdx.ToString())
        sb.Append("].Chords[")
        sb.Append(chordIdx.ToString())
        sb.Append("].Motors[")
        sb.Append(motorIdx.ToString())
        sb.Append("].AnalogValues.ActSpeed")
        Return sb.ToString()
    End Function

    ''' <summary>
    ''' Resolves the first HmiSoftware in the active TIA project.
    ''' Replace with a named lookup if multiple HMIs exist.
    ''' </summary>
    Private Function GetHmiSoftware() As HmiSoftware
        Dim tia As TiaPortal = TiaPortal.GetCurrentProcess()
        Dim project As Project = tia.Projects(0)
        Dim hmiDevice As HmiTarget = Nothing

        For Each device As Device In project.Devices
            If TypeOf device Is HmiTarget Then
                hmiDevice = DirectCast(device, HmiTarget)
                Exit For
            End If
        Next

        If hmiDevice Is Nothing Then
            Throw New InvalidOperationException("No HMI device found in project.")
        End If

        Return DirectCast(hmiDevice.Software, HmiSoftware)
    End Function

End Class

Key API Calls Explained

Call Description
hmiTags.Find(name) Resolves an HmiTag by its fully qualified PLC path. Returns Nothing if the tag does not exist; always null-check before use.
hmiTag.LoggingTags.Create(name) Appends a new logging tag to the tag's logging composition. Name must be unique within the data log.
loggingTag.DataLog String identifier of the target data log. Must match an existing log configured on the HMI.
loggingTag.LoggingMode Enum value: Cyclic, OnChange, or OnCommand.
loggingTag.LoggingCycle Integer in milliseconds. Common values: 1000 (1 s), 2000, 5000 (5 s), 10000.
loggingTag.PersistentName Short, deterministic name used by the SQL-backed runtime log. Persists across tag renames.

Parameter Mapping Table

Editor Column Openness Property Data Type Example
Name HmiLoggingTag.Name String "Leg 0 Chord 1 Motor 2 Speed"
Data Log HmiLoggingTag.DataLog String "ProcessDataLog"
Logging Mode HmiLoggingTag.LoggingMode Enum HmiLoggingMode.Cyclic
Logging Cycle HmiLoggingTag.LoggingCycle Integer (ms) 5000
Persistent Name HmiLoggingTag.PersistentName String "L0C1M2_Speed"

Step-by-step: Deploying the Openness Script

  1. Open Microsoft Visual Studio and create a new Class Library (.NET Framework) project targeting the same .NET version as the TIA Openness API.
  2. Add references to the TIA Openness assemblies located at C:\Program Files\Siemens\Automation\Portal V20\PublicAPI\V20\. Required references:
    • Siemens.Engineering.dll
    • Siemens.Engineering.Hmi.dll
  3. Paste the LoggingTagBulkCreator class into the project and compile to a DLL.
  4. Launch TIA Portal V20 and open the target project.
  5. Execute the compiled DLL using one of the supported hosts:
    • A custom Windows Forms or WPF host application launched externally.
    • The TIA Openness Explorer add-in sample shipped with the SDK.
    • A PowerShell script that loads the DLL and calls the entry method.
  6. Open the HMI tags editor in TIA Portal and verify the logging tags now appear in the Logging Tags tab of the affected tags.
  7. Compile the HMI to push the configuration to the runtime database.

Idempotent Pattern (Find-or-Create)

Running the script twice will throw a duplicate-name exception. Wrap the create call in a find-or-create check:

Public Function FindOrCreateLoggingTag(hmiTag As HmiTag, name As String) As HmiLoggingTag
    Dim existing = hmiTag.LoggingTags.Find(name)
    If existing IsNot Nothing Then
        Return existing
    End If
    Return hmiTag.LoggingTags.Create(name)
End Function

WinCC 7.5 vs TIA Portal V20 Comparison

Feature WinCC 7.5 TIA Portal V20
Bulk-create logging tags in table view Yes (full sheet) Partial (button + drag-fill)
Programmatic creation Limited VBS macro Full TIA Openness API
Drag-fill across rows Yes Yes (per cell)
Exposes LoggingTags collection via API No Yes
Supports deeply nested array paths Manual UDT walk Loop-driven API access
Export logging config as CSV Yes No
Re-apply on project re-open N/A Re-run script
SQL data log backend Optional Default in Unified

Verification

After the script runs, perform the following checks:

  • Count check: The number of generated logging tags should equal the product of the loop bounds (4 × 3 × 8 = 96 in the example).
  • Path check: For a sample tag (HMI_ActVal_Platform.Legs[0].Chords[0].Motors[0].AnalogValues.ActSpeed), the logging tag should be present with the configured name and the ProcessDataLog reference.
  • Cycle check: Open the Properties panel of any generated logging tag and confirm LoggingCycle = 5000 ms.
  • Compile check: Right-click the HMI device → Compile → Software (rebuild all). The compile must complete without warnings about orphaned logging tags.
  • Runtime check: Download to the HMI panel or Runtime PC. In the WinCC Runtime, open the data log viewer and confirm new rows appear every 5 seconds.

Troubleshooting Matrix

Symptom Likely Cause Fix
HmiTag.Find(path) returns null Path string is wrong, or PLC DB is not compiled Use the HMI tag editor to copy the exact qualified name
loggingTags.Create(name) throws Duplicate name within the same data log Append leg/chord/motor indices to the name
LoggingCycle not applied Runtime does not support the value Check HMI panel's minimum logging cycle (often 500 ms or 1000 ms)
Script silently exits TIA Portal not started from matching version Launch the TIA Portal version that matches the Openness DLL
Tags appear but no data logged Data Log not yet created in HMI Create the data log in the HMI editor before running the script
Compiler warning: orphaned logging tag Underlying HMI tag was deleted Re-create the HMI tag or remove the orphan logging tag
PersistentName conflict Two scripts use the same persistent name across log files Namespace the persistent name with the tag path
EngineeringTargetInvocationException Project is being saved or compiled Wait for the project to reach an idle state before re-running

Best Practices

  • Idempotent execution: Wrap the create call in a find-or-create check so re-running the script does not duplicate tags.
  • Versioned scripts: Store the .vb source in version control. TIA project files are binary blobs and cannot be diffed.
  • Pre-validate HMI tag paths: Build a list of expected paths from the PLC DB structure first, then iterate. This surfaces PLC/HMI mismatch before the API call fails.
  • Use PersistentName: A short, deterministic persistent name survives tag renaming and is required for SQL-based data log queries.
  • Limit the runtime cycle: 5 s is acceptable for slow process data; for high-speed acquisition use 1000 ms or move the data acquisition to the PLC and log on change.
  • Use OnChange for event data: Cyclic logging at 1 s for thousands of tags can saturate the storage backend; switch to OnChange with a small deadband for setpoint-style data.

Notes on WinCC Unified

WinCC Unified follows the same HmiTag / HmiLoggingTag model. The Siemens online help for V20 (URL: Configuring multiple logging tags (RT Unified)) covers the editor bulk-add flow. The Openness API is shared between Professional and Unified with the same method signatures, so the Visual Basic code in this article is portable across both runtimes without modification.

Why is the logging configuration not exported when I export HMI tags to Excel?

HMI tag export only includes the tag properties (name, PLC path, data type, access method). Logging configuration lives in a separate composition (HmiLoggingTagComposition) and is stored in the HMI's logging database, not in the tag interchange file. This is why a spreadsheet find-and-replace cannot be used to modify logging properties.

Can I use the Openness API to modify the Logging Cycle of an existing logging tag?

Yes. Call hmiTag.LoggingTags.Find(name) to retrieve the existing HmiLoggingTag, then set LoggingCycle, LoggingMode, or DataLog directly. Changes are committed to the project on the next compile.

What is the minimum Logging Cycle supported on a WinCC Unified panel?

The minimum cycle depends on the panel class. Comfort Panels typically support 500 ms; Unified Comfort Panels support 100 ms. Below the panel's minimum, the runtime clamps the value and logs a warning in the diagnostic view.

How do I delete logging tags in bulk?

Iterate the LoggingTags composition and call loggingTag.Delete() for each entry. There is no built-in bulk delete in the editor; Openness is the only practical path for cleanup of hundreds of tags.

Does the script need to run on the engineering station with TIA Portal installed?

Yes. The TIA Openness API is a COM/.NET interface that requires a running TIA Portal instance on the same machine. It cannot be executed from a remote workstation without the TIA Portal installation.

Back to blog