If you have ever had to calculate the total carpet area of a floor plan consisting of 50 separate rooms, you know the pain. Without a Lisp routine, you have three bad options:
An advanced LISP can extract area and a text attribute (e.g., room number) and output to a CSV file. This is getting into territory of full AutoLISP programming with file writing.
Modify the routine to exclude hatched areas representing voids, or to sum only polylines on layer "A-FLOR-SEAL".
This Visual LISP function works on any curve and returns a real number. total area autocad lisp
Copy the following text exactly into a blank Notepad file. Save it with the name TOTAREA.LSP (ensure the extension is .lsp, not .txt).
;;; TOTAREA.LSP - Calculate total area of selected objects ;;; Command: TOTAREA ;;; Supports: LWPOLYLINE, CIRCLE, ELLIPSE, SPLINE, REGION, HATCH(defun C:TOTAREA ( / ss total area obj_name obj_list i ent) (princ "\nSelect objects to calculate total area: ")
;; Step 1: Create a selection set (setq ss (ssget '((0 . "LWPOLYLINE,CIRCLE,ELLIPSE,SPLINE,REGION,HATCH")))) If you have ever had to calculate the
;; Step 2: Exit if nothing is selected (if (null ss) (princ "\nNo valid objects selected.") (progn (setq total 0.0) ; Initialize total to zero (setq i 0) ; Initialize counter
;; Step 3: Loop through each object in the selection set (repeat (sslength ss) (setq ent (ssname ss i)) ; Get entity name (setq obj_name (cdr (assoc 0 (entget ent)))) ; Get object type ;; Step 4: Calculate area based on object type (cond ;; For Polylines, Circles, Ellipses, Splines ((member obj_name '("LWPOLYLINE" "CIRCLE" "ELLIPSE" "SPLINE")) (command "_.AREA" "_Object" ent) (setq area (getvar "AREA")) ) ;; For Regions ((equal obj_name "REGION") (setq area (vla-get-area (vlax-ename->vla-object ent))) ) ;; For Hatches ((equal obj_name "HATCH") (setq area (vla-get-area (vlax-ename->vla-object ent))) ) ) ;; Step 5: Add area to total (if area (setq total (+ total area)) (princ (strcat "\nWarning: Could not compute area for object " (itoa i))) ) (setq i (1+ i)) ; Increment counter (setq area nil) ; Reset area variable ) ; end repeat ;; Step 6: Display the result (princ "\n=========================================") (princ (strcat "\n>>> TOTAL AREA: " (rtos total 2 2) " square units <<<")) (princ "\n=========================================") ) ; end progn
) ; end if (princ) ; Clean exit )
This version shows your total in Square Meters and Square Feet simultaneously:
(setq sq_meters total)
(setq sq_feet (* total 10.7639))
(princ (strcat "\n>>> TOTAL: " (rtos sq_meters 2 2) " Sq. M. | " (rtos sq_feet 2 2) " Sq. Ft. <<<"))
Save this as TOTALAREA.LSP and load it with APPLOAD:
(defun C:TLA (/ ss total area obj name)
(setq ss (ssget '((0 . "LWPOLYLINE,CIRCLE,ELLIPSE,HATCH,REGION"))))
(if (= ss nil)
(princ "\nNo valid objects selected.")
(progn
(setq total 0)
(repeat (setq i (sslength ss))
(setq obj (ssname ss (setq i (1- i))))
(setq area (vlax-curve-getArea obj))
(setq total (+ total area))
)
(princ (strcat "\n--- TOTAL AREA ---"
"\nSquare feet: " (rtos total 2 2)
"\nSquare meters: " (rtos (* total 0.092903) 2 2)
"\nAcres: " (rtos (/ total 43560) 2 3)
"\nSquare yards: " (rtos (/ total 9) 2 2)))
)
)
(princ)
)
Note: Assumes your drawing units are in feet. Change the conversion multipliers if you work in meters or millimeters. ) ; end if (princ) ; Clean exit )