Need help working out something in a lisp routine.

Need help working out something in a lisp routine.

q_Q25S5
Participant Participant
572 Views
6 Replies
Message 1 of 7

Need help working out something in a lisp routine.

q_Q25S5
Participant
Participant

Hi, i currently have a problem where i have a csv file with 2 locations (start and end point). 
What i need is a quick lisp fix to draw a line between these 2 points, and for it to place a specific block on point A and B.

 

I also have attached a test file for the CSV and DWG

Thanks for your help in advance!

0 Likes
Accepted solutions (1)
573 Views
6 Replies
  • Lisp
Replies (6)
Message 2 of 7

Moshe-A
Mentor
Mentor

@q_Q25S5  hi,

 

it would more easy\simple if the csv file format would have each piece of data in seperate coulmn

 

pt name |   X    |  Y   |  Z  | other data (like start\end)

 

is this possible?

 

Moshe

 

 

0 Likes
Message 3 of 7

q_Q25S5
Participant
Participant

@Moshe-A This will be a bit difficult since this is the setup we work with a lot..
i did try to simplify the file a little.

0 Likes
Message 4 of 7

Moshe-A
Mentor
Mentor

formating the file is for your own good.

 

if you search this forum you will find alot of examples how to read from csv file (which is simple text file)

and draw lines\plines or insert some blocks from it.

 

Moshe

 

0 Likes
Message 5 of 7

Moshe-A
Mentor
Mentor

 

here is one from great LEE MAC 

0 Likes
Message 6 of 7

CADaSchtroumpf
Advisor
Advisor
Accepted solution

Quick and dirty with your DWG and CSV

To be adapted if necessary...

(defun c:readCSV ( / )
  (setvar "ATTDIA" 0)
  (setvar "ATTREQ" 0)
  (setvar "CMDECHO" 0)
  (setq
    input (getfiled "Select a CSV file" "" "csv" 2)
    f_open (open input "r")
  )
  (setq l_read (read-line f_open))
  (while (setq l_read (read-line f_open))
    (setq txt1 (substr l_read 1 (vl-string-position 59 l_read)))
    (setq l_read (substr l_read (+ 2 (vl-string-position 59 l_read))))
    (setq x1_data (atof (substr l_read 1 (vl-string-position 59 l_read))))
    (setq l_read (substr l_read (+ 2 (vl-string-position 59 l_read))))
    (setq y1_data (atof (substr l_read 1 (vl-string-position 59 l_read))))
    (setq l_read (substr l_read (+ 2 (vl-string-position 59 l_read))))
    (setq txt2 (substr l_read 1 (vl-string-position 59 l_read)))
    (setq l_read (substr l_read (+ 2 (vl-string-position 59 l_read))))
    (setq x2_data (atof (substr l_read 1 (vl-string-position 59 l_read))))
    (setq l_read (substr l_read (+ 2 (vl-string-position 59 l_read))))
    (setq y2_data (atof (substr l_read 1 (vl-string-position 59 l_read))))
    (setq l_read (substr l_read (+ 2 (vl-string-position 59 l_read))))
    (setq dist (atof (substr l_read 1 (vl-string-position 59 l_read))))
    (setq l_read (substr l_read (+ 2 (vl-string-position 59 l_read))))
    (setq nam_blk (substr l_read 1 (vl-string-position 59 l_read)))
    (setq new_pt1 (list x1_data y1_data))
    (setq new_pt2 (list x2_data y2_data))
    (if (eq nam_blk "Startpunt") (setq nam_blk "well"))
    (command "_.layer" "_set" "B-WE-RI-DWA_RIOOLPUT_INSPECTIEPUT-S" "")
    (if (eq nam_blk "leak")
      (command "_.-insert" nam_blk "_none" new_pt1 1.0 0.0 "_.-insert" nam_blk "_none" new_pt2 1.0 0.0 )
      (command "_.-insert" nam_blk "_none" new_pt1 1.0 1.0 0.0 "_.-insert" nam_blk "_none" new_pt2 1.0 1.0 0.0)
    )
    (command "_.line" "_none" new_pt1 "_none" new_pt2 "")
    (command "_.layer" "_set" "04-PUT-PUTNUMMER" "")
    (command "_.text" "_none" new_pt1 0.0 txt1)
    (command "_.text" "_none" new_pt2 0.0 txt2)
  )
  (close f_open)
  (setvar "ATTDIA" 1)
  (setvar "ATTREQ" 1)
  (setvar "CMDECHO" 1)
  (prin1)
)
0 Likes
Message 7 of 7

q_Q25S5
Participant
Participant
Thank you! This worked perfectly.
0 Likes