VBA Code
VBA Code
Counter = Counter + 1
ReDim Preserve VarsToFind(Counter) As String
VarsToFind(Counter) = TextLine
End If
Wend
Source.Close
For Each File In Folder.Files
If Not Left(File.Name, 1) = "@" And LCase(Right(File.Name, 4)) = ".pdl"
Then
Set Doc = grafexe.Documents.Open(File.Path)
For Each Obj In Doc.HMIObjects
For Each Prop In Obj.Properties
If Prop.DynamicStateType = hmiDynamicStateTypeVariableDirect
Then
VarName = Prop.Dynamic.VarName
For Counter = 1 To UBound(VarsToFind)
If VarsToFind(Counter) = VarName Then
TS.WriteLine File.Name & "," & Obj.ObjectName &
"," & Prop.Name & "," & VarName
End If
Next
End If
Next
Next
Doc.Close
End If
Next
TS.Close
End Sub
Sub ReplaceTag()
Dim FSO As New FileSystemObject
Dim Folder As Folder
Dim File As File
Dim Doc As Document
Dim Obj As HMIObject
Dim Prop As HMIProperty
Dim VarName As String
Dim VarToFind As String
Dim TS As TextStream
Dim Source As TextStream
Dim VarsToFind() As String
Dim ReplaceWith() As String
Set Source = FSO.OpenTextFile("D:\TagsToReplace.txt", ForReading, True)
Set Folder = FSO.GetFolder(grafexe.ApplicationDataPath)
Set TS = FSO.OpenTextFile("D:\TagsReplaced.csv", ForWriting, True)
Counter = 0
While Not Source.AtEndOfStream
TextLine = Source.ReadLine
If Len(TextLine) > 0 Then
Counter = Counter + 1
ReDim Preserve VarsToFind(Counter) As String
ReDim Preserve ReplaceWith(Counter) As String
VarsToFind(Counter) = Split(TextLine, ",")(0)
ReplaceWith(Counter) = Split(TextLine, ",")(1)
End If
Wend
Source.Close
For Each File In Folder.Files
If Not Left(File.Name, 1) = "@" And LCase(Right(File.Name, 4)) = ".pdl"
Then
Set Doc = grafexe.Documents.Open(File.Path)
DocChanged = False
For Each Obj In Doc.HMIObjects
For Each Prop In Obj.Properties
If Prop.DynamicStateType = hmiDynamicStateTypeVariableDirect
Then
VarName = Prop.Dynamic.VarName
For Counter = 1 To UBound(VarsToFind)
If VarsToFind(Counter) = VarName Then
Prop.Dynamic.VarName = ReplaceWith(Counter)
DocChanged = True
TS.WriteLine File.Name & "," & Obj.ObjectName &
"," & Prop.Name & "," & VarName & " replaced with " & ReplaceWith(Counter)
End If
Next
End If
Next
Next
If DocChanged Then
Doc.Save
End If
Doc.Close
End If
Next
TS.Close
End Sub
Sub FindText()
Dim FSO As New FileSystemObject
Dim Folder As Folder
Dim File As File
Dim Doc As Document
Dim Obj As HMIObject
Dim Prop As HMIProperty
Dim TextToFind As String
Set Folder = FSO.GetFolder(grafexe.ApplicationDataPath)
TextToFind = "gain"
For Each File In Folder.Files
If Not Left(File.Name, 1) = "@" And LCase(Right(File.Name, 4)) = ".pdl"
Then
Set Doc = grafexe.Documents.Open(File.Path)
For Each Obj In Doc.HMIObjects
If Not Obj.Type = "HMIActiveXControl" Then
For Each Prop In Obj.Properties
If InStr(1, LCase(Prop.value), LCase(TextToFind)) > 0 Th
en
Obj.Selected = True
Obj.Selected = False
End If
Next
End If
Next
Doc.Close
End If
Next
End Sub
Sub PrintScreens()
Dim FSO As New FileSystemObject
Dim Folder As Folder
Dim File As File
Dim Doc As Document
Dim Obj As HMIObject
Dim objView As HMIView
Dim TS As TextStream
Dim colSearchResults As HMICollection
Dim objStaticText As HMIStaticText
Set Folder = FSO.GetFolder(grafexe.ApplicationDataPath)
Set TS = FSO.OpenTextFile("D:\SMR Graphics List.txt", ForWriting, True)
For Each File In Folder.Files
If Not Left(File.Name, 1) = "@" And LCase(Right(File.Name, 4)) = ".pdl"
Then
Set Doc = grafexe.Documents.Open(File.Path)
TS.WriteLine Doc.Name
'Doc.Width = 1280
'Doc.Height = 845
Set colSearchResults = ActiveDocument.HMIObjects.Find(ObjectType:="H
MIRectangle")
For Each Obj In colSearchResults
If Obj.Properties("BackColor") = RGB(0, 0, 0) Then
Obj.Delete
End If
Next
Set colSearchResults = ActiveDocument.HMIObjects.Find(ObjectType:="H
MIButton")
For Each Obj In colSearchResults
If Obj.Properties("Text") = "Close" Then
Obj.Delete
End If
Next
Set colSearchResults = ActiveDocument.HMIObjects.Find(ObjectType:="H
MIStaticText")
For Each Obj In colSearchResults
If Obj.Properties("ForeColor") = RGB(255, 191, 255) Then
Obj.Properties("ForeColor") = RGB(255, 255, 255)
End If
Next
Set objStaticText = ActiveDocument.HMIObjects.AddHMIObject("Static_T
ext1", "HMIStaticText")
With objStaticText
.Text = "Close"
.AdaptBorder = False
.Height = 30
.Width = 159
.Top = 723
.Left = 684