Total Area Autocad Lisp
Mastering the "Total Area" in AutoCAD: The Ultimate Guide to Lisp Routines
Introduction: The Pain Point of Polyline Area Calculation
(princ "\n----------------------------------------") (princ (strcat "\nTOTAL AREA: " (rtos total-area 2 2) " sq units"))Customization:
Change precision by modifying the prec variable (line ~15): total area autocad lisp
The code (yes, you can copy this)
Save this as TOTALAREA.LSP and load it with APPLOAD: Mastering the "Total Area" in AutoCAD: The Ultimate
Advanced Total Area LISP: With Unit Conversion and Annotations
For professional work, you need more. Let me walk you through a more robust routine called AT (Add Total) that is popular among surveyors and architects. If your drawing units are millimeters and you
Example: set output to square meters (if drawing units are mm)
- If your drawing units are millimeters and you want m², set: scale = 1e-6
Sample Advanced Code Snippet (Conversion to Acres)
(defun C:AT ( / ss area_list total sf)
(setq sf (getreal "\nConversion factor (1 drawing unit = ? feet): "))
(if (= sf nil) (setq sf 1.0))
(setq ss (ssget '((0 . "LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE,REGION"))))
(if ss
(progn
(setq total 0.0)
(repeat (setq i (sslength ss))
(setq ent (ssname ss (setq i (1- i))))
(setq area (vlax-curve-getArea ent))
(setq total (+ total area))
)
(setq total_sqft (* total sf sf))
(setq total_acres (/ total_sqft 43560.0))
(alert (strcat "Total Area: " (rtos total_acres 2 2) " Acres"))
;; Optional: Insert text
(command "_.MTEXT" (getpoint "\nPick text insertion point: ") "J" "TL" "W" "0" (strcat "TOTAL AREA = " (rtos total_acres 2 2) " ACRES") "")
)
(princ "\nNo objects selected.")
)
(princ)
)