I have to write a macro for my work and I can’t get it to work, so if anyone could help me, I would be grateful.
For eg, an electrical drawing has multiple PMAs such as PMA17-100, PMA12-200, PMA17-500 etc. I need to write a macro that will firstly make a pop up box, msgbox, that will list the PMAs for eg: 2 PMA17: 100,500 , 1 PMA12-200. Also, I need it to then make a table in a drawing (next to where there is part name etc.) and in the first column it willl list PMA17 and PMA12 and then in the second column it would sum the numbers after – if the numbers after PMA are the same (for eg PMA17: 600, PMA12: 200). I am stuck on this for days, I can’t even find the macro that does something similar so any help is reallllly needed 🙂
I only got to this:
`Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swNote As SldWorks.Note
Dim swAnn As SldWorks.annotation
Dim bRet As Boolean
Dim noteText As String
Dim notePrefix As String
Dim notesDict As Object
Dim noteKex As Variant
Dim groupedNotes As String
Dim msgText As String
Dim instance As IModelDoc2
notePrefix = "PMA"
Set notesDict = CreateObject("Scripting.Dictionary")
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swView = swDraw.GetFirstView
Set swNote = swView.GetFirstNote
swModel.ClearSelection2 (True)
Debug.Print "File = " & swModel.GetPathName
Do While Not swNote Is Nothing
Set swAnn = swNote.GetAnnotation
bRet = swAnn.Select2(True, 0)
noteText = swNote.GetText
If Left(noteText, Len(notePrefix)) = notePrefix Then
Debug.Print " " & swNote.GetName
Debug.Print " " & swNote.GetText
End If
Set swNote = swNote.GetNext
Loop
If notesDict.Count > 0 Then
msgText = "Grouped Notes starting with " & notePrefix & ":" & vbCrLf & vbCrLf
MsgBox msgText, vbInformation, "Notes Grouped by PMA"
Else
MsgBox " '" & notePrefix & "' not found.", vbExclamation, "Nema PMA u dokumentu"
End If
End Sub`
```
`
and it displays correct text in the immediate window and not in the msgbox.
Arijana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.