Importing Coordinates & Automated Drawing
Importing Coordinates & Automated Drawing
(OP)
Is there a relatively easy way to import x,y coordinates from an ASCII text file and automatically draw a polyline between them?
I have had limited success by adding the "_pline" command at the beginning of the file and saving it as a script (*.scr) file, then running the "script" command within Autocad. However, this requires considerable manual tweaking, as I must add commas between each x,y pair and delete any blank spaces in the file. For some reason, Autocad sees any blank space as a carriage return when the script is running. Is there an easier way to do this?
I have had limited success by adding the "_pline" command at the beginning of the file and saving it as a script (*.scr) file, then running the "script" command within Autocad. However, this requires considerable manual tweaking, as I must add commas between each x,y pair and delete any blank spaces in the file. For some reason, Autocad sees any blank space as a carriage return when the script is running. Is there an easier way to do this?





RE: Importing Coordinates & Automated Drawing
x1,y1
x2,y2
or
x1 y1
x2 y2
How many points (max) will be in this file?
RE: Importing Coordinates & Automated Drawing
My ASCII text file is generated by Mathcad, and is in the form of:
x1 y1
x2 y2
It needs to be changed to the form of:
x1,y1
x2,y2
There are potentially several hundred pairs of coordinates. What I really need is an easier method of changing the file from space delimited to comma delimeted. I have not been able to do this from within Mathcad.
RE: Importing Coordinates & Automated Drawing
You can add this macro to convert the format of the data file from space delimeted to comma delimeted. By the sounds of it, you have the rest of the solution to draw the polylines. Let me know if you need any additional help.
Sub FormatDataFile()
Dim sDataFile As String, sTempFile As String
Dim sLine As String, sX As String, sY As String
Dim iPos As Integer
sDataFile = "C:\Temp\MyData.txt"
sTempFile = "C:\Temp\MyData.tmp"
FileCopy sDataFile, sTempFile
Open (sTempFile) For Input As #1
Open (sDataFile) For Output As #2
Do While Not EOF(1)
Line Input #1, sLine
iPos = InStr(1, sLine, " ")
sX = Left(sLine, iPos - 1)
sY = Right(sLine, Len(sLine) - iPos)
Print #2, sX & "," & sY
Loop
Close #2
Close #1
Kill sTempFile
MsgBox "File Conversion Complete"
End Sub
RE: Importing Coordinates & Automated Drawing
RE: Importing Coordinates & Automated Drawing
RE: Importing Coordinates & Automated Drawing
RE: Importing Coordinates & Automated Drawing
The macro you posted is to work within Autocad? I guess, given the right parameters, it will work in any windows environment. Could you clarify this point for my understanding.
Thanks
RE: Importing Coordinates & Automated Drawing
Both AutoCAD and SolidWorks support VBA programming. This is an extremely powerful tool that, unfortunately, very few people use. For example, I have completely automated several portions of our product design in SolidWorks using similar programming techniques, turning 40 hour design projects into 4 hour drafting projects. Needless to say, projects like this take significant time, but the ROIs are extraordinary. Let me know if you have any more questions.
RE: Importing Coordinates & Automated Drawing