login about faq

Could a script be used to find and replace screen tags with Siemens Win CC?

asked Dec 09 '09 at 02:15

DaveM's gravatar image

DaveM
60618


Use this script when: You have screen A and tags: XXXX_A are assigned to objects on this screen. You want to copy this screen and call it screen B, and assign tags XXX_B to objects on screen B. The properties of the objects that this script will access are listed below.

Objects and Properties:
- StaticTexts: Dynamic Dialog and Background Color
- IOFields: Output and Background Color
- Rectangles: Background Color
- Polygon: Background Color and Flashing
- Buttons: background Color
- Bars: Process Value
This script extracts the existing tag and replaces it with the new tag.

Sub TEST()



Dim Index As String

Dim Str As String



Index = "_10"



'Change StaticTexts Tag for Dynamic Dialog and Background Color

Dim objStaticText As HMIStaticText

Dim colSearchResults As HMICollection

Dim objMember As HMIObject

Dim iResult As Integer

Dim StrName As String



Set colSearchResults = ActiveDocument.HMIObjects.Find(ObjectType:="HMIStaticText")



For Each objMember In colSearchResults

    iResult = colSearchResults.Count

    StrName = objMember.ObjectName

    Set objStaticText = ActiveDocument.HMIObjects(StrName)

        If objStaticText.BackColor.DynamicStateType = hmiDynamicStateTypeDynamicDialog Then

            Str = objStaticText.BackColor.Dynamic.SourceCode

            Str = Left(Str, Len(Str) - 1)

            Str = Str + Index

            Str = Str + "'"

            objStaticText.BackColor.Dynamic.SourceCode = Str

        End If



        If objStaticText.Text.DynamicStateType = hmiDynamicStateTypeDynamicDialog Then

            Str = objStaticText.Text.Dynamic.SourceCode

            Str = Left(Str, Len(Str) - 1)

            Str = Str + Index

            Str = Str + "'"

            objStaticText.Text.Dynamic.SourceCode = Str

        End If



Next objMember



' Change IOFields Tag for Output and Background Color

Dim objIOField As HMIIOField

Dim IOcolSearchResults As HMICollection

Dim IOobjMember As HMIObject

Dim IOiResult As Integer

Dim IOStrName As String



Set IOcolSearchResults = ActiveDocument.HMIObjects.Find(ObjectType:="HMIIOField")



For Each IOobjMember In IOcolSearchResults

    IOiResult = IOcolSearchResults.Count

    IOStrName = IOobjMember.ObjectName

    Set objIOField = ActiveDocument.HMIObjects(IOStrName)

        If objIOField.BackColor.DynamicStateType = hmiDynamicStateTypeDynamicDialog Then

            Str = objIOField.BackColor.Dynamic.SourceCode

            Str = Left(Str, Len(Str) - 1)

            Str = Str + Index

            Str = Str + "'"

            objIOField.BackColor.Dynamic.SourceCode = Str

        End If



        If objIOField.OutputValue.DynamicStateType = 1 Then

            Str = objIOField.OutputValue.Dynamic.VarName

            Str = Str + Index

            objIOField.OutputValue.Dynamic.VarName = Str

        End If

Next IOobjMember



' Change Boxes Tag for Background Color

Dim objRectangle As HMIRectangle

Dim ReccolSearchResults As HMICollection

Dim RecobjMember As HMIObject

Dim ReciResult As Integer

Dim RecStrName As String



Set ReccolSearchResults = ActiveDocument.HMIObjects.Find(ObjectType:="HMIRectangle")



For Each RecobjMember In ReccolSearchResults

    ReciResult = ReccolSearchResults.Count

    RecStrName = RecobjMember.ObjectName

    Set objRectangle = ActiveDocument.HMIObjects(RecStrName)

        If objRectangle.BackColor.DynamicStateType = hmiDynamicStateTypeDynamicDialog Then

            Str = objRectangle.BackColor.Dynamic.SourceCode

            Str = Left(Str, Len(Str) - 1)

            Str = Str + Index

            Str = Str + "'"

            objRectangle.BackColor.Dynamic.SourceCode = Str

        End If

Next RecobjMember



' Change Polygon Tag for Background Color and Flashing

Dim objPoly As HMIPolygon

Dim PolycolSearchResults As HMICollection

Dim PolyobjMember As HMIObject

Dim PolyiResult As Integer

Dim PolyStrName As String



Set PolycolSearchResults = ActiveDocument.HMIObjects.Find(ObjectType:="HMIPolygon")



For Each PolyobjMember In PolycolSearchResults

    PolyiResult = PolycolSearchResults.Count

    PolyStrName = PolyobjMember.ObjectName

    Set objPoly = ActiveDocument.HMIObjects(PolyStrName)

        If objPoly.BackColor.DynamicStateType = hmiDynamicStateTypeDynamicDialog Then

            Str = objPoly.BackColor.Dynamic.SourceCode

            Str = Left(Str, Len(Str) - 1)

            Str = Str + Index

            Str = Str + "'"

            objPoly.BackColor.Dynamic.SourceCode = Str

        End If



        If objPoly.FlashBackColor.DynamicStateType = hmiDynamicStateTypeDynamicDialog Then

            Str = objPoly.FlashBackColor.Dynamic.SourceCode

            Str = Left(Str, Len(Str) - 1)

            Str = Str + Index

            Str = Str + "'"

            objPoly.FlashBackColor.Dynamic.SourceCode = Str

        End If

Next PolyobjMember



' Change Buttons Tag for Background Color

Dim objBtn As HMIButton

Dim BtncolSearchResults As HMICollection

Dim BtnobjMember As HMIObject

Dim BtniResult As Integer

Dim BtnStrName As String



Set BtncolSearchResults = ActiveDocument.HMIObjects.Find(ObjectType:="HMIButton")



For Each BtnobjMember In BtncolSearchResults

    BtniResult = BtncolSearchResults.Count

    BtnStrName = BtnobjMember.ObjectName

    Set objBtn = ActiveDocument.HMIObjects(BtnStrName)

        If objBtn.BackColor.DynamicStateType = hmiDynamicStateTypeDynamicDialog Then

            Str = objBtn.BackColor.Dynamic.SourceCode

            Str = objBtn.BackColor.Dynamic.SourceCode

            Str = Left(Str, Len(Str) - 1)

            Str = Str + Index

            Str = Str + "'"

            objBtn.BackColor.Dynamic.SourceCode = Str

        End If

Next BtnobjMember



'Change Bars Tag for Process Value

Dim objBar As HMIBarGraph

Dim BarcolSearchResults As HMICollection

Dim BarobjMember As HMIObject

Dim BariResult As Integer

Dim BarStrName As String



Set BarcolSearchResults = ActiveDocument.HMIObjects.Find(ObjectType:="HMIBargraph")



For Each BarobjMember In BarcolSearchResults

    BariResult = BarcolSearchResults.Count

    BarStrName = BarobjMember.ObjectName

    Set objBar = ActiveDocument.HMIObjects(BarStrName)

        If objBar.Process.DynamicStateType = 1 Then

            Str = objBar.Process.Dynamic.VarName

            Str = Str + Index

            objBar.Process.Dynamic.VarName = Str

        End If

Next BarobjMember



End Sub
link

answered Dec 09 '09 at 02:19

Dave%20Riehl's gravatar image

Dave Riehl
11219

edited Dec 09 '09 at 02:32

Loks good. Thanks for the work on this.

(Dec 09 '09 at 02:42) DaveM
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×10
×1

Asked: Dec 09 '09 at 02:15

Seen: 1,291 times

Last updated: Dec 09 '09 at 02:32