Please help: How to read coordinates from a txt file

Discussion in 'AutoCAD' started by Nenad Markovic, Feb 1, 2004.

  1. I need to read x,y,z coordinates from an ASCII file and then draw points
    with this coordinates in AutoCAD. Can anybody help me suggesting the
    AutoLISP function(s) that I should use and the pseudo code or algorithm.

    Thanks in advance

    Nesha
     
    Nenad Markovic, Feb 1, 2004
    #1
  2. Nenad Markovic

    Tom Berger Guest

    ....
    (setq filehandle (open "path/filename" "r"))
    (while (setq line (read-line filehandle))
    ;; if your string is not "x,y,z"
    ;; then process the string here
    (setq datalist (cons line datalist))
    )
    (close filehandle)
    (foreach pt (reverse datalist)
    (command "._POINT" pt)
    )
    ....

    I don't know how your file is formatted. If it is x,y,z in each single
    line, then you can pass the string directly to the POINT command, or
    if you need the coordinates in LISP format then you could substitute
    (vl-string-subst) the commas with spaces, add (strcat) a leading "("
    and a trailing ")" to each line (inside the while loop) and use
    (setq datalist (cons (read line) datalist))

    Tom Berger
     
    Tom Berger, Feb 1, 2004
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.