4 Replies Latest reply on Apr 28, 2015 8:12 AM by Alec Hearne

    Issue with using create line function

    Alec Hearne

      As a disclaimer I am fairly new to programming in VBA and my code may not be the prettiest to look at.


      I have written a code that pulls ten points from a spline and places them at even intervals along the spline. At that point it calculates a rough approximation of the tangents from each point, and uses the "createline" function to place a line normal to the tangent using coordinates I've calculated. I run into an issue, though, with this function and it not plotting the second set of coordinates correctly, if at all. Sometimes it works, and sometimes it doesn't. It seems pretty arbitrary as to whether it will work or not. I've even tried hard coding the points I want to plot as shown below, and it will still not correctly plot. I've noticed it works correctly with a larger line length, but unfortunately for my purpose I need a short line.


      Below is a sample of the code that creates the line. The debug.print function outputs the correct points, yet when I take those same values and input them into the createline command, it does not use the correct values for x2 and y2. The x1 and y1 values are always correct, also.


          For j = 0 To UBound(locs)

              pointIndex = locs(j)

              x1 = IDPtArr(pointIndex, 1)

              y1 = IDPtArr(pointIndex, 2)

              x2 = x1

              y2 = y1 + 0.00254

              If pointIndex = 15 Then

                  x2 = x1 - 0.0008

                  y2 = y1 + 0.0038

              ElseIf pointIndex = 19 Then

                  x2 = x1

                  y2 = y1 + 0.0046

              End If

              Set skSegment = swModel.SketchManager.CreateLine(x1, y1, 0#, x2, y2, 0#)

              swModel.ClearSelection2 True

              Debug.Print x1 & "x____y" & x1

              Debug.Print x2 & "dx____dy" & y2



      I've attached the full code in the two macros below if you want to take a look at the context, and thanks in advance for the help! I ended up using two macros to decrease the length of the code, as I was running into some performance issues by having it all in one place.