2 Replies Latest reply on Jan 30, 2017 7:27 PM by Yong Ning

    How to traverse line in dawingdoc

    Yong Ning

      Traverse Delete Line.jpg


      follow code, can be delete text with traverse method.


      Function delTxtLayer(SwDraw As DrawingDoc, Layer)

          Dim SwView As View

              Set SwView = SwDraw.GetFirstView

          Dim SwNote As Note, SwAnn As Annotation

              Set SwNote = SwView.GetFirstNote

              Do While Not SwNote Is Nothing

                  Set SwAnn = SwNote.GetAnnotation

                  ''Debug.Print SwNote.GetText, SwAnn.Layer

                  If SwAnn.Layer = Layer Then

                      SwAnn.Select True

                  End If

                  Set SwNote = SwNote.GetNext



      End Function



      Help me.

        How to traverse line in drawingdoc. delte line in drawingdoc.

        • Re: How to traverse line in dawingdoc
          Raghvendra Bhargava

          Try this:


          Dim swApp As Object

          Dim Part As Object

          Dim boolstatus As Boolean


          Sub main()

          Set swApp = Application.SldWorks

          Set Part = swApp.ActiveDoc


          boolstatus = Part.Extension.SelectByID2("Sheet1", "SHEET", 0, 0, 0, False, 0, Nothing, 0)'Change your Sheet Name



          Dim sk As Sketch

          Set sk = Part.SketchManager.ActiveSketch

          Dim ArrSegment As Variant

          ArrSegment = sk.GetSketchSegments


          Dim Segment As SketchSegment

          Dim cnt As Integer

          For cnt = 0 To UBound(ArrSegment)

              Set Segment = ArrSegment(cnt)

              Segment.Select False




          Part.ClearSelection2 True

          End Sub

            • Re: How to traverse line in dawingdoc
              Yong Ning

              Thanks your code.


              My code is




              Sub Del()

                  Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                      Set SwApp = Application.SldWorks

                      Set SwModel = SwApp.ActiveDoc

                  Dim SwDraw As DrawingDoc

                      Set SwDraw = SwModel

                      DelLineLayer SwDraw, "细实线"

              End Sub

              Function DelLineLayer(SwDraw As DrawingDoc, Layer)

                     SwDraw.ClearSelection2 True


                   Dim SwSketch As Sketch

                       Set SwSketch = SwDraw.GetActiveSketch2

                   Dim ArrSegment, SwSegMent As SketchSegment

                       ArrSegment = SwSketch.GetSketchSegments


                       For ii = 0 To UBound(ArrSegment)

                           Set SwSegMent = ArrSegment(ii)

                           If SwSegMent.Layer = Layer Then

                               SwSegMent.Select False


                           End If

                       Next ii

                       SwDraw.ClearSelection2 True

              End Function