1 Reply Latest reply on Jan 25, 2018 6:19 PM by Jacob Corder

    Macro to divide selected segment with equalsegment

    Al Beau

      I'm not quite sure how to use the API for a process. I have a sketch open and I want the user to have a spline sketch entity selected and the api will use the equalsegment applied with user input on the number of sketch segments along the path. I'm not sure how to get the current sketch entity selected for this problem. The API has a vast amount of information and I was hoping someone could guide me in the right direction.



      Equalsegment tool for the spline

      2017 SOLIDWORKS API Help - EqualSegment Method (ISketchSegment)


      Useritemselect? Just want to use the line

        • Re: Macro to divide selected segment with equalsegment
          Jacob Corder

          if the segment is selected then this will work, i didnt test it but it should

          if you want it split into sketch points


          Function SplitSegment(ByVal SplitCt As Integer) As Boolean

                  Dim Part As ModelDoc2

                  Dim swApp As SldWorks = Application.SldWorks

                  Set Part = swApp.ActiveDoc

                  Dim SelMgr As SelectionMgr

                  Set SelMgr = Part.SelectionManager

                  If SelMgr.GetSelectedObjectCount2(-1) = 1 Then

                      If SelMgr.GetSelectedObjectType3(1, -1) = swSelectType_e.swSelSKETCHSEGS Then

                          Dim SkSeg As SketchSegment

                        Set SkSeg = SelMgr.GetSelectedObject6(1, -1)

                        SplitSegment = SkSeg.EqualSegment(swSketchSegmentType_e.swSketchSegmentType_sketchpoints, SplitCt)

                      End If

                  End If

              End Function