Macro Note Manipulation on MEP

Hello everyone,

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.

I tried to use the example here ==> 2020 API - Get Note By Name Example (VBA)

By replacing the name of the sample note (DetailItem300) with my own (Annotation219). nothing happens. Without this step I can't continue my macro :frowning:

Will any of you be able to solve this problem?

Thank you :slight_smile:

Good evening
Could you post your code and specify if the note is in the background, if it comes from a property...

Hello

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"

In addition, the annotation in the SW sample file to test the macro is called Annotation11.

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)
image
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).

Hello Cyril.f,

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?? :thinking:

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.

No indeed it's in FR, well seen :wink:

I test it right away.

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. :slight_smile:

Thank you for your help Cyril.f

:metal:

You're welcome.
For the scan normally with just "Detail object1130" it should work.