Author Topic: Import Points From CSV File  (Read 3069 times)

0 Members and 1 Guest are viewing this topic.

Ron Heigh

  • Guest
Import Points From CSV File
« on: September 09, 2005, 10:45:59 AM »
Is there any way to create a drawing full of points based a txt file with the x,y,z format?
I have hundreds from our surveyor, and need to recreate them all in AutoCAD.
The format is as follows:
Code: [Select]
0,0,2540.6858
2.75733,0.12301,2541.06505
10.63198,0.08052,2541.87804
19.06206,0.0576,2542.86645

Ron Heigh

  • Guest
Re: Import Points From CSV File
« Reply #1 on: September 09, 2005, 12:36:42 PM »
I got it.
Thanks guys.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Import Points From CSV File
« Reply #2 on: September 09, 2005, 12:47:07 PM »
Darn, too slow again.....
Well, here's a solution anyway.....
Code: [Select]
(defun c:import_pts (/ file ff ln pt_lst)
;;;str2list by John Uhden, as posted to the adesk customization newsgroup
  (defun Str2List (str pat / i j n lst)
    (cond
      ((/= (type str) (type pat) 'STR))
      ((= str pat) '(""))
      (T
       (setq i 0
     n (strlen pat)
       )
       (while (setq j (vl-string-search pat str i))
(setq lst (cons (substr str (1+ i) (- j i)) lst)
       i   (+ j n)
)
       )
       (reverse (cons (substr str (1+ i)) lst))
      )
    )
  )
  ;;*********
  (cond ((not (setq file (getfiled "Select CSV File" "" "" 0)))
(princ "\nMust have a file to use! Try again....")
)
;; cond1
((not (and (setq ff (open file "r"))
   (setq ln (read-line ff))
   (vl-string-search "," ln 0)
      )
)
(princ "\nNot a valid CSV file, try again.....")
)
;;cond2
((while ln
   (setq pt_lst (str2list ln ","))
   (entmake (list '(0 . "POINT")
  (cons 10
(list (atof (car pt_lst))
      (atof (cadr pt_lst))
      (atof (cadr pt_lst))
)
  )
    )
   )
   (setq ln (read-line ff))
)
;;while
(close ff)
)
;;cond3
  )
  (princ)
)

DEVITG

  • Bull Frog
  • Posts: 481
Re: Import Points From CSV File
« Reply #3 on: September 10, 2005, 10:58:55 PM »
I got it.
Thanks guys.


I gues you did it

put point at command line
before you select all your point at the txt file , do a copy
and paste it at the command line when acad promt you to place the point
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Swift

  • Swamp Rat
  • Posts: 596
Re: Import Points From CSV File
« Reply #4 on: September 11, 2005, 09:36:15 PM »
I hope it had point numbers and descriptions included ... if not that will be messy

Peter Jamtgaard

  • Guest
Re: Import Points From CSV File
« Reply #5 on: September 12, 2005, 05:46:54 PM »
Is there any way to create a drawing full of points based a txt file with the x,y,z format?
I have hundreds from our surveyor, and need to recreate them all in AutoCAD.
The format is as follows:
Code: [Select]
0,0,2540.6858
2.75733,0.12301,2541.06505
10.63198,0.08052,2541.87804
19.06206,0.0576,2542.86645

I just thought I would jump in here and share a little code I use for CSV files.

Just FYI

Peter Jamtgaard

Code: [Select]

; Written By: Peter Jamtgaard P.E. copr 2004
; Import a CSV File to a list of Sublists
(defun csvFiletoList (strFilename strChar / lstOfSublists strText z)
 (setq z (open strFilename "r"))
 (while (setq strText (read-line z))
  (setq lstOfSublists (cons (CSVStringToList strText strChar) lstOfSublists))
 )
 (close z)
 (reverse lstOfSublists)
)

; Parsing a textstring to a list.
; Written By: Peter Jamtgaard P.E. copr 2004

(defun CSVStringToList  (strText strChar / intPosition lstStrings)
 (while (setq intPosition (vl-string-search strChar strText 0))
  (setq lstStrings  (cons (substr strText 1 intPosition) lstStrings)
        strText     (substr strText (+ intPosition 1 (strlen strChar)))
  )
 )
 (reverse (cons strText lstStrings))
)