2 Replies Latest reply on May 7, 2014 2:35 AM by Yong Ning

    SwAnn.Select+EditDelete→Solidworks is fail.

    Yong Ning

      Why Run "SwAnn.Select True + SwDraw.EditDelete" code,Result is fail → Solidworks quit

      Why Run ".Extension.SelectByID2 + SwDraw.EditDelete" code, Result is currend.

               

               

      ******************************

      Code is

      Private Sub tDelDim()

        ''

        Dim Arr, Str

        Str = "凸台@JB4721Sketch,h1@JB4721Sketch,Delta1@JB4721Sketch,Delta2@JB4721Sketch,R@JB4721Sketch,D2@JB4721Sketch,D4@JB4721Sketch,D1@Alfa基准面"

        ''

        Dim SwApp As SldWorks.SldWorks, SwDraw As DrawingDoc

        Dim SwView As View, SwAnn As Annotation

        Dim SwDim As Dimension, DispDim As DisplayDimension

        Set SwApp = Application.SldWorks

        Set SwDraw = SwApp.ActiveDoc

        Set SwView = SwDraw.GetFirstView

        Do While Not SwView Is Nothing

           Set DispDim = SwView.GetFirstDisplayDimension

           Do While Not DispDim Is Nothing

              Set SwDim = DispDim.GetDimension

              oStr = SwDim.FullName

              oStr = Left(oStr, InStrRev(oStr, "@") - 1)

              Debug.Print oStr

       

              If InStr(Str, oStr) > 0 Then

                Set SwAnn = DispDim.GetAnnotation

                SwAnn.Select True

                SwDraw.EditDelete

              End If

              Set DispDim = DispDim.GetNext

           Loop

           Set SwView = SwView.GetNextView

        Loop

        ''

      End Sub

      *****************************************

       

      Follow code is current,don't fail.

          SwDraw.Extension.SelectByID2 Str, "DIMENSION", 0, 0, 0, False, 0, Nothing, 0

          SwDraw.EditDelete

       

       

      ''

      Function DelDim(SwApp As SldWorks.SldWorks, SwDraw As DrawingDoc, SwView As View, Arr)

        Dim SwModel As ModelDoc2, Str

        Set SwModel = SwApp.GetOpenDocumentByName(SwView.GetReferencedModelName)

        Str = SwModel.GetTitle

        oStr = Left(Str, Len(Str) - 7)

        ''

        For ii = 0 To UBound(Arr)

          Str = Arr(ii) & "@" & oStr & "@" & SwView.GetName2

          SwDraw.Extension.SelectByID2 Str, "DIMENSION", 0, 0, 0, False, 0, Nothing, 0

          SwDraw.EditDelete

        Next ii

      End Function

       

       

      Private Sub DelDim0502()

        ''

        Dim Arr, Str

        Arr = Array("凸台@JB4721Sketch", "h1@JB4721Sketch", "Delta1@JB4721Sketch", "Delta2@JB4721Sketch", "R@JB4721Sketch", "D2@JB4721Sketch", "D4@JB4721Sketch")

        ''

        Dim SwApp As SldWorks.SldWorks, SwDraw As DrawingDoc

        Dim SwView As View, SwAnn As Annotation

        Dim SwDim As Dimension, DispDim As DisplayDimension

        Set SwApp = Application.SldWorks

        Set SwDraw = SwApp.ActiveDoc

        Set SwView = SwDraw.GetFirstView

        Set SwView = SwView.GetNextView

        DelDim SwApp, SwDraw, SwView, Arr

        ''

        Set SwView = SwView.GetNextView

        DelDim SwApp, SwDraw, SwView, Arr

      End Sub

        • Re: SwAnn.Select+EditDelete→Solidworks is fail.
          Jacob Corder

          I use this below because it can be used for all selectable entities. I typed this in from memory so tbere may be spelling issues.

          you could also use in the Functions Arguments instead of ByRef Selobj() as object, you could also do Byref Objects as object which could be an array or just a single item. you would have to do a Typeof Check on it to see if its an array of items or just a single item.

          Public Function DeleteEntities(ByVal Modeldoc As ModelDoc2, ByRef selobj() As Object) As Boolean

                  Dim retBool As Boolean = False

                  If IsNothing(Modeldoc) = False And IsNothing(selobj) = False Then

                      Dim SelMgr As SelectionMgr = Modeldoc.SelectionManager

                      If IsNothing(selmgr) = False Then

                          Try

                              SelMgr.SuspendSelectionList()

                              Dim dwrapper(UBound(selobj)) As DispatchWrapper

                              Dim seldata As SelectData = SelMgr.CreateSelectData

                              For i = LBound(dwrapper) To UBound(dwrapper)

                                  dwrapper(i) = New DispatchWrapper(selobj(i))

                              Next

                              Dim selcount As Integer = selmgr.AddSelectionListObjects(dwrapper, seldata)

                              retBool = Modeldoc.Extension.DeleteSelection2(swDeleteSelectionOptions_e.swDelete_Absorbed)

                          Catch ex As Exception

                          Finally

                              selmgr.ResumeSelectionList()

                          End Try

                      End If

                      selmgr = Nothing

                  End If

                  Return retBool

              End Function