API - Delete annotations

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?
Reply to
Rod Morningwood
Loading thread data ...
Don't allow the user to do anything while your macro runs ! ModelDoc2::Lock + ModelDoc2::Unlock
Reply to
Philippe Guglielmetti
Philippe Guglielmetti wrote in news:8d800261-cccb-4884- snipped-for-privacy@e10g2000prf.googlegroups.com:
Thanks for the idea,
I've tried ModelDoc2::Lock/Unlock as well as SelectionMgr::EnableSelection. Still not happy
/still scratching head
Reply to
Rod Morningwood
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
Reply to
Wayne Tiffany
"Wayne Tiffany" wrote in news:47cd949d$0$1347$ snipped-for-privacy@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
Reply to
Rod Morningwood
Rod Morningwood wrote in news:9e49f$47cda9d5$401a9325$20901 @PRIMUS.CA:
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?
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 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
Reply to
Rod Morningwood

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.