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?
> 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
WT
"Rod Morningwood" <p...@ph.uk> wrote in message
news:32105$47cd8fa8$401a9325$29...@PRIMUS.CA...
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
<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