This is just 1st step getting some thing to work next step is to add field values, but I have a problem the sum function is not working, not sure why not, done manually works.
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-can-i-use-the-lisp-fieldobjectsv1-0-with-a-field-in-table/td-p/13004617
; PL area custom table
; BY AlanH Sep 2024
(defun c:plarea ( / )
(defun cmaxstrlen ( l )
(if (apply 'or l)
(cons (apply 'max (mapcar 'strlen (subst "" nil (mapcar 'car l))))
(cmaxstrlen (mapcar 'cdr l))
)
)
)
(defun CreateTableStyle ( / dicts dictobj key class custobj )
;; Get the Dictionaries collection and the TableStyle dictionary
(setq dicts (vla-get-Dictionaries (vla-get-ActiveDocument(vlax-get-acad-object))))
(setq dictObj (vla-Item dicts "acad_tablestyle"))
(setq dname (strcat "table" (rtos txtht 2 0)))
(vlax-for dictname dictobj
(if (= (vlax-get dictname 'name) dname)
(princ "yes")
(progn
;; Create a custom table style
(setq custObj (vla-AddObject dictObj dname "AcDbTableStyle"))
;; Set the name and description for the style
(vla-put-Name custObj dname)
(vla-put-Description custObj (strcat dname " custom table style"))
;; Sets the bit flag value for the style
(vla-put-BitFlags custObj 1)
;; Sets the direction of the table, top to bottom or bottom to top
(vla-put-FlowDirection custObj acTableTopToBottom)
;; Sets the horizontal margin for the table cells
(vla-put-HorzCellMargin custObj (* txtht 0.5))
;; Sets the vertical margin for the table cells
(vla-put-VertCellMargin custObj (* txtht 0.5))
;; Set the alignment for the Data, Header, and Title rows
(vla-SetAlignment custObj (+ acDataRow acHeaderRow acTitleRow) acMiddleCenter)
;; Set the text height for the Title, Header and Data rows
(vla-SetTextHeight custObj acDataRow txtht)
(vla-SetTextHeight custObj acHeaderRow (* txtht 1.2))
(vla-SetTextHeight custObj acTitleRow (* txtht 1.5))
;; Set the text height and style for the Title row
(vla-SetTextStyle custObj (+ acDataRow acHeaderRow acTitleRow) "Standard")
)
)
)
(setvar 'ctablestyle dname)
(princ)
)
(defun AH:maketable ( / )
(command "table" 2 3 (getpoint "\nPick point for table "))
(setq objtable (vlax-ename->vla-object (entlast)))
(vla-Setcolumnwidth objtable 0 4800 )
(vla-Setcolumnwidth objtable 1 2250 )
(vla-settext objtable 0 0 "TABLE title")
(vla-settext objtable 1 0 "layer")
(vla-settext objtable 1 1 "Area m²")
)
(setq ss (ssget '((0 . "LWPOLYLINE"))))
(setq lst '() lenlay 0)
(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(setq objid (rtos (vla-get-objectid obj)))
(setq lay (vlax-get obj 'Layer))
(setq laylen (strlen lay))
(if (< lenlay laylen)(setq lenlay laylen))
(setq lst (cons (list lay objid) lst))
)
(setq lst (vl-sort lst '(lambda (x y) (< (car x)(car y)))))
(setq collst (cmaxstrlen lst))
(setq txtht (getint "\nEnter text height "))
(CreateTableStyle)
(ah:maketable)
(setq rownum 2)
(setq rowht (vla-getrowheight objtable 2))
(foreach val lst
(vla-InsertRows objtable rownum rowht 1)
(setq lay (strcat "%<\\AcObjProp Object(%<\\_ObjId " (cadr val) ">%).Layer>%"))
(setq area (strcat "%<\\AcObjProp Object(%<\\_ObjId " (cadr val) ">%).Area \\f \"%lu2 %ct8[1e-006]\">%"))
(vla-settext objtable rownum 0 lay)
(vla-settext objtable rownum 1 area)
(setq rownum (1+ rownum))
)
(setvar 'luprec 2)
(setq ans (strcat "Total=" "%<\\AcExpr (Sum(B3:B" (RTOS rownum 2 0) ")) \\f \"%lu2 %ct8[1e-006]\">%"))
(vla-settext objtable rownum 1 ans)
(command "regen")
(princ)
)
(c:plarea)
Hoping some one can help sort out sum.