Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing Coordinates & Automated Drawing 1

Status
Not open for further replies.

butelja

Mechanical
Jun 9, 1999
674
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? [sig][/sig]
 
Replies continue below

Recommended for you

How is your ASCII text file written?
x1,y1
x2,y2
or
x1 y1
x2 y2

How many points (max) will be in this file?
[sig][/sig]
 
tclere,

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. [sig][/sig]
 
butelja,

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
[sig][/sig]
 
I don't know much about MathCad, but here's an idea you may want to think about. Could you open the ASCII text with Word, and then change the spaces into commas using a search and replace? Once that's done, save the file as ASCII and proceed on your merry way.

[sig][/sig]
 
I have found the solution to my problem. If the data is pulled in to Excel, it can be saved as a "comma separated value" file (*.CSV). This automatically removes all blanks and adds the needed commas. [sig][/sig]
 
The nice thing about the macro is that you can add it to your AutoCAD template, making it always available. This saves you from the intermediate Excel step. I guess it just depends on how often you need to do this. [sig][/sig]
 
tclere:

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 [sig][/sig]
 
This VBA code can be used in AutoCAD, Excel, Word, etc. This is generic VB code that can be used in any package that supports MS VBA. If you put this code in an AutoCAD project, then you can create a menu item and/or a toolbar button to run the code. I have written several AutoCAD utilities in this manner, including the automation of flanges and weld symbols.

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. [sig][/sig]
 
Great explanantion. With my limited knowledge of the breadth of VBA code I was assuming that you were downloading the files to Excel for post/pre processing. However, there was no mention of that in your post. Naturally, I was curious about the matter. Thanks for the explanation. [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor