How-to
How WinCC Runtime Color Selection Reaches a VBScript
Short answer
No WinCC basic or Comfort panel ships a runtime color-picker control, but the operator does not need one. Configure each palette swatch as a screen object whose press event writes an assigned identifier to an internal HMI tag, and have the VBScript read that tag and resolve it to the destination color value.
On this page
A WinCC runtime color selection reaches a VBScript only as a tag value. No WinCC Flexible 2008 target and no WinCC Advanced basic or Comfort panel provides a runtime color-picker control that hands the operator's pick to a script, so you build the palette from ordinary screen objects: each swatch writes an assigned identifier to an internal HMI tag on press, and the script reads that tag. The script consumes the value, never the pixel color. This works on both of the tools you already have, because both support press events on screen objects, internal tags, and VBScript on the configured target.
Decide the selection contract first #
Before you configure anything, write down four things: the fixed list of approved colors, the identifier each swatch writes, the destination object and property the script must change, and what the screen shows after a runtime restart. A fixed palette is the practical choice for an operator station; arbitrary free color selection would need a custom interface with a documented result value, and neither generation of the tools you named gives you that control out of the box.
If the selection only drives the panel's own screen, keep it in an internal tag and nothing crosses the bus. If the controller or a second station needs the selection, map the same identifier to a controller tag and write it on selection as well.
Build the palette screen #
- Add an internal HMI tag, for example one named
SelectedColorof type Int, with a start value of 1 that matches your default color. - Draw one screen object per approved color and fill it with that color in the engineering view. Four swatches is a typical application palette.
- On each swatch, configure the press event to write its assigned identifier to
SelectedColor: the first swatch writes 1, the second writes 2, and so on. Use the direct-value form of the tag write in the event, not a script, so the assignment exists even if the script later errors. - Add a text field that displays
SelectedColorwhile you commission, so you can watch the selection move without opening a watch table. - Add a preview rectangle that the script will color, next to the palette.
Connect and test the script #
Trigger the script from an event that fires after the write completes, and have it read the tag, validate the identifier, and apply the resolved color to the preview object through its documented color property or an appearance animation. Keep the identifier-to-color mapping in one place in the script.
The following worked example uses the documented SmartTags access for HMI tags and an illustrative four-color mapping; check the installed help for the exact property names of your configured target, because the destination property name belongs to that target's interface, not to this example.
Dim sel
sel = SmartTags("SelectedColor") ' Int tag written by the swatch press
Select Case sel
Case 1
SmartTags("PreviewColor") = &H0000FF ' example: red in the panel's packed RGB form
Case 2
SmartTags("PreviewColor") = &H00FF00 ' example: green
Case 3
SmartTags("PreviewColor") = &HFF0000 ' example: blue
Case 4
SmartTags("PreviewColor") = &HFFFF00 ' example: yellow
Case Else
SmartTags("PreviewColor") = &HAAAAAA ' explicit gray for an invalid selection
End Select
To verify it, put the tag write and the script on the bench before the panel goes on the machine. Press each swatch in turn and read the numeric display: after pressing the third swatch, SelectedColor shows 3 and the preview resolves to the third entry, which in the example above is the blue value. When SelectedColor holds 9, which no swatch writes, the preview shows the explicit gray, proving the Case Else branch works. If a value reaches the tag but the script produces nothing, trigger a trivial script-visible result first and check the runtime diagnostics for a script error; the same isolation logic applies here as in diagnosing whether it is the driver, the tag or the screen behind an HMI value.
Separate the three failures #
Every symptom in this design falls into one of three boundaries, and mixing them wastes hours.
- Interface failure. The swatch highlights but the tag stays at its start value. The press event or the direct tag write is misconfigured.
- Transfer failure. The tag changes but the destination object does not. The script trigger, the property access, or the event ordering is wrong; the numeric display field from step 4 separates this from the first case in one press.
- Mapping failure. The object changes to the wrong color. The assigned identifier and the resolved value disagree; compare them against the mapping in the script.
A result that appears in offline simulation but not on the panel is a target-capability difference, not a script bug. Repeat the acceptance sequence on the configured hardware and treat only that run as the passing test.
Keep design styles and operator colors apart #
The HMI Template Suite coordinates appearance across a project, including central color changes for screens and elements, and it is worth adopting for a consistent design. It is an engineering-time appearance framework, not an operator-facing runtime picker, and using it does not by itself give a script a readable selection. Keep alarm, warning and operating-state colors fixed by the design so that a operator-customizable palette can never recolor them, and let the swatch palette write only to the tags the mapping consumes.
If the upgrade also replaces the panel itself, the same tag-driven palette works unchanged on any target that supports press events, internal tags and VBScript, including a PC-based runtime on an industrial panel PC, so the selection design does not have to be redone when the hardware moves.
Questions asked
Do WinCC Comfort panels have a color picker control I can drop on a screen?
No basic or Comfort panel runtime ships a color-picker control that the operator can open at runtime and that hands the chosen color to a script. The documented route is application-built: selectable screen objects whose press events write assigned identifiers to an internal tag. WinCC Unified treats a color palette as a project-library type, which is a different generation of runtime with its own interface and is not a drop-in answer on Comfort hardware.
Why does my swatch highlight but the script never sees the selection?
The highlight proves only that the screen object reacted. Check three things in order: the press event actually carries the tag write with the assigned value, the tag is the internal tag the script reads, and the script is triggered by an event that fires after the write completes. If the tag value changes in a watch table but the object color stays, the write path is fine and the problem is in how the script applies the resolved color.
Can the operator's color choice survive a runtime restart?
Only if you make it persist. An internal tag returns to its configured start value when the runtime restarts, so set that start value to the default color identifier and tell the operator that the selection resets, or write the identifier to a controller tag you have set up as retentive and read it back at startup. Keep the mapping table in the script identical either way.
Should the color identifier go to the PLC as well?
Decide by who consumes the selection. If only the panel screen uses the color, an internal HMI tag is enough and nothing crosses the bus. If a batch record, a second panel or the controller logic needs to know the chosen category, map the identifier to a controller tag of a documented matching type and write it on selection, so the two sides cannot drift apart.