FAQ 11/2014
Changing the Color and
Transparency of HMI
Elements during Runtime
SIMATIC WINCC V7.0 to V7.3
http://support.automation.siemens.com/WW/view/en/33912016
This entry originates from the Siemens Industry Online Support. The conditions of
use specified there apply http://www.siemens.com/terms_of_use).
Security
Notes
Siemens offers products and solutions with industrial security functions which
support the secure operation of plants, solutions, machines, devices and/or
networks. They are important components in a comprehensive industrial security
concept. The Siemens products and solutions continue to be developed under
this aspect. Siemens recommends that you keep yourself regularly informed
about product updates.
For the safe operation of Siemens products and solutions it is necessary to take
appropriate security measures (cell protection concept, for example) and to
integrate each component in an overall industrial security concept which is state
of the art. This should also cover the third-party products used. Additional
information about industrial security is available at:
http://www.siemens.com/industrialsecurity.
Siemens AG 2014 All rights reserved
In order to keep yourself informed about product updates, we recommend
subscribing to our product-specific newsletter. Additional information about this is
available at: http://support.automation.siemens.com.
Contents
1
Color Display in WinCC.................................................................................. 3
Requirements ................................................................................................. 4
2.1
2.2
Disable Global Color Scheme ............................................................ 4
Change the WinCC Style ................................................................... 4
Implementation ............................................................................................... 5
3.1
3.1.1
3.1.2
3.2
3.2.1
3.2.2
Configure Using C Scripts.................................................................. 5
Assign Colors from a Central Color Palette ........................................ 6
Specify Colors with Numerical Values .............................................. 11
Configure Using C Scripts................................................................ 12
Assign Colors from a Central Color Palette ...................................... 13
Specify Colors with Numerical Values .............................................. 17
Color change with WinCC RT
Entry ID: 33912016,
V1.0,
11/2014
1 Color Display in WinCC
Color Display in WinCC
In WinCC 7.0 and higher the colors consist of 32-bit values. Transparency of the
colors is possible. This is achieved by influencing the alpha channel.
In the active WinCC Runtime you can change the colors of objects if this has been
configured beforehand. Object components which can be changed are, for
example, background color, frame color and text color.
Siemens AG 2014 All rights reserved
Below we present two options for changing the color of objects using scripts.
Assign colors from a central color palette
WinCC 7.0 and higher enables you to create your own color palette in addition
to the default style colors. You can create 10 color palettes of 20 colors each
specifically for a project.
Scripts are used to access the colors in the color palette and assign the object
color (text color, for example).
This procedure is suitable for frequent use of colors and if the color is to be
changeable centrally, in other words, after changing a color in the palette, the
object color (text color, for instance) assigned to that palette color changes too.
Specify colors with numerical values
WinCC 7.0 and higher enables you to use scripts to create a color value and
then assign that color value to an object color (text color, for example).
This procedure is suitable for when color is seldom used and changes to the
style colors or color palette are not to influence the colors created.
The scripts used here are available at the relevant point in the description and in
the .txt file available for downloading on the entry page.
Color change with WinCC RT
Entry ID: 33912016,
V1.0,
11/2014
2 Requirements
Requirements
2.1
Disable Global Color Scheme
In order to change the colors of an object, the "Central color scheme" property
must be disabled. You can set this property in the Graphics Designer.
Table 2-1
No.
2.2
Procedure
1.
Open the Graphics Designer.
2.
Right-click the relevant project and click "Properties".
3.
Click the "Properties" tab, then "Button" and finally "Display".
4.
In the detail window you can change the property from "yes" to "no" with a
double-click in the "Static" column next to the attribute.
Change the WinCC Style
If the "WinCC style" attribute is available in the object, then you must also change
the "WinCC style" attribute.
Siemens AG 2014 All rights reserved
Table 2-2
No.
Procedure
1.
Open the Graphics Designer.
2.
Right-click the relevant project and click "Properties".
3.
Click the "Properties" tab, then "Button" and finally "Display".
4.
In the detail window you change the property with a double-click in the "Static"
column next to the attribute.
5.
In the selection field that opens you selected "User-defined".
Color change with WinCC RT
Entry ID: 33912016,
V1.0,
11/2014
3 Implementation
Implementation
Below we present a solution for the script languages C and Visual Basic Script
(VBS) for each of the versions named.
3.1
Configure Using C Scripts
In the example below the background color of a WinCC screen is changed during
Runtime by clicking a button.
The C scripts used in this example are available at the relevant point in the
description.
You can also use the scripts other than with the example.
Siemens AG 2014 All rights reserved
Additional information about programming with C in WinCC is available in the
manual here ("ANSI-C for Creating Functions") and here ("ANSI-C Function
Descriptions").
The manual also includes other color-independent properties of objects which can
be changed during Runtime. Furthermore there is also an extensive list of other
script examples.
Color change with WinCC RT
Entry ID: 33912016,
V1.0,
11/2014
3 Implementation
3.1.1
Assign Colors from a Central Color Palette
Create and fill a project-specific color palette
Table 3-1
No.
Procedure
In the WinCC Explorer you right-click the project name in the tree view and then
click "Properties" to open the Project Properties.
2.
Select the "User Interface and Design" tab.
Click "Edit" next to "Central Color Palette".
Siemens AG 2014 All rights reserved
1.
Color change with WinCC RT
Entry ID: 33912016,
V1.0,
11/2014
3 Implementation
No.
Click the "Add color palette" button (1) and then the "Rename color palette"
button (2).
Siemens AG 2014 All rights reserved
3.
Procedure
4.
Enter a name for the project palette (New Colors, for example).
Color change with WinCC RT
Entry ID: 33912016,
V1.0,
11/2014
3 Implementation
No.
5.
Procedure
Set the slider controls (Transparency, Red, Green and Blue) to the colors
required (1), or enter the RGB values and transparency in the relevant input
fields (2).
Click the "To Palette" button (3) and then the number in the color palette (4).
Siemens AG 2014 All rights reserved
6.
Confirm both dialog boxes with "OK".
Color change with WinCC RT
Entry ID: 33912016,
V1.0,
11/2014
3 Implementation
Add a global C script
Table 3-2
No.
Procedure
1.
In the WinCC Explorer you right-click "Global Script" in the tree view and then
click "Open C Editor".
2.
In the menu bar you click "File" > "Create New Project Function" and replace the
function template with the following C script (C script 1a):
Siemens AG 2014 All rights reserved
long GetPaletteColor(int ColorIndex)
{
if (ColorIndex > 199)
ColorIndex = 199;
return pow(2,31) + ColorIndex;
}
3.
Click "File" > "Save", enter a name and confirm with "OK".
4.
Confirm the settings with "Yes" and close the C editor.
Create trigger for color change and assign a color
Table 3-3
No.
Procedure
1.
In the WinCC Explorer you click "Graphics Designer" in the tree view and doubleclick your project picture to open it.
2.
Add a button to the picture from the object palette by selecting "Standard" >
"Windows Objects" > "Button".
3.
Right-click the inserted button and then click "Properties". The Properties dialog
opens.
4.
Select the "Event" tab and click "Button" > "Mouse".
5.
Right-click in the "Action" column in the "Mouse click" line and then click "C
action...".
6.
Replace the commented-out (green) lines with the following C script
(C script 1b):
SetBackColor(lpszPictureName, "Testobject", GetPaletteColor(4));
Color change with WinCC RT
Entry ID: 33912016,
V1.0,
11/2014
3 Implementation
No.
7.
Procedure
Replace the name "Testobject" (1) with the name of the object whose
background is to be changed.
Replace the number 4 with the new background color from the projectspecific color palette (2 in the example)(2).
The value corresponds to the associated number of the color in the color
palette.
Siemens AG 2014 All rights reserved
8.
Note
Confirm the dialog with "OK", close the Properties dialog and close the picture.
If you do not use a button, the script must be called from Table 3-3, No.6.
Color change with WinCC RT
Entry ID: 33912016,
V1.0,
11/2014
10
3 Implementation
3.1.2
Specify Colors with Numerical Values
Add a global C script
Table 3-4
No.
Procedure
1.
In the WinCC Explorer you right-click "Global Script" in the tree view and then
click "Open C Editor".
2.
In the menu bar you click "File" > "Create New Project Function" and replace the
function template with the following C script (C script 2a):
long CreateRGBColor32(int nRed, int nGreen, int nBlue, ...)
{
va_list argptr;
int Alpha;
long Color;
va_start (argptr, nBlue);
Siemens AG 2014 All rights reserved
if (argptr != NULL)
Alpha = va_arg(argptr, int);
else
Alpha = 0;
va_end(argptr);
Color = nRed + (pow(2, 8)) * nGreen + (pow(2, 16)) * nBlue + (pow(2, 24))
* (Alpha + 1);
return Color;
}
3.
Click "File" > "Save", enter a name and confirm with "OK".
Create trigger for color change and assign a color
Table 3-5
No.
Procedure
1.
In the WinCC Explorer you click "Graphics Designer" in the tree view and doubleclick your project picture to open it.
2.
Add a button to the picture from the object palette by selecting "Standard" >
"Windows Objects" > "Button".
3.
Right-click the inserted button and then click "Properties". The "Properties" dialog
opens.
Color change with WinCC RT
Entry ID: 33912016,
V1.0,
11/2014
11
3 Implementation
No.
Procedure
4.
Select the "Event" tab and click "Button" > "Mouse".
5.
Right-click in the "Action" column in the "Mouse click" line and then click "C
action...".
6.
Replace the commented-out (green) lines with the following C script
(C script 2b):
SetBackColor(lpszPictureName, "Testobject", CreateRGBColor32(255, 60,
100, 30));
7.
Siemens AG 2014 All rights reserved
Replace the name "Testobject" (1) with the name of the object whose
background is to be changed.
Replace the values 255, 60, 100, 30 with the RGB values and transparency
of the color required. (2)
The order is the following: red, green, blue, transparency.
8.
Note
3.2
Confirm the dialog with "OK", close the Properties dialog and close the picture.
If you do not use a button, the script must be called from Table 3-5, No.6.
Configure Using C Scripts
In the example below the background color of a WinCC screen is changed during
Runtime by clicking a button.
The C scripts used in this example are available at the relevant point in the
description.
You can also use the scripts other than with the example.
Additional information about programming with C in WinCC is available in the
manual here ("VBS for Creating Functions") and here ("VBS Reference").
The manual also includes other color-independent properties of objects which can
be changed during Runtime. Furthermore there is also an extensive list of other
script examples.
Color change with WinCC RT
Entry ID: 33912016,
V1.0,
11/2014
12
3 Implementation
3.2.1
Assign Colors from a Central Color Palette
Create and fill a project-specific color palette
Table 3-6
No.
Procedure
In the WinCC Explorer you right-click the project name in the tree view and then
click "Properties" to open the Project Properties.
2.
Select the "User Interface and Design" tab.
Click "Edit" next to "Central Color Palette".
Siemens AG 2014 All rights reserved
1.
Color change with WinCC RT
Entry ID: 33912016,
V1.0,
11/2014
13
3 Implementation
No.
Click the "Add color palette" button (1) and then the "Rename color palette"
button (2).
Siemens AG 2014 All rights reserved
3.
Procedure
4.
Enter a name for the project palette (New Colors, for example).
Color change with WinCC RT
Entry ID: 33912016,
V1.0,
11/2014
14
3 Implementation
No.
5.
Procedure
Set the slider controls (Transparency, Red, Green and Blue) to the colors
required (1), or enter the RGB values and transparency in the relevant input
fields (2).
Click the "To Palette" button (3) and then the number in the color palette (4).
Siemens AG 2014 All rights reserved
6.
Click the "To Palette" button and then the number in the color palette (2, for
example).
7.
Confirm both dialog boxes with "OK".
Color change with WinCC RT
Entry ID: 33912016,
V1.0,
11/2014
15
3 Implementation
Create trigger for color change and assign a color
Table 3-7
No.
Procedure
1.
In the WinCC Explorer you click "Graphics Designer" in the tree view and doubleclick your project picture to open it.
2.
Add a button to the picture from the object palette by selecting "Standard" >
"Windows Objects" > "Button".
3.
Right-click the inserted button and then click "Properties". The Properties dialog
opens.
4.
Select the "Event" tab and click "Button" > "Mouse".
5.
Right-click in the "Action" column in the "Mouse click" line and then click "VBS
action...".
Replace the commented-out (green) lines with the following VB script
(VB script 1):
6.
Dim ColorIndex
ColorIndex=4
ScreenItems(Testobject).BackColor=-2147483648+ColorIndex
Siemens AG 2014 All rights reserved
Replace the name "Testobject" (1) with the name of the object whose
background is to be changed.
Replace the number 4 with the new background number from the projectspecific color palette (12 in the example)(2).
The "ColorIndex" variable corresponds exactly to the number of the color in
the color palette.
7.
Note
Confirm the dialog with "OK", close the Properties dialog and close the picture.
If you do not use a button, the script must be called from Table 3-7, No.6.
Color change with WinCC RT
Entry ID: 33912016,
V1.0,
11/2014
16
3 Implementation
3.2.2
Specify Colors with Numerical Values
Create trigger for color change and assign a color
Table 3-8
No.
Procedure
1.
In the WinCC Explorer you click "Graphics Designer" in the tree view and doubleclick your project picture to open it.
2.
Add a button to the picture from the object palette by selecting "Standard" >
"Windows Objects" > "Button".
3.
Right-click the inserted object and then click "Properties". The "Properties" dialog
opens.
4.
Select the "Event" tab and click "Button" > "Mouse".
5.
Right-click in the "Action" column in the "Mouse click" line and then click "VBS
action...".
Replace the commented-out (green) lines with the following VB script
(VB script 2):
6.
Siemens AG 2014 All rights reserved
ScreenItems(Testobject).BackColor=RGB(70,60,100)
ScreenItems(Testobject).Transparency=50
7.
Replace the name "Testobject" (1) with the name of the object whose
background is to be changed.
Replace the values 255, 60, 100, 30 with the RGB values and transparency
of the color required. (2)
The order is the following: 1st line: red, green, blue; 2nd line: transparency.
Note
To obtain the color code of the desired color you can use the slider controls to
set the color in the color palette. The associated color code is given under the
slider controls in the "HTML code" output field. The color code is set in the
"RRGGBB" order (red, green blue) and be applied as such. You do not have to
store the new color in the palette.
8.
Note
Confirm the dialog with "OK", close the Properties dialog and close the picture.
If you do not use a button, the script must be called from Table 3-8, No.6.
Color change with WinCC RT
Entry ID: 33912016,
V1.0,
11/2014
17