×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Importing Coordinates & Automated Drawing

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?

RE: Importing Coordinates & Automated Drawing

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?

RE: Importing Coordinates & Automated Drawing

(OP)
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.

RE: Importing Coordinates & Automated Drawing

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

RE: Importing Coordinates & Automated Drawing

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.

RE: Importing Coordinates & Automated Drawing

(OP)
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.

RE: Importing Coordinates & Automated Drawing

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.

RE: Importing Coordinates & Automated Drawing

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

RE: Importing Coordinates & Automated Drawing

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.

RE: Importing Coordinates & Automated Drawing

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources