Lisp: Total Area Autocad
This LISP routine provides a complete solution for calculating total area from multiple selected objects in AutoCAD.
Calculating total areas in AutoCAD often involves a tedious "add one by one" process with the native
command. AutoLISP routines automate this by summing multiple objects instantly and even exporting results to tables or Excel. Popular LISP Commands for Total Area
Different routines offer various levels of automation, from simple command-line totals to complex reporting:
: A widely used routine (often attributed to Jimmy Bergmark) that calculates the total area of all selected objects at once. It works on polylines, circles, ellipses, and splines. A2F (Area to Field)
: Creates an MText object containing a dynamic "Field Expression". If you modify the original shapes, the total area updates automatically after a AMO (Add Multiple Objects) total area autocad lisp
: Measures total area and automatically places text indicating the area at the centroid of each individual polygon. Area Table (AT)
: Calculates areas for multiple plots and automatically generates a structured AutoCAD table. RTR (Read Triangle Area)
: For detailed surveying, this command splits polygons into triangles and provides a table showing the calculation for each. Autodesk Community, Autodesk Forums, Autodesk Forum Core Logic: How the LISP Works
Most total area LISPs follow a similar logic structure to process multiple selections: Lisp to calculate area of all closed polylines selected 02-Apr-2019 —
Calculating the total area of multiple objects in AutoCAD can be done using various built-in features or custom AutoLISP routines. This LISP routine provides a complete solution for
While AutoCAD's native AREA command allows for "Add Area" functionality, it can be tedious for large numbers of objects. Below are the best ways to achieve a complete "Total Area" feature. 1. Built-in "Quick" Methods (No LISP Required)
Hatch Method: Select all closed areas and apply a single hatch. The Properties Palette (Ctrl+1) will display the cumulative area of all selected hatches as a single value.
Quick Measure: Use the MEASUREGEOM command and select the "Quick" or "Area" option. You can hold Shift while clicking in various closed areas to see a running cumulative total for area and perimeter.
Properties Palette: For multiple closed polylines, simply selecting them all and checking the "Area" field in the Properties palette will often show "Varies" for individual values, but some versions/plug-ins may sum them. 2. Specialized AutoLISP Routines
For a more automated experience, you can load these specific scripts: Lisp to calculate area of all closed polylines selected Introduction: The Pain Point of Polyline Area Calculation
;; ============================================================
;; TOTAL AREA.LSP
;; Command: TA
;; Purpose: Calculate and display total area of selected objects
;; Supports: Circles, Arcs, Ellipses, Polylines, Regions, Hatches, Splines
;; ============================================================
(defun C:TA ( / ss ent obj area total cnt)
;; Set area units precision (adjust as needed)
(setq prec 2) ; decimal places
;; Initialize total area
(setq total 0.0)
(setq cnt 0)
;; Prompt user to select objects
(prompt "\nSelect objects to calculate total area: ")
(setq ss (ssget '((0 . "CIRCLE,ARC,ELLIPSE,LWPOLYLINE,POLYLINE,REGION,HATCH,SPLINE"))))
;; If selection set exists
(if ss
(progn
;; Loop through each object in selection set
(repeat (setq i (sslength ss))
(setq ent (ssname ss (setq i (1- i))))
(setq obj (vlax-ename->vla-object ent))
;; Check if object has Area property
(if (vlax-property-available-p obj "Area")
(progn
(setq area (vla-get-area obj))
(setq total (+ total area))
(setq cnt (1+ cnt))
)
(prompt (strcat "\nSkipped: " (cdr (assoc 0 (entget ent))) " - No area property"))
)
)
;; Display results
(princ "\n========================================")
(princ (strcat "\nTotal Area of " (itoa cnt) " object(s):"))
(princ "\n----------------------------------------")
;; Show in current drawing units
(princ (strcat "\nSquare units: " (rtos total 2 prec)))
;; Convert to common units (optional - adjust conversion factor)
;; For meters to square meters: no change
;; For millimeters to square meters: divide by 1e6
;; For inches to square feet: divide by 144
;; For feet to square feet: no change
;; Example: If drawing units are millimeters, show square meters
;; (princ (strcat "\nSquare meters: " (rtos (/ total 1000000.0) 2 prec)))
;; Example: If drawing units are inches, show square feet
;; (princ (strcat "\nSquare feet: " (rtos (/ total 144.0) 2 prec)))
(princ "\n========================================")
;; Optional: Add text to drawing
(if (yes-or-no-p "\nAdd total area text to drawing? ")
(insert-area-text total)
)
)
(prompt "\nNo valid objects selected!")
)
(princ)
)
;; Helper function to insert total area as text in drawing
(defun insert-area-text (area / pt)
(setq pt (getpoint "\nPick insertion point for text: "))
(if pt
(entmake
(list
'(0 . "TEXT")
'(100 . "AcDbEntity")
'(100 . "AcDbText")
(cons 10 pt)
(cons 40 (getvar 'TEXTSIZE))
(cons 1 (strcat "Total Area: " (rtos area 2 2) " sq units"))
'(50 . 0.0)
'(7 . "Standard")
'(72 . 0)
'(73 . 0)
)
)
)
)
;; Alternative: Quick total area with selection window
(defun C:TAQ ( / ss total area obj)
(setq ss (ssget '((0 . "CIRCLE,ARC,ELLIPSE,LWPOLYLINE,POLYLINE,REGION,HATCH"))))
(setq total 0.0)
(if ss
(repeat (setq i (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
(if (vlax-property-available-p obj "Area")
(setq total (+ total (vla-get-area obj)))
)
)
)
(princ (strcat "\nTotal Area = " (rtos total 2 2)))
(princ)
)
;; Alternative: Area of polylines only (with option for multiple selections)
(defun C:TAP ( / ss total)
(setq ss (ssget '((0 . "LWPOLYLINE,POLYLINE"))))
(setq total 0.0)
(if ss
(repeat (setq i (sslength ss))
(setq total (+ total (vla-get-area (vlax-ename->vla-object (ssname ss (setq i (1- i)))))))
)
)
(princ (strcat "\nTotal Polyline Area = " (rtos total 2 2)))
(princ)
)
;; Helper function to check if object has area property
(defun vlax-property-available-p (obj prop)
(not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-get-property (list obj prop))))
)
;; Load command
(princ "\nTotal Area LISP loaded successfully!")
(princ "\nType 'TA' to calculate total area of selected objects")
(princ "\nType 'TAQ' for quick total area")
(princ "\nType 'TAP' for total area of polylines only")
(princ)
;; Make commands available
(autoload "C:TA" '("TA"))
(autoload "C:TAQ" '("TAQ"))
(autoload "C:TAP" '("TAP"))
Introduction: The Pain Point of Polyline Area Calculation
For architects, civil engineers, and interior designers, calculating the total area of multiple spaces is a daily, yet tedious, task. AutoCAD’s native AREA command is powerful for single objects, but what happens when you need the combined square footage of 50 apartments on a floor plan, or 200 different lawn sections in a landscape master plan?
Manually adding each area using a calculator is not only slow but also prone to human error. This is where the magic of AutoLISP comes in. A well-written "Total Area Lisp" routine can instantly sum the areas of selected objects (polylines, circles, hatches, or regions) and present the result in your desired unit—square feet, meters, or even acres.
In this article, we will explore what a "Total Area Lisp" is, how to install and use the most popular routine (TOTAREA), how to modify it to display totals in different units, and how to troubleshoot common errors.
That small script saves me 5–10 minutes every day. Over a year? That’s nearly 40 hours of not re-clicking and re-adding.
More importantly: I never second-guess my area totals again. No manual math errors. No missing a polyline behind a hatch.