Gerard Posted October 26, 2020 Posted October 26, 2020 Hallo,I have a CSV in the format Layer, x, y, z, text.So would like to use the Layer colum to put the text in different layers.Gerard Quote
Lee Mac Posted October 26, 2020 Posted October 26, 2020 Here's a simple example using my Read CSV function: (defun c:txtfromcsv ( / csv des hgt ins itm str sty ) (setq hgt (getvar 'textsize) sty (getvar 'textstyle) ) (cond ( (not (setq csv (getfiled "Select CSV File" "" "csv" 16))) (princ "\n*Cancel*") ) ( (not (setq des (open csv "r"))) (princ "\nUnable to open CSV file for reading.") ) ( t (while (setq str (read-line des)) (setq itm (LM:csv->lst str "," 0)) (if (and (< 3 (length itm)) (snvalid (car itm)) (apply 'and (setq ins (mapcar 'distof (mapcar '(lambda ( a b ) a) (cdr itm) '(0 1 2))))) ) (entmake (list '(000 . "TEXT") (cons 010 ins) (cons 007 sty) (cons 040 hgt) (cons 001 (last itm)) (cons 008 (car itm)) ) ) ) ) (close des) ) ) (princ) ) ;; 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 ) (princ) 1 Quote
Gerard Posted October 27, 2020 Author Posted October 27, 2020 lijnen-test.csv Here is an example file. Text to Cad will work but the Layer settings will not work. Quote
Speedster2 Posted October 31, 2020 Posted October 31, 2020 Tried to add rotate column before text column and I modified the code at entmake output ; error: bad DXF group: (50 . "0.000000000000000") Please help (entmake (list '(000 . "TEXT") (cons 010 ins) (cons 007 sty) (cons 040 hgt) (cons 001 (last itm)) (cons 008 (car itm)) (cons 050 (car (cdr (reverse itm)))) ) ) Quote
Lee Mac Posted October 31, 2020 Posted October 31, 2020 The rotation angle will need to be a numerical value expressed in radians, and so assuming that your text file contains a value in degrees, try: (cons 050 (* pi (/ (atof (cadr (reverse itm))) 180.0))) Quote
Speedster2 Posted November 1, 2020 Posted November 1, 2020 It worked... Thanks for help AutoCAD Genius @Lee Mac 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.