I'm making a macro to add notes and update them according to data entered in a Userform. I then get out of it to add the notes and format them but to find existing notes on a plan I dry up.
In addition, if you only changed the name of the annotation in the second part of the example, it's normal that it doesn't work. Typically here, you have to put the name of your sheet:
DetailItem300@Sheet Format1
Edit: And after testing, SW via the swNote.Getname method doesn't return the name displayed in the properties but rather something like "Detail objectxxx"
By the macro, the object returned by SwNote.GetName is DetailItem300 (in fact all the notes in their example are returned in the format DetailItemmxxx)
So their example macro is great but knowing in advance the name of the annotation is just impossible. The simplest way is to scan the notes, and if you are in " fixed " notes from one clip format to another (in the case of a title block, for example, if they are all originally from the same template), you can then simplify the code to directly target the desired notes. For my part, I've always played with the note scanner and it's not particularly slower (especially on the background plan in general there are not 250 of them).
Thank you for these answers, I see more clearly. Indeed I had omitted details, the notes are in a background plan (in the cartridge), so I should be able to target the notes concerned... For the code I copied and pasted the example by making some modifications only.
For the "scan" method: With the first part of the code. Nothing happens by changing the name
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDrawing As SldWorks.DrawingDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim swNote As SldWorks.Note
Dim swView As SldWorks.View
Dim swSelObj As Object
Dim theCurrentRev As String
Dim foundNote As Boolean
Dim ret As Boolean
Dim descriptionText As String
Const swSelNOTES = 15
Const swDocDRAWING = 3
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
' Verify that the document is a drawing
If (swModel Is Nothing) Or (swModel.GetType <> swDocDRAWING) Then
Exit Sub
End If
Set swDrawing = swModel
' Edit the current drawing template
swDrawing.EditTemplate
' This is the template
Set swView = swDrawing.GetFirstView
' This section shows a slower method for
' selecting a note by name by using note
' traversal (swView::GetFirstNote and SwView::GetNext)
' Get the first note object
Set swNote = swView.GetFirstNote
' While you have a valid note
Do While Not swNote Is Nothing
' Verify if you have the desired note by checking its name
' This can also be done by checking the position or the existing
' text string in the note
If (swNote.GetName = "DetailItem219") Then
foundNote = True
theCurrentRev = swNote.GetText
swApp.SendMsgToUser ("Note found")
End If
'Set swNote = swNote.GetNext
' Continue until no more notes
Loop
So there's something I'm not doing right. But what??
Hello Are you sure that your annotations are coded DetailItem? If your SW is in French and your templates are created on the FR version, unless I'm mistaken, all the annotations are codified as a detail object.
After a few unsuccessful attempts, I succeeded. In fact, the name "Annotation219" is not very useful by making a macro recording and selecting the note concerned, I was able to know its name (Object of détail1130@Fond of plan1 in this case). As a result, it works with the "targeted" method but not the scan... But for the time being, it doesn't bother me.
Now that the note is found, I can do whatever I want with it.