;; LyrTbl creates a Table listing Layer names, color, linetype & lineweight ;; OP: ; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-count-layer-name-and-its-area-in-table-format/m-p/12440430#M458944 (defun c:LyrTbl ( / AllData Layer_table cellht cellwd choice clr crow fname get_laylst lwt lyr_v15_sort str txtht) (vl-load-com) (setq fname "LAYER PROPERTIES TABLE") ; Table Title ; (setq fname(vl-filename-base (getvar "dwgname"))) ; Table Title matches dwg file name (setq txtht 10) ;; Change all '500' to this (setq cellht (* 3 txtht)) ;; Change all 1500 to this (setq cellwd (* 14 txtht)) ;; Change 7000 to this ; lyr_v15_sort list (defun lyr_v15_sort (lst-arg / tmp) (setq tmp (vl-sort lst-arg '(lambda (a b) (< (strcase a) (strcase b))))) tmp ) ; defun lyr_v15_sort list ; get_laylst builds layer list ; Argument: ; opt = determines what layers to include "In-Use": only layers with objects otherwise all layers (defun get_laylst (opt / lyr lyrname tmp) (while (setq tmp (tblnext "LAYER" (not tmp))) (setq lyrname (cdr (assoc 2 tmp))) (if (eq opt "In-Use" ) (if(ssget"_X" (list (cons 8 lyrname))) (setq lyr (cons lyrname lyr)) ) ; if (setq lyr (cons lyrname lyr)) ) ; if ) ; while (if lyr (setq lyr (lyr_v15_sort lyr))) lyr ) ; defun get_laylst ; ; main program ; (if(not **lyrtbl**)(setq **lyrtbl** "All")) (initget "All In-Use") (setq choice (getkword (strcat "\nCreate Table of Layers [All/In-Use] <" **lyrtbl** ">: "))) (if(not choice)(setq choice **lyrtbl**)) (setq **lyrtbl** choice) (if(setq AllData (get_laylst **lyrtbl**)) ; create list of all layers in dwg (progn (setq Layer_table ; add a table object (vlax-invoke (vlax-get (vla-get-ActiveLayout (vla-get-activedocument (vlax-get-acad-object)) ) 'Block ) 'Addtable (getpoint "\nPick point for Layer Properties Table:") 2 4 cellht cellwd ; with 4 columns ) ) (vla-settext Layer_table 0 0 fname) ; set header name (vla-setcelltextheight Layer_table 0 0 txtht) (mapcar '(lambda (y) (vla-settext Layer_table 1 (car y) (cadr y)) (vla-setcelltextheight Layer_table 1 (car y) txtht) ; second row text height ) (list '(0 "LAYER NAME") '(1 "COLOR") '(2 "LINETYPE") '(3 "LINEWEIGHT")) ; column headings ) ; begin filling out rest of table with layer properties (foreach d AllData (vla-insertrows Layer_table (1+ (setq crow (vla-get-rows Layer_table))) cellht ; cell height for rest of rows 1 ) (vla-setCellValue Layer_table crow 0 d) ; fill Layer name (vla-setcelltextheight Layer_table crow 0 txtht) (vla-setCellAlignment Layer_table crow 0 5) (setq x(strcat "AutoCAD.AcCmColor." (substr (getvar 'Acadver) 1 2))) ; set Color markers (setq clr (vlax-create-object x)) (vla-put-colorindex clr (cdr (assoc 62 (tblsearch "LAYER" d)))) ; get layer Color (vla-SetCellBackgroundColor Layer_table crow 1 clr) ; fill color (vla-setcellcontentcolor Layer_table crow 1 clr) ; text color (vla-setCellValue Layer_table crow 2 (cdr (assoc 6 (tblsearch "LAYER" d)))) ; fill Linetype (vla-setcelltextheight Layer_table crow 2 txtht) (vla-setCellAlignment Layer_table crow 2 5) (setq lwt (cdr (assoc 370 (entget (tblobjname "LAYER" d))))) ; get lineweight (if (eq lwt -3) (setq lwt "Default") (setq lwt (strcat (rtos (* lwt 0.01) 2 2) " mm")) ) (vla-setCellValue Layer_table crow 3 lwt) ; fill Lineweight (vla-setcelltextheight Layer_table crow 3 txtht) (vla-setCellAlignment Layer_table crow 3 5) ) ; foreach ) ; progn (alert(strcat"There Are No Layers " **lyrtbl**)) ) ; if (princ) ; clean exit ) ; defun