Draw lines from text file and update sketch from text file

If you have XYZ point in a tab delimited text file, this macro will import the data and draw straight line segments between the points and ask you to name the sketch.  If your XYZ data changes, then just re-run the macro and tell it what sketch to update.  The lines will move to the new points.

The main benefit of this macro is that any references connected/mated to the original data will not be lost after an update because the lines/points are moving and not being replaced or renamed.

SolidworksApi macros
Answers 6
DG
DG 2010-02-11 Best Answer
Thanks for sharing it Ray
SF
SF 2010-02-12

I found an error in the "update" portion of the macro.  The text file needs to have coordinates between 4 and 8 characters long, e.g. 1.234567, -11.6543, 999.4567, 12.1, 1.65 are all acceptable coordinate components.

If you run the macro and import S1.txt and then run the macro to update your existing sketch using S2.txt the existing sketch updates.

DG
DG 2010-02-12

I haven't tested it yet but thanks for the updates. Also I referred Jeff on (www.swgeeks.com) to use your macro and here are his comments

<p>Thank you Ray. I was able to retrieve your macro and I did attemp torun it. As you might guess I am using SW 2006 and several of your linesof code were a problem.<br>" Dim sketchFeat As Feature",<br>and it didn' like<br>"If Mid(dataStr, I, 1) = Chr(9) Then"<br>for starters. It didn't recognize the "Mid" . I expect there is a work around.<br>Again thankyou for your time and effort.<br><br>Jeff</p>
SO
SO 2012-02-21

Thanks for posting this. Was able to send it to a customer to use right away. New there had to be a macro to read in X,Y,Z data somewhere out there.

Works good in 2012 by the way all the way out to 8 decimal places.

TT
TT 2023-01-26

What is wrong? That macro always stop to this line: ​​​​​​​ Set retval = Part.CreateLine2(Val(Coords(4) * 0.001), Val(Coords(5) * 0.001), Val(Coords(6) * 0.001), Val(Coords(1) * 0.001), Val(Coords(2) * 0.001), Val(Coords(3) * 0.001))
          

comment imagecomment image
TT
TT 2023-01-30

Hi! What am I doing wrong?

I am using SW2021. Always the macro is stopping to that line. In my txt file coordinates are 4 to 7 digits. I also have tried that S1.txt.

Could it be regional settings?