1 Reply Latest reply on Dec 10, 2014 4:04 AM by Yong Ning

    How to traverse select line or arc in SketchSegment

    Yong Ning

      0.jpg

      Follow code is select line or arc ,use   selectByID method.

       

      Sub Main3()

        Dim swApp As SldWorks.SldWorks

        Dim swModel As SldWorks.ModelDoc2, SwSelMgr As SelectionMgr

        Dim swMeasure As SldWorks.Measure

        Dim SwSkSeg As SketchSegment

       

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

          ''

          With swModel

             Set SwSelMgr = .SelectionManager

             .Extension.SelectByID2 "Line1@Sketch1", "EXTSKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0

             Set SwSkSeg = SwSelMgr.GetSelectedObject2(1)

             Debug.Print Round(SwSkSeg.GetLength, 6)

             .Extension.SelectByID2 "Arc1@Sketch1", "EXTSKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0

             Set SwSkSeg = SwSelMgr.GetSelectedObject2(1)

             Debug.Print Round(SwSkSeg.GetLength, 6)

          End With

      End Sub

       

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

      Help me.

      traverse method ,select line or arc in SketchSegment

       

      Thanks

        • Re: How to traverse select line or arc in SketchSegment
          Yong Ning

          Find method

          2014 SolidWorks API Help - Get All Elements of Sketch Example (VBA)

          http://help.solidworks.com/2014/English/api/sldworksapi/get_all_elements_of_sketch_example_vb.htm

           

          Private Sub ll1()

            Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

              Set SwApp = Application.SldWorks

              Set SwModel = SwApp.ActiveDoc

            Dim SwSelMgr As SelectionMgr, SwFeat As Feature

              Set SwSelMgr = SwModel.SelectionManager

              Set SwFeat = SwSelMgr.GetSelectedObject5(1)

            Dim SwSketch As Sketch, SkSegArr, SkSeg As SketchSegment

              Set SwSketch = SwFeat.GetSpecificFeature

              SkSegArr = SwSketch.GetSketchSegments

              For ii = 0 To UBound(SkSegArr)

                Set SkSeg = SkSegArr(ii)

                Debug.Print SkSeg.GetType, Round(SkSeg.GetLength, 6)

                SkSeg.Select2 True, 1

              Next

           

          End Sub

          ''

          Private Sub ll2()

            Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

              Set SwApp = Application.SldWorks

              Set SwModel = SwApp.ActiveDoc

            Dim SwSelMgr As SelectionMgr, SwFeat As Feature

              Set SwSelMgr = SwModel.SelectionManager

              Set SwFeat = SwModel.FeatureByName("Sketch1")

            Dim SwSketch As Sketch, SkSegArr, SkSeg As SketchSegment

              Set SwSketch = SwFeat.GetSpecificFeature

              SkSegArr = SwSketch.GetSketchSegments

              For ii = 0 To UBound(SkSegArr)

                Set SkSeg = SkSegArr(ii)

                Debug.Print SkSeg.GetType, Round(SkSeg.GetLength, 6)

                SkSeg.Select2 True, 1

              Next

           

          End Sub

           

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

           

           

          Private Sub ll()

            Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

               Set SwApp = Application.SldWorks

               Set SwModel = SwApp.ActiveDoc

            Dim SwFeat As Feature

               Set SwFeat = SwModel.FeatureByName("草图1")

               SwFeat.Select True

            Dim SwSketch As Sketch, SkArr, SkSeg As SketchSegment

               Set SwSketch = SwFeat.GetSpecificFeature

             With SwModel

                .EditSketch

                SkArr = SwSketch.GetSketchSegments

                For ii = 0 To UBound(SkArr)

                   Set SkSeg = SkArr(ii)

                   SkSeg.Select True

                Next ii

                .EditDelete

                .CreateCircleByRadius2 0, 0, 0, 0.0125

                .SketchManager.InsertSketch True

             End With        

          End Sub