Page 1 of 1
notes and views
Posted: Fri Mar 26, 2021 6:48 am
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.
Re: notes and views
Posted: Fri Mar 26, 2021 9:16 am
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
Re: notes and views
Posted: Fri Mar 26, 2021 11:58 am
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.
Re: notes and views
Posted: Fri Mar 26, 2021 12:29 pm
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
Re: notes and views
Posted: Mon Mar 29, 2021 1:11 pm
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?
Re: notes and views
Posted: Tue Mar 30, 2021 12:50 am
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
Re: notes and views
Posted: Tue Mar 30, 2021 6:43 am
by steph
Thank you very much, just what I needed
And thanks to the others who also tried to help, greatly appreciated.