As part of my preparing an AutoCAD drawing for my office’s layering system I managed to insert layers into a drawing from Excel using only scripting.
However the creation of a line and a text on each of the layers, so that users can copy and paste to get the layers etc. into new drawings, needed full AutoCAD and its access to LISP to create these quickly.
The script below is a modified (larger text and longer lines) version of a script, kindly written, from here.
(defun c:lintextfromlayer (/ pt dat ln)
(setq pt (getpoint “\nSelect insertion point: “))
(while (setq dat (tblnext “layer” (null dat)))
(entmake (list ‘(0 . “line”) (cons 10 pt) (cons 11 (mapcar ‘+ pt ‘(5000 0 0))) (cons 8 (setq ln (cdr (assoc 2 dat))))))
(entmake (list ‘(0 . “text”) (cons 10 (mapcar ‘+ pt ‘(5200 -125 0))) ‘(40 . 250) (cons 1 ln) (cons 8 ln)))
(setq pt (mapcar ‘- pt ‘(0 1000 0))))
(princ))