API - Delete annotations

Discussion in 'SolidWorks' started by Rod Morningwood, Mar 4, 2008.

  1. 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?
     
    Rod Morningwood, Mar 4, 2008
    #1
  2. Don't allow the user to do anything while your macro runs !
    ModelDoc2::Lock + ModelDoc2::Unlock
     
    Philippe Guglielmetti, Mar 4, 2008
    #2
  3. Thanks for the idea,

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

    /still scratching head
     
    Rod Morningwood, Mar 4, 2008
    #3
  4. 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
     
    Wayne Tiffany, Mar 4, 2008
    #4
  5. 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, Mar 4, 2008
    #5
  6. @PRIMUS.CA:

    <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?


    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
     
    Rod Morningwood, Mar 5, 2008
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.