Author Topic: Solved- repeat a lisp with cvs data  (Read 278 times)

0 Members and 1 Guest are viewing this topic.

nekonihonjin

  • Newt
  • Posts: 47
Solved- repeat a lisp with cvs data
« on: August 03, 2022, 09:25:08 PM »
Hi guys, I have this poorly made code that I use to create a borehole by entering its start coordinates along with its dip, azimuth and length.
Code: [Select]
(defun C:bno(/ line prof )
(setq rad (getreal "\nRadius: "))
(setq romp (getstring "\n Start coordinates X,Y,Z: "))
(setq incl (getstring "\n dip: "))
(setq azim (getreal "\n Azimuth: "))
(setq prof (getstring "\n depth: "))
(setq angul (+ (* azim -1.0 ) 90.0 ))
(setq direc (strcat "@" prof "<" (rtos angul 2 4) "<" incl))
(command "_line" romp direc "")
(setq line (entlast))
(command "_circle" "0,0,0" rad)
(setq prof (entlast))
(command "_sweep" "_MO" "_SO" prof "" line)
(command "_erase" prof "" "")
(princ)
)

I find it useful when it is just one or a few, but I would like to be able to use it to read a CSV file with a long list of boreholes and be able to display them in autocad.

I took a look at LeeMac's Read CSV, but I don't know enough to know how to extract the information from the list and use it for drawing.

« Last Edit: August 04, 2022, 10:08:19 PM by nekonihonjin »

BIGAL

  • Swamp Rat
  • Posts: 1037
  • 40 + years of using Autocad
Re: repeat a lisp with cvs data
« Reply #1 on: August 03, 2022, 10:13:11 PM »
The obvious is what your csv file looks like. This sub routine pulls the csv line apart into individual elements, note for excel it may be 44 for "," and 59 for ";".

Then you make the variables using say (setq X (nth 0 lst) y (nth 1 lst) Z (nth 2 lst) ...........)

Code: [Select]
; thanks to Lee-mac for this defun
; www.lee-mac.com
; 44 is comma 32 is space
(defun _csv->lst ( str / pos )
(if (setq pos (vl-string-position 44 str))
(cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2))))
(list str)
    )
)


(setq fo (open "c:\\acadtemp\\bore.csv" "R"))
(setq lst '())
(while (setq nline (read-line fo))
  (setq lst (cons (_csv->lst nline) lst))
)
(close fo)

Look at lst use !lst
A man who never made a mistake never made anything

nekonihonjin

  • Newt
  • Posts: 47
Re: repeat a lisp with cvs data
« Reply #2 on: August 04, 2022, 02:28:07 AM »
Thanks for the tips Bigal

it's more or less done,

What should I do to insert the first column (HOLEID) as a text near the starting coordinates (in the correct Z elevation)?


Code: [Select]
; thanks to Lee-mac for this defun
; www.lee-mac.com
; 44 is comma 32 is space
(defun _csv->lst ( str / pos )
(if (setq pos (vl-string-position 44 str))
(cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2))))
(list str)
    )
)

(defun C:bno(/ data file)
(setq rad (getreal "\nRadius: "))


(setq fo (open (getfiled "Select CSV File" "" "csv" 16) "R"))
(setq lst '())
(while (setq nline (read-line fo))
    (setq lst (cons (_csv->lst nline) lst))
          (setq lst (nth 0 lst))

         (setq ID (nth 0 lst) X (nth 1 lst) Y (nth 2 lst) Z (nth 3 lst) prof (nth 4 lst) incl (nth 5 lst) azim (nth 6 lst))
         
         (setq romp (strcat X "," Y "," Z))
         (setq angul (+ (* (atof azim) -1.0 ) 90.0 ))
         (setq direc (strcat "@" prof "<" (rtos angul 2 4) "<" incl))
         (command "_line" romp direc "")
         (setq 3dline (entlast))
         (command "_circle" "0,0,0" rad)
         (setq profile (entlast))
         (command "_sweep" "_MO" "_SO" profile "" 3dline)
     
)


(princ)
)



I also attach the CSV file
« Last Edit: August 04, 2022, 02:37:08 PM by nekonihonjin »

BIGAL

  • Swamp Rat
  • Posts: 1037
  • 40 + years of using Autocad
Re: repeat a lisp with cvs data
« Reply #3 on: August 04, 2022, 07:58:01 PM »
Very easy

Code: [Select]
(setq id (nth 0 lst)
x (nth 1 lst)
y (nth 2 lst)
z (nth 3 lst)
)

(command "text" (list x y z) "" 0.0 id) ; this depends on you text style if height is set or not.

Oh yeah do a dummy (princ (read-line)) at start to read the header then start the (while (read-line

A man who never made a mistake never made anything

nekonihonjin

  • Newt
  • Posts: 47
Re: repeat a lisp with cvs data
« Reply #4 on: August 04, 2022, 09:49:51 PM »
Perfect!  thanks a lot!