Excel points to Acad

Discussion in 'AutoCAD' started by CadDennis, Oct 13, 2004.

  1. CadDennis

    CadDennis Guest

    I posted this topic in the AutoCAD 2002 group, but I think I may get better ideas if I also post here too. I'm using Acad 2002 (Not LDT) and I need to plot points from Excel into Acad. Because there are hundreds of points, I don't want to enter one by one. Do you have any way to do this? or if you have a lisp to do this, can I have it, please! Thanks for suggestions.
     
    CadDennis, Oct 13, 2004
    #1
  2. CadDennis

    CadDennis Guest

    I alread created a .csv file, but how do I import it into Standard acad 2002. This is my primary question. Thanks
     
    CadDennis, Oct 13, 2004
    #2
  3. CadDennis

    fengk Guest

    It would be something like this. Need a little input from you to finish.

    ;; The function processStr depends how your cvs file looks like, i.e.
    ;; whether it only has X, Y coordinates, or also has Z coordinates.
    ;; Can you post a screen shot of it. Or just type couple of lines.
    ;; This function should be easy to write.

    ;; Command: CVS2PTS
    ;; By FengK, Oct 2004
    (defun C:CVS2PTS (/ path file str lstPt mSpace)
    (setq path (getfiled
    "Select .CVS file to import point data:"
    (setq prefix (getvar "DWGPREFIX"))
    "cvs"
    8
    )
    file (open path "R")
    )
    (while (setq str (read-line file))
    (setq lstPt (cons (processStr str) lstPt))
    )
    (close file)
    (setq mSpace (vla-get-modelspace
    (vla-get-activedocument (vlax-get-acad-object))
    )
    )
    (foreach pt (reverse lstPt)
    (vla-addpoint mSpace (vlax-3d-point pt))
    )
    (prompt "\nDone.")
    (princ)
    )
     
    fengk, Oct 14, 2004
    #3
  4. CadDennis

    BillZ Guest

    This would have been my next suggestion also.

    Read the file and create the points.

    My only question was are the lines of the file a "list" or not.


    Bill
     
    BillZ, Oct 14, 2004
    #4
  5. CadDennis

    CadDennis Guest

    First of all, I'm appreciated for your help. This is an example of my .cvs file
    x,y,z
    2835400.4197,746671.4382,1822.8590
    2835440.1215,746676.3130,1822.4829
    2835457.1833,746537.3566,1821.7426
    2835423.4367,746533.2130,1822.5674
    Thanks.
     
    CadDennis, Oct 14, 2004
    #5
  6. CadDennis

    BillZ Guest

    Can you make a file like this in a "space" delimited?

    That way each line of the file can be used as a point using the list function.

    Oh, and is the first line of the file "x,y,z" ?
    We'd have to trim that.

    Bill
     
    BillZ, Oct 14, 2004
    #6
  7. CadDennis

    CadDennis Guest

    I'm not quite understanding your question. please explain...
    Oh, the first line x,y,z is not in the file.
     
    CadDennis, Oct 14, 2004
    #7
  8. CadDennis

    BillZ Guest

    Well I'm not sure how you created the file that you posted a sample of, but it is what you call a comma delimited format.
    Some apps will allow you to saveas a comma delimited or space delimited.

    32.4,55.7,22.3 = comma delimited.

    32.4 55.7 22.3 = space delimited.

    Just thought it would be easier to use space delimited.

    Bill
     
    BillZ, Oct 14, 2004
    #8
  9. CadDennis

    BillZ Guest

    Okay,
    Sorry this took so long.

    Open your drawing.

    Cut and paste this lisp into a notepad file and save it somewhere in the search path as insert_points.lsp

    ;;10-14-04 Bill Zondlo

    (vl-load-com)


    ;;
    ;;Reads point coordinates from comma delimited file and creates points in acad.
    ;;

    (defun c:Insert_Points (/ fl fl1)
    (if (setq filename (getfiled "SELECT COMMA DELIMITED TEXT FILE" "C:/" "" 6)) ;get filename file.
    (progn
    (setvar "pdmode" 34)
    (setq fl (open filename "r") ;open file for read.
    )
    (while (setq fl1 (read-line fl)) ;while there are files.
    (if (not (null fl1))
    (progn
    (setq fl1 (vl-string-subst " " "," fl1)
    fl1 (vl-string-subst " " "," fl1)
    )
    (vl-cmdf ".point" (read (strcat "(" fl1 ")")))
    )
    ) ;end if.
    ) ;end while.
    (close fl) ;must close file.
    ) ;end progn
    ) ;end if.
    (princ)
    )

    Load the lisp file at the command line.

    Command:(load "insert_points")

    Then type in:

    Command:insert_points

    Select the .cvs file from the dialog box and the program should do the rest.
    Zoom all to see the points.


    Bill
     
    BillZ, Oct 14, 2004
    #9
  10. CadDennis

    fengk Guest

    You're welcome. See code below. I assume you don't have first line "x,y,z" in you .csv file. I didn't test this code. Post back if you have problem running it.

    ;; Command: CVS2PTS
    ;; By FengK, Oct 2004.
    (defun C:CVS2PTS (/ path file str lstPt mSpace)
    (setq path (getfiled
    "Select .CVS file to import point data:"
    (setq prefix (getvar "DWGPREFIX"))
    "cvs"
    8
    )
    file (open path "R")
    )
    (prompt "\nReading point data...")
    (princ)
    (while (setq str (read-line file))
    (setq lstPt (cons (processStr str) lstPt))
    )
    (close file)
    (setq mSpace (vla-get-modelspace
    (vla-get-activedocument (vlax-get-acad-object))
    )
    )
    (prompt "\nInserting points...")
    (princ)
    (foreach pt (reverse lstPt)
    (vla-addpoint mSpace (vlax-3d-point pt))
    )
    (prompt " Done.")
    (princ)
    )

    (defun processStr (str / @1 @2)
    (setq @1 (vl-string-search "," str)
    @2 (vl-string-search "," str (1+ @1))
    )
    (mapcar 'atof
    (list str (substr str 1 (+ 2 @1)) (substr str (+ 2 @2)))
    )
    )
     
    fengk, Oct 14, 2004
    #10
  11. CadDennis

    CadDennis Guest

    Perfect!....
    It works perfect with mutiple extension files. It works with .csv and .txt also.
    Again, thank you for sending time to do this.
    You should think that I am a dump guy if I ask you another thing...
     
    CadDennis, Oct 14, 2004
    #11
  12. CadDennis

    CadDennis Guest

    Thank you for sending time to do this, Fengk!
    It works, but all points go to 0,0...
    May be my file has some thing wrong. Do you think..?
     
    CadDennis, Oct 14, 2004
    #12
  13. CadDennis

    fengk Guest

    Had some errors in it. Try this one.

    ;; Command: CSV2PTS
    ;; By FengK, Oct 2004.
    (defun C:CSV2PTS (/ path file str lstPt mSpace)
    (setq path (getfiled
    "Select .CSV file to import point data:"
    (setq prefix (getvar "DWGPREFIX"))
    "csv"
    8
    )
    file (open path "R")
    )
    (prompt "\nReading point data...")
    (princ)
    (while (setq str (read-line file))
    (setq lstPt (cons (processStr str) lstPt))
    )
    (close file)
    (setq mSpace (vla-get-modelspace
    (vla-get-activedocument (vlax-get-acad-object))
    )
    )
    (prompt "\nInserting points...")
    (princ)
    (foreach pt (reverse lstPt)
    (vla-addpoint mSpace (vlax-3d-point pt))
    )
    (prompt " Done.")
    (princ)
    )

    (defun processStr (str / @1 @2)
    (setq @1 (vl-string-search "," str)
    @2 (vl-string-search "," str (1+ @1))
    )
    (mapcar 'atof
    (list str (substr str (+ 2 @1)) (substr str (+ 2 @2)))
    )
    )
     
    fengk, Oct 14, 2004
    #13
  14. CadDennis

    CadDennis Guest

    It just read y and z values only. It could not read x value. it inserts all x value to 0. thanks
     
    CadDennis, Oct 15, 2004
    #14
  15. CadDennis

    fengk Guest

    I tested on the coordinates you posted. I don't know what is going on. Can you post your csv file in customer files group?
     
    fengk, Oct 15, 2004
    #15
  16. CadDennis

    BillZ Guest

    You're welcome.

    I'm glad it was what you wanted.

    You can set the directory that it opens in by changing the "C:\" path string to what you want in this line of code:

    (if (setq filename (getfiled "SELECT COMMA DELIMITED TEXT FILE" "C:\" "" 6))

    i.e. "C\TEMP\" or "C:\Documents and Settings\wpz\My Documents"



    Bill
     
    BillZ, Oct 15, 2004
    #16
  17. CadDennis

    BillZ Guest

    Heres a cleaned up version.

    I caught heck for the (not (null var)) once before.

    ;;10-15-04 Bill Zondlo
    ;;
    ;;Reads point coordinates from comma delimited file and creates points in acad.
    ;;

    (defun c:Insert_Points (/ fl fl1 filename)
    (vl-load-com)
    (if (setq filename (getfiled "SELECT COMMA DELIMITED TEXT FILE" "C:/" "" 6)) ;get filename.
    (progn
    (setvar "pdmode" 34)
    (setq fl (open filename "r") ;open file for read.
    )
    (while (setq fl1 (read-line fl)) ;while there are lines.
    (if fl1
    (progn
    (setq fl1 (vl-string-subst " " "," fl1)
    fl1 (vl-string-subst " " "," fl1)
    )
    (vl-cmdf ".point" (read (strcat "(" fl1 ")")))
    )
    ) ;end if.
    ) ;end while.
    (close fl) ;must close file.
    ) ;end progn
    ) ;end if.
    (princ)
    )

    Bill
     
    BillZ, Oct 15, 2004
    #17
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.