Get Note By Name Example (VBA)
This example shows how to get a note by its
name using two separate methods: note traversal and note selection. The
note selection method is faster since it avoids traversing all the notes
on the template. Once the first note is selected, the example gets the
text from the note and uses it to modify another note on the drawing.
'---------------------------------------------
Public Sub GetNotes()
Dim swApp As
Object
Dim Model, DwgDoc
As Object
Dim SelMgr As
Object
Dim note, view
As Object
Const swSelNOTES
= 15
Const swDocDRAWING
= 3
Set swApp =
CreateObject("SldWorks.Application")
Set Model =
swApp.ActiveDoc
If (Model Is
Nothing) Or (Model.GetType <> swDocDRAWING) Then
Exit Sub
End If
Set DwgDoc =
Model
DwgDoc.EditTemplate
Set view = DwgDoc.GetFirstView
Set note = view.GetFirstNote()
Do While Not
note Is Nothing
If (note.GetName = "RevNum") Then
theCurrentRev
= note.GetText
If foundNote
= True then
Exit
Do
End If
Set note = note.GetNext
Loop
If (foundNote)
Then
ret = Model.SelectById ("RevDescription@Template1",
"NOTE", 0, 0, 0)
Set SelMgr
= Model.SelectionManager()
If (SelMgr.GetSelectedObjectCount <> 0) Then
Set selObj
= SelMgr.GetSelectedObject2(1)
If (SelMgr.GetSelectedObjectType(1) = swSelNOTES)
Then
descriptionText
= "This drawing has been updated to
" + theCurrentRev + " per blah-blah"
ret = selObj.SetText(descriptionText )
If (ret = True)
Then
swApp.SendMsgToUser ("Successfully changed
note text"
Else
swApp.SendMsgToUser ("Error changing
note text.")
End If
End If
Else
swApp.SendMsgToUser ("Error selecting
RevDescription note.")
End If
End If
End Sub