Okay, you can type the layer, or layers now.
comma separated, for example Layer1 or Layer1,Layer2
;; @FILE export texts. contents, insert point, layer
(vl-load-com)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Exporting to csv
;; http://www.lee-mac.com/writecsv.html
;; Write CSV - Lee Mac
;; Writes a matrix list of cell values to a CSV file.
;; lst - [lst] list of lists, sublist is row of cell values
;; csv - [str] filename of CSV file to write
;; Returns T if successful, else nil
(defun LM:WriteCSV ( lst csv / des sep )
(if (setq des (open csv "w"))
(progn
(setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) (",")))
(foreach row lst (write-line (LM:lst->csv row sep) des))
(close des)
t
)
)
)
;; List -> CSV - Lee Mac
;; Concatenates a row of cell values to be written to a CSV file.
;; lst - [lst] list containing row of CSV cell values
;; sep - [str] CSV separator token
(defun LM:lst->csv ( lst sep )
(if (cdr lst)
(strcat (LM:csv-addquotes (car lst) sep) sep (LM:lst->csv (cdr lst) sep))
(LM:csv-addquotes (car lst) sep)
)
)
(defun LM:csv-addquotes ( str sep / pos )
(cond
( (wcmatch str (strcat "*[`" sep "\"]*"))
(setq pos 0)
(while (setq pos (vl-string-position 34 str pos))
(setq str (vl-string-subst "\"\"" "\"" str pos)
pos (+ pos 2)
)
)
(strcat "\"" str "\"")
)
( str )
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Command ET, for Extract Text
(defun c:ET ( / ss i rows ent filepath layers)
;; Select the text objects
(setq layers (getstring "\nLayers to extract, example Layer1,Layer2 : "))
(setq ss (ssget "X" (list (cons 0 "TEXT") (cons 8 layers) )))
;;;; Or maybe you also want MTEXT, then you replace "TEXT" with "TEXT,MTEXT"
;;;; notice: Mtext encodes "new line" as "\P", and may also contain code for style (like color, bold...)
;; the head (column titles) of the CSV. You coule leave this blank, like this: (setq rows (list))
(setq rows (list (list "LAYER" "X" "Y" "ROTATION" "TEXT")))
;; read the data, put it in a list (in variable rows)
(setq i 0)
(repeat (sslength ss)
(setq ent (entget (ssname ss i))) ;; extract the properties
;; add the data to rows
(setq rows (append rows (list (list
(cdr (assoc 8 ent)) ;; Layer
(rtos (nth 0 (cdr (assoc 10 ent))) 2 16) ;; X value, notice: numbers must be converted to text, that's what the rtos does. Feel free to change the precision (the 16)
(rtos (nth 1 (cdr (assoc 10 ent))) 2 16) ;; Y value
(rtos (/ (* (cdr (assoc 50 ent)) 180) pi ) 2 16) ;; rotation - ("angle in rad" * 180 / pi) = angle in 360 degrees
(cdr (assoc 1 ent)) ;; Text contents
))))
(setq i (+ i 1))
)
;; we'll save the file in the same path, and same file name as the dwg, except with extension .csv
;; (make sure the drawing is saved somewhere, and make sure that location is writable)
(setq filepath (strcat (getvar "dwgprefix") (vl-filename-base (getvar "dwgname")) ".csv"))
;; save to csv
(if
(LM:WriteCSV rows filepath)
(progn (princ "\nSaved as: ") (princ filepath))
(progn (princ "\nSomething went wrong"))
)
(princ)
)