Change Note Text Example (VBA)
This example shows how to change the note on
a drawing template by opening the template for editing and then selecting
the note and using the INote::SetText method to modify the note.
'--------------------------------------------------
Option Explicit
Const NumStrings As Long = 3
Dim GermanString(NumStrings) As
String
Dim EnglishString(NumStrings) As
String
Private Sub InitStrings()
'
German strings, copied and pasted from SOLIDWORKS drawing
GermanString(0)
= "ERROR!:SW-Blattmaßstab"
GermanString(1)
= "ERROR!:SW-Aktuelles Blatt"
GermanString(2)
= "ERROR!:SW-Gesamtzahl der Blätter"
'
equivalent English strings, copied and pasted from SOLIDWORKS drawing
EnglishString(0)
= "$PRP:" + Chr(34) + "SW-Sheet Scale" + Chr(34)
EnglishString(1)
= "$PRP:" + Chr(34) + "SW-Total Sheets" + Chr(34)
EnglishString(2)
= "$PRP:" + Chr(34) + "SW-Current Sheet" + Chr(34)
End Sub
Private Sub DoReplaceString(ByRef sNoteText As String)
Dim
i As
Long
For
i = 0 To NumStrings
sNoteText
= Replace(sNoteText, GermanString(i), EnglishString(i), 1, -1, vbTextCompare)
Next
i
End Sub
Sub main()
Dim
swApp As
SldWorks.SldWorks
Dim
swModel As
SldWorks.ModelDoc
Dim
swDraw As
SldWorks.DrawingDoc
Dim
swView As
SldWorks.view
Dim
swNote As
SldWorks.note
Dim
sNoteText As
String
Dim
nTextCount As
Long
Dim
i As
Long
InitStrings
Set
swApp = CreateObject("SldWorks.Application")
Set
swModel = swApp.ActiveDoc
Set
swDraw = swModel
Set
swView = swDraw.GetFirstView
While
Not swView Is Nothing
Set
swNote = swView.GetFirstNote
While
Not swNote Is Nothing
If
swNote.IsCompoundNote Then
nTextCount
= swNote.GetTextCount
For
i = 1 To nTextCount
sNoteText
= swNote.GetTextAngleAtIndex(i)
DoReplaceString
sNoteText
swNote.SetTextAtIndex i, sNoteText
Next
i
Else
sNoteText
= swNote.GetText
DoReplaceString
sNoteText
swNote.SetText sNoteText
End
If
Set
swNote = swNote.GetNext
Wend
Set
swView = swView.GetNextView
Wend
End Sub
'--------------------------------------------------