pragadsp Posted December 14, 2022 Posted December 14, 2022 How to export these points from excel to autocad? Quote
BIGAL Posted December 15, 2022 Posted December 15, 2022 1 need the xl file 2 need a explanation as to what the values mean, are the XY twice meaning a LINE ? Quote
Emmanuel Delay Posted December 15, 2022 Posted December 15, 2022 (edited) You want to draw lines with those coordinates, right? -To make it easy, save the Excel file as csv (3 line sample in attachment here) - top of the script, make sure the settings of the file match (this can be handled with open file dialog if needed) - I just take the coordinates and ignore all other columns. type command IMC (for Import Lines Csv) I call it import, from the point of view of Autocad. (vl-load-com) ;; SETTINGS ;; you need to set this to the path and filename on your computer (setq csv_file "C:\\Data\\desktop\\lisp\\CADTUTOR\\import_lines_csv.csv") ;; delimitor. Check how Excel saves the file to CSV. Either comma or somicolon (setq csvdelimiter ",") ;;(setq csvdelimiter ";") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; http://www.lee-mac.com/readcsv.html ;; Read CSV - Lee Mac ;; Parses a CSV file into a matrix list of cell values. ;; csv - [str] filename of CSV file to read (defun LM:readcsv ( csv / des lst sep str ) (if (setq des (open csv "r")) (progn (setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) (csvdelimiter))) (while (setq str (read-line des)) (setq lst (cons (LM:csv->lst str sep 0) lst)) ) (close des) ) ) (reverse lst) ) ;; CSV -> List - Lee Mac ;; Parses a line from a CSV file into a list of cell values. ;; str - [str] string read from CSV file ;; sep - [str] CSV separator token ;; pos - [int] initial position index (always zero) (defun LM:csv->lst ( str sep pos / s ) (cond ( (not (setq pos (vl-string-search sep str pos))) (if (wcmatch str "\"*\"") (list (LM:csv-replacequotes (substr str 2 (- (strlen str) 2)))) (list str) ) ) ( (or (wcmatch (setq s (substr str 1 pos)) "\"*[~\"]") (and (wcmatch s "~*[~\"]*") (= 1 (logand 1 pos))) ) (LM:csv->lst str sep (+ pos 2)) ) ( (wcmatch s "\"*\"") (cons (LM:csv-replacequotes (substr str 2 (- pos 2))) (LM:csv->lst (substr str (+ pos 2)) sep 0) ) ) ( (cons s (LM:csv->lst (substr str (+ pos 2)) sep 0))) ) ) (defun LM:csv-replacequotes ( str / pos ) (setq pos 0) (while (setq pos (vl-string-search "\"\"" str pos)) (setq str (vl-string-subst "\"" "\"\"" str pos) pos (1+ pos) ) ) str ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun drawLine (p1 p2) (entmakex (list (cons 0 "LINE") (cons 10 p1) (cons 11 p2))) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; IMC for Import Lines Csv (defun c:IMC ( / csv_data i a) (setq csv_data (LM:readcsv csv_file)) (setq i 0) (foreach a csv_data ;; a is 1 line of the csv data (if (> i 0) (progn ;; Skip the first line that holds the title of the columns (drawLine (list (atof (nth 0 a)) (atof (nth 1 a)) (atof (nth 4 a)) ) (list (atof (nth 2 a)) (atof (nth 3 a)) (atof (nth 5 a)) ) ) )) (setq i (+ i 1)) ) (princ) ) import_lines_csv.csv Edited December 15, 2022 by Emmanuel Delay 1 Quote
pragadsp Posted December 15, 2022 Author Posted December 15, 2022 thanks for the reply but i need to draw a line with angle. Quote
BIGAL Posted December 15, 2022 Posted December 15, 2022 Please answer my two questions. Then we can help. You have more values than just a pt angle and distance is this in your other post ? Quote
pragadsp Posted December 15, 2022 Author Posted December 15, 2022 I have starting point of line x and y, the angle and its span of length. Quote
BIGAL Posted December 16, 2022 Posted December 16, 2022 YEAH BUT WHICH VARIABLES ! You have 8 columns in the image. It may be a language problem but your not explaining what to use, the answer is so simple. Quote
pragadsp Posted December 16, 2022 Author Posted December 16, 2022 X and y are the coordinates or starting point of line, from there the line has to travel in an angle of 270 degree for a length if 10m Quote
Emmanuel Delay Posted December 16, 2022 Posted December 16, 2022 (edited) Alright. Same as last code, but now with polar coordinates. command IMCP for Import Lines Csv Polar Again, change the path settings. I now call it "import_lines_csv_polar.csv", see attachment (vl-load-com) ;; SETTINGS ;; you need to set this to the path and filename on your computer ;;(setq csv_file "C:\\Data\\desktop\\lisp\\CADTUTOR\\import_lines_csv.csv") (setq csv_file "C:\\Data\\desktop\\lisp\\CADTUTOR\\import_lines_csv_polar.csv") ;; delimitor. Check how Excel saves the file to CSV. Either comma or somicolon (setq csvdelimiter ",") ;;(setq csvdelimiter ";") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; http://www.lee-mac.com/readcsv.html ;; Read CSV - Lee Mac ;; Parses a CSV file into a matrix list of cell values. ;; csv - [str] filename of CSV file to read (defun LM:readcsv ( csv / des lst sep str ) (if (setq des (open csv "r")) (progn (setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) (csvdelimiter))) (while (setq str (read-line des)) (setq lst (cons (LM:csv->lst str sep 0) lst)) ) (close des) ) ) (reverse lst) ) ;; CSV -> List - Lee Mac ;; Parses a line from a CSV file into a list of cell values. ;; str - [str] string read from CSV file ;; sep - [str] CSV separator token ;; pos - [int] initial position index (always zero) (defun LM:csv->lst ( str sep pos / s ) (cond ( (not (setq pos (vl-string-search sep str pos))) (if (wcmatch str "\"*\"") (list (LM:csv-replacequotes (substr str 2 (- (strlen str) 2)))) (list str) ) ) ( (or (wcmatch (setq s (substr str 1 pos)) "\"*[~\"]") (and (wcmatch s "~*[~\"]*") (= 1 (logand 1 pos))) ) (LM:csv->lst str sep (+ pos 2)) ) ( (wcmatch s "\"*\"") (cons (LM:csv-replacequotes (substr str 2 (- pos 2))) (LM:csv->lst (substr str (+ pos 2)) sep 0) ) ) ( (cons s (LM:csv->lst (substr str (+ pos 2)) sep 0))) ) ) (defun LM:csv-replacequotes ( str / pos ) (setq pos 0) (while (setq pos (vl-string-search "\"\"" str pos)) (setq str (vl-string-subst "\"" "\"\"" str pos) pos (1+ pos) ) ) str ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun drawLine (p1 p2) (entmakex (list (cons 0 "LINE") (cons 10 p1) (cons 11 p2))) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun deg2rad (deg /) (* (/ deg 180) pi) ) ;; IMC for Import Lines Csv Polar (defun c:IMCP ( / csv_data i a p1 p2) ;; reset if needed (setq csv_data (list)) (setq csv_data (LM:readcsv csv_file)) ;;(princ (nth 0 csv_data)) (setq i 0) (foreach a csv_data ;; a is 1 line of the csv data (if (> i 0) (progn ;; Skip the first line that holds the title of the rows (drawLine (setq p1 (list (atof (nth 2 a)) (atof (nth 3 a)) )) ;;(polar pt ang dist) (polar p1 (deg2rad (atof (nth 1 a))) (atof (nth 0 a))) ) )) (setq i (+ i 1)) ) (princ) ) import_lines_csv_polar.csv Edited December 16, 2022 by Emmanuel Delay Quote
devitg Posted December 16, 2022 Posted December 16, 2022 It seem to be the same post here line at angle from x y value Quote
mhupp Posted December 16, 2022 Posted December 16, 2022 If you have the start and end points you dont need length and angle. Quote
pragadsp Posted December 16, 2022 Author Posted December 16, 2022 DO YOU HAVE ANY FORMULA FOR COMBINING THESE TWO? Quote
BIGAL Posted December 17, 2022 Posted December 17, 2022 I agree with devitg is it a case of 2 people from 1 company ? Look at other post. Quote
pragadsp Posted December 17, 2022 Author Posted December 17, 2022 Thank you everyone. We have sorted it out Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.