2 Replies Latest reply on Mar 28, 2018 10:16 AM by Harold Black

    Reusing a spline in a loop

    Harold Black

      I am needing to create horizontal lines tangent to all the valleys and mountains of a spline. I have vertical lines spaced evenly on the spline to dictate "intervals". In each interval I create my horizontal line. My steps below are as follows.


      Code outside of the loop

      1) Create a copy of the spline and set swSpCopy equal to it.

      2) Trim outside swSpCopy using the left and right vertical lines as boundaries.

      3) Add a tangent constraint on the horizontal line to the spline.

      4) Create a sketch point and add a constraint to be coincident to the horizontal line and another constraint coincident to the spline.

      5) Set Tanx = swTanPoint.X and Tany = swTanPoint.Y


      This code works fine for the first interval. The problem arises when I need to select my original spline to make a copy for the second interval and so on. How do I go about redrawing the full spline and selecting it without using swModel.SelectByID("Spline2", "SKETCHSEGMENT", 0#,0#,0#)? In my loop, Spline2 will never be the copy of the whole spline. I would need to set a variable equal to the copied spline. How do I use this code to set a variable equal to it swModel.Extension.MoveOrCopy True, 1, False, 0, 0, 0, 0, 0, 0? I was hoping to use Set swSpCopy = swModel.Extension.MoveOrCopy(True, 1, False, 0, 0, 0, 0, 0, 0) but this does not work.

        • Re: Reusing a spline in a loop
          Michael Spens

          Hello Harold,

          Interesting problem.  Try these ideas to see if they might help.


          First, getting the underlying SketchSegment after making the selection will help you get back to it - either to select it again, or find another spline in your sketch that isn't the original.  Here's an example of getting the SketchSegment and re-selecting it.


          Dim splineSeg As SketchSegment

          Set splineSeg = Part.SelectionManager.GetSelectedObject(1)

          splineSeg.Select False 'don't append it to the selection


          Finally, after making a copy, you can traverse all of the SketchSegments in your active sketch, checking if they are splines, then checking to see if they are the same as the original spline (the Is comparison).



          Part.Extension.MoveOrCopy True, 1, True, 0, 0, 0, 0, 0, 0

          Dim sk As Sketch

          Set sk = Part.SketchManager.ActiveSketch

          Dim skSegs As Variant

          skSegs = sk.GetSketchSegments

          Dim i As Integer

          For i = 0 To UBound(skSegs)

              Dim skSeg As SketchSegment

              Set skSeg = skSegs(i)

              Dim c As Curve

              Set c = skSeg.GetCurve

              If c.IsBcurve Then

                  'found a spline

                  If skSeg Is splineSeg Then

                      'this is the original spline



                      'this is a different spline


                  End If

              End If