2 Replies Latest reply on Dec 12, 2016 5:22 AM by Yong Ning

    SelectByID2→delete line,SketchSeg.Select→don't delete line?

    Yong Ning

      SelectByID2 can be delete line. follow code is

       

      boolstatus = Part.ActivateView("bb")

      boolstatus = Part.Extension.SelectByID2("Line3", "SKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)

      boolstatus = Part.Extension.SelectByID2("Line2", "SKETCHSEGMENT", 0, 0, 0, True, 0, Nothing, 1)

      boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", 0, 0.1570691751775, 0, True, 0, Nothing, 1)

      boolstatus = Part.Extension.SelectByID2("Line4", "SKETCHSEGMENT", 0, 0.1992614229289, 0, True, 0, Nothing, 1)

      Part.EditDelete

       

       

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

      SwSketchSeg.Select True,        SwDraw.EditDelete

       

      Error.jpg

       

         Dim SwSketch As Sketch

              Set SwSketch = SwView.GetSketch

         Dim vSketchSeg, SwSketchSeg As SketchSegment

              vSketchSeg = SwSketch.GetSketchSegments

              ''

              For ii = 0 To UBound(vSketchSeg)

                  Set SwSketchSeg = vSketchSeg(ii)

                  SwSketchSeg.Select True

                  SwDraw.DeleteSelection True

              Next ii

              SwDraw.EditDelete

        • Re: SelectByID2→delete line,SketchSeg.Select→don't delete line?
          Artem Taturevych

          You need to activate the view before. Add the lines marked in green

           

          Function delBrokenOut(SwDraw As DrawingDoc, SwView As View)

           

              SwDraw.ClearSelection

              Dim SwSketch As Sketch

              Set SwSketch = SwView.GetSketch

                 

             SwDraw.ActivateView SwView.Name

                 

              Dim vSketchSeg, SwSketchSeg As SketchSegment

              vSketchSeg = SwSketch.GetSketchSegments

                  ''

              For ii = 0 To UBound(vSketchSeg)

                  Set SwSketchSeg = vSketchSeg(ii)

                  SwSketchSeg.Select2 True, ii

                  'SwDraw.DeleteSelection True

                  SwDraw.DeleteSelection False

                     

              Next ii

             

              SwDraw.EditDelete

           

              SwDraw.ClearSelection

              SwDraw.ActivateView ""

              Stop

                 

          End Function

            • Re: SelectByID2→delete line,SketchSeg.Select→don't delete line?
              Yong Ning

              Thank your key code is

               

              SwDraw.ActivateView SwView.Name → SwDraw.DeleteSelection False

               

              Follow code is correct →

              Function delBrokenOut(SwDraw As DrawingDoc, SwView As View)

                      ''

                      SwDraw.ClearSelection

                      SwDraw.ActivateView SwView.Name

                 Dim SwSketch As Sketch

                      Set SwSketch = SwView.GetSketch

                 Dim vSketchSeg, SwSketchSeg As SketchSegment

                      vSketchSeg = SwSketch.GetSketchSegments

                      ''

                      For ii = 0 To UBound(vSketchSeg)

                          Set SwSketchSeg = vSketchSeg(ii)

                          SwSketchSeg.Select True

                          SwDraw.DeleteSelection False

                      Next ii

                      SwDraw.ActivateView ""

                      SwDraw.ClearSelection

              End Function

               

               

              Private Sub lll()

                  Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                      Set SwApp = Application.SldWorks

                      Set SwModel = SwApp.ActiveDoc

                  Dim SwSelMgr As SelectionMgr

                      Set SwSelMgr = SwModel.SelectionManager

                  Dim SwDraw As DrawingDoc

                      Set SwDraw = SwModel

                  Dim SwView As View, tmp, ViewName

                      ViewName = "卧式贮罐主视图"

                      ViewName = "bb"

                      tmp = SwModel.Extension.SelectByID2(ViewName, "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)

                      Set SwView = SwSelMgr.GetSelectedObject5(1)

                      'BrokenOut SwDraw, SwView

                      SwModel.ClearSelection

                      SwModel.ForceRebuild3 False

                      tmp = SwModel.Extension.SelectByID2(ViewName, "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)

                      Set SwView = SwSelMgr.GetSelectedObject5(1)

                      delBrokenOut SwDraw, SwView

              End Sub