notes and views

Programming and macros
steph
Posts: 17
Joined: Fri Mar 26, 2021 6:45 am
Answers: 0
x 4

notes and views

Unread post by steph »

I'm looking for a simple macro that would attach all notes in a drawing to a single view, in may case "Drawing view1".

I played around with (swAttachAnnotationOption_e.swAttachAnnotationOption_View) but since I don't know much about VB I'm not getting anywhere. Help would be greatly appreciated.
Lapuo
Posts: 109
Joined: Tue Mar 09, 2021 2:06 am
Answers: 0
x 176
x 106

Re: notes and views

Unread post by Lapuo »

Maybe i did not understand you well , but i am not sure why do you need macro.
If the view is highlighted when you drop the note then it will be attached to the view
You can also right click on the note and click "attachment" and then do "attach to view" to link it to a view
User avatar
DanPihlaja
Posts: 814
Joined: Thu Mar 11, 2021 9:33 am
Answers: 25
Location: Traverse City, MI
x 790
x 944

Re: notes and views

Unread post by DanPihlaja »

steph wrote: Fri Mar 26, 2021 6:48 am I'm looking for a simple macro that would attach all notes in a drawing to a single view, in may case "Drawing view1".

I played around with (swAttachAnnotationOption_e.swAttachAnnotationOption_View) but since I don't know much about VB I'm not getting anywhere. Help would be greatly appreciated.
I am not a macro guy...
But try this:
  • Activate the drawings view that you want all notes into
  • Select 1 note, then hit CTRL A
  • Hit CTRL X to cut all your notes and add them to the Clipboard
  • Click inside your activated view and hit CTRL V
  • You will have to rearrange them afterward, but they will be all added to the view.
-Dan Pihlaja
Solidworks 2022 SP4

2 Corinthians 13:14
JeromeP
Posts: 12
Joined: Wed Mar 24, 2021 12:40 pm
Answers: 0
x 1
x 2

Re: notes and views

Unread post by JeromeP »

Hello, Try this:

Code: Select all

Option Explicit
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 vNotes As Variant
Dim vNote As Variant
Dim vComps As Variant
Dim vEnts As Variant
Dim swEnt As SldWorks.Entity

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swView = swDraw.GetFirstView
swModel.ClearSelection2 True
vNotes = swView.GetNotes
For Each vNote In vNotes
    Set swNote = vNote
    Set swAnn = swNote.GetAnnotation
    If swAnn.OwnerType = swAnnotationOwner_e.swAnnotationOwner_DrawingSheet Then
        swAnn.Select3 True, Nothing
    End If
Next
Set swView = swView.GetNextView
vComps = swView.GetVisibleComponents
vEnts = swView.GetVisibleEntities2(vComps(0), swViewEntityType_e.swViewEntityType_Face)
Set swEnt = vEnts(0)
swEnt.Select4 True, Nothing
swDraw.AttachAnnotation swAttachAnnotationOption_e.swAttachAnnotationOption_View
End Sub
Note: It will attach all the sheet's notes to the first drawing view, but not the notes already attached to a view.
If you also want to do that (i.e attach the other drawing views notes to the first view), try to change:

Code: Select all

If swAnn.OwnerType = swAnnotationOwner_e.swAnnotationOwner_DrawingSheet Then
to

Code: Select all

If swAnn.OwnerType = swAnnotationOwner_e.swAnnotationOwner_DrawingSheet Or swAnn.OwnerType = swAnnotationOwner_e.swAnnotationOwner_DrawingView Then
steph
Posts: 17
Joined: Fri Mar 26, 2021 6:45 am
Answers: 0
x 4

Re: notes and views

Unread post by steph »

Hi Jerome
Thanks for your help, it's very close to what I'm looking for. The macro works for notes that are attached to the sheet, they attached to the "Firstview" but when I try the second option, that is to get all notes from all views, there's no difference.
I added a "Debug.Print swNote.GetText" right after the "Set swAnn = swNote.GetAnnotation" to try to understand a bit more what was going on and the only notes that get listed are the ones that are attached to the sheet. Would you be kind enough to help a little bit more?
JeromeP
Posts: 12
Joined: Wed Mar 24, 2021 12:40 pm
Answers: 0
x 1
x 2

Re: notes and views

Unread post by JeromeP »

Sure. Try this:

Code: Select all

Option Explicit
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 vNotes As Variant
Dim vNote As Variant
Dim vComps As Variant
Dim vEnts As Variant
Dim swEnt As SldWorks.Entity

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swView = swDraw.GetFirstView
swModel.ClearSelection2 True
While Not swView Is Nothing
    vNotes = swView.GetNotes
    For Each vNote In vNotes
        Set swNote = vNote
        Set swAnn = swNote.GetAnnotation
        If swAnn.OwnerType = swAnnotationOwner_e.swAnnotationOwner_DrawingSheet Or swAnn.OwnerType = swAnnotationOwner_e.swAnnotationOwner_DrawingView Then
            swAnn.Select3 True, Nothing
        End If
    Next
    Set swView = swView.GetNextView
Wend
Set swView = swDraw.GetFirstView
Set swView = swView.GetNextView
vComps = swView.GetVisibleComponents
vEnts = swView.GetVisibleEntities2(vComps(0), swViewEntityType_e.swViewEntityType_Face)
Set swEnt = vEnts(0)
swEnt.Select4 True, Nothing
swDraw.AttachAnnotation swAttachAnnotationOption_e.swAttachAnnotationOption_View
End Sub
steph
Posts: 17
Joined: Fri Mar 26, 2021 6:45 am
Answers: 0
x 4

Re: notes and views

Unread post by steph »

Thank you very much, just what I needed
And thanks to the others who also tried to help, greatly appreciated.
Post Reply