AnsweredAssumed Answered

Some help reviewing my code

Question asked by Harold Black on Mar 29, 2018
Latest reply on Mar 30, 2018 by Harold Black

I'm having problems in a couple areas of my code and I would like to get some feedback if possible of what is going on. What my code does is take a spline and divide it up into regions called piles (in this example I have it set to piles = 6) and it creates rectangles above the spline; almost like an integral. The red lines are the region boundaries and the green line is the center line which is only used for visual purposes. In each region, I take a copy of the spline and trim it between the red vertical boundary lines. This allows me to create a line that is tangent to just this portion of the original spline. I can then create a point that is coincident to the line and the spline segment. This point is now the tangent point in the region. This tangent point is used later to determine if I need to start drawing the rectangle end segment starting from the left or right or if I need to draw it tangent to the curve.



In the development phase, I copied the original spline 6 times for the 6 regions I will have. Each copy is offset from each other 10 mm so I could see if my trim operation was performing correctly. In the code, I remove the offset using a counter multiplied by 0.01 each time the sketch segment is a spline. This is done to create my rectangle end segment in the correct location. I am now satisfied with the trim operation and I change the 0.01 offset back to what it is intended to be, 0. Now when I perform the trim operation, I get a runtime error. It looks like the error is coming from swPilePoint2.X. It seems there is no data for this point. I printed swPilePoint2.X before the trim operation and I'm able to get a value for it but not after the trim operation. What is going on? You can change the offset in this bit of code


    'Create copy of spline

    boolstatus = swModel.SelectByID("Spline1", "SKETCHSEGMENT", 0#, 0#, 0#)

    swModel.Extension.MoveOrCopy True, piles, False, 0, 0, 0, 0, 0, 0          'second 0 from last is the offset2f80d0262e58b6918e9eee050cbf9f62.png

    vSegs = swSketch.GetSketchSegments



I'm working on SolidWorks 2018. I've attached and image of where in the code the problem is and also the test file and macro file for debugging.