Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

API - Delete annotations

406 views
Skip to first unread message

Rod Morningwood

unread,
Mar 4, 2008, 9:05:25 AM3/4/08
to
Hey gang,

Thought I'd pose a little head scratcher here as I hunt for an answer.

SWX 2007, VB app deleting layers (hence annotations) using the selection
manager (similar to the vb example on the SWX website).

Problem is, if the user clicks on a drawing sheet at any time during the
selection/delete routine, that sheet is included in the selection manager
list and thus deleted. Not Happy

Any suggestions?

Philippe Guglielmetti

unread,
Mar 4, 2008, 9:45:56 AM3/4/08
to
Don't allow the user to do anything while your macro runs !
ModelDoc2::Lock + ModelDoc2::Unlock

Rod Morningwood

unread,
Mar 4, 2008, 1:06:32 PM3/4/08
to
Philippe Guglielmetti <goo...@goulu.net> wrote in news:8d800261-cccb-4884-
8962-3cf...@e10g2000prf.googlegroups.com:

> Don't allow the user to do anything while your macro runs !
> ModelDoc2::Lock + ModelDoc2::Unlock
>

Thanks for the idea,

I've tried ModelDoc2::Lock/Unlock as well as SelectionMgr::EnableSelection.
Still not happy

/still scratching head

Wayne Tiffany

unread,
Mar 4, 2008, 1:27:58 PM3/4/08
to
Maybe I'm missing something here but it sounds like your real issue is
whether the sheet is part of the selection set, not when it was clicked.
Can't you just first check each selection as you process it and if it's the
sheet, ignore it?

WT

"Rod Morningwood" <p...@ph.uk> wrote in message
news:32105$47cd8fa8$401a9325$29...@PRIMUS.CA...

Rod Morningwood

unread,
Mar 4, 2008, 2:58:13 PM3/4/08
to
"Wayne Tiffany" <wayne.tiff...@asi.com> wrote in
news:47cd949d$0$1347$834e...@reader.greatnowhere.com:

Sub from the SWX website below ...

During the while-loop, clicking on the drawing adds the selected drawing
sheet to the selection list, which is subsequently deleted.

ModelDoc2::Lock and SelectionMgr::EnableSelection do not appear to
disallow this. Parsing through the selection list (if possible), I think
is heading down the wrong road.

For this reason, I would like to stay away from the selection manager
altogether but I haven't (yet) found another way of deleting a note.

Ideally, I would like to delete the entire layer (and anything residing
on it), but any notes residing on a deleted layer remain on the drawing
(no layer) and must be dealt with.

Also, looping through every note in the drawing and checking against a
layer name is too time consuming (and unnecessary) so I would like to
retrieve them more directly (by name, by text, etc).

Thanks for any help.


Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swAnn As SldWorks.Annotation
Dim NumShts As Long
Dim bRet As Boolean
Dim i As Long


Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swDraw = swModel

NumShts = swDraw.GetSheetCount
For i = 1 To NumShts
' blindly go to the first sheet
swDraw.SheetPrevious
Next i

For i = 1 To NumShts
' clear selection set for this sheet
swModel.ClearSelection2 True

Set swView = swDraw.GetFirstView
While Not swView Is Nothing
Set swAnn = swView.GetFirstAnnotation2
While Not swAnn Is Nothing
If swNote = swAnn.GetType Then
If DeleteLayer = swAnn.Layer Then
bRet = swAnn.Select2(True, 0)
End If
End If

Set swAnn = swAnn.GetNext2
Wend

Set swView = swView.GetNextView
Wend

bRet = swModel.DeleteSelection(False)

swDraw.SheetNext
Next i
End Sub

Rod Morningwood

unread,
Mar 5, 2008, 12:24:38 PM3/5/08
to
Rod Morningwood <p...@ph.uk> wrote in news:9e49f$47cda9d5$401a9325$20901
@PRIMUS.CA:

<snip>



> During the while-loop, clicking on the drawing adds the selected
drawing
> sheet to the selection list, which is subsequently deleted.
>
> ModelDoc2::Lock and SelectionMgr::EnableSelection do not appear to
> disallow this. Parsing through the selection list (if possible), I
think
> is heading down the wrong road.
>
> For this reason, I would like to stay away from the selection manager
> altogether but I haven't (yet) found another way of deleting a note.
>
> Ideally, I would like to delete the entire layer (and anything residing
> on it), but any notes residing on a deleted layer remain on the drawing
> (no layer) and must be dealt with.
>
> Also, looping through every note in the drawing and checking against a
> layer name is too time consuming (and unnecessary) so I would like to
> retrieve them more directly (by name, by text, etc).
>
> Thanks for any help.

<snip>

Just as a follow up, I've modified the while loop as indicated below.
Although it descreases the window of opportunity for the user to include
a sheet in the selection list, it is far from bulletproof.

As a side note I can't believe there is no method to directly delete a
note or annotation. wtf?

Set swView = swDraw.GetFirstView

swModel.ClearSelection2 True
bRet = swAnn.Select2(True, 0)
Set swAnn = swAnn.GetNext3
bRet = swModel.DeleteSelection(False)
Else
Set swAnn = swAnn.GetNext3
End If
Else
Set swAnn = swAnn.GetNext3
End If


Wend
Set swView = swView.GetNextView
Wend

swDraw.SheetNext
Next i

End Sub

0 new messages