# Thread: lisp to calculate total areas

1. ## lisp to calculate total areas

Registered forum members do not see this ad.

please i need a lisp programming for autocad to caculate all the closed areas in a certain layer, also i need another program to calculate the total area of all the similar shapes ie: when u select assume a rectangle of dim(a,b) so it check all the similar rectangles and give the total summation area of the all of the same dimesnsions, anybody can help plz

2. Search here first for "area lisp" lots of them out there.

hello plz i need it to calculate every closed area including circules and elipses and all closed polylines if curved or straight, if any, thanks again

4. Something like:

Code:
```(defun c:sarea(/ aSum cSet cSet)
(setq aSum 0)
(if
(setq cSet
(ssget '((0 . "*POLYLINE,SPLINE,CIRCLE,ELLIPSE"))))
(progn
(foreach c(vl-remove-if 'listp
(if(vlax-curve-IsClosed c)
(setq aSum(+ aSum(vlax-curve-GetArea c)))
(ssdel c cSet)
); end if
); end foreach
(princ(strcat "\nTotal area = " (rtos aSum)))
(sssetfirst nil cSet)
); end progn
); end if
(princ)
); end of c:sarea```

5. ## can somebody proffesional modify polyarea.lsp plz

Thanks very much for the lisp "sarea" i used it but something missing because i drew with the polyline a closed shape including some arcs but couldnt calculate its area ie: like a closed barrel-vault or a closed dome but couldnt give me its area, it is saying zero knowing that it is closed.

i want to give you this polyarea.lsp please so if anybody can help:
It is calculating all the closed areas you imagine except the circles so can you please modify this lisp to take the circle in to consideration when giving the total areas summation:

;;POLYAREA.LSP - (c)
;;
;; Calculates the area of one or more closed polylines and
;;
(defun COLYAREA (/ a ss n du)
(setq a 0
du (getvar "dimunit")
ss (ssget '((0 . "*POLYLINE"))))
(if ss
(progn
(setq n (1- (sslength ss)))
(while (>= n 0)
(command "_.area" "_o" (ssname ss n))
(setq a (+ a (getvar "area"))
n (1- n)))
(strcat "The total area of the selected\nobject(s) is "
(if (or (= du 3)(= du 4)(= du 6))
;
;The following 2 lines translate the area to square inches and feet
;for users using US engineering or architectural units:
;
(strcat (rtos a 2 2) " square inches,\nor "
(rtos (/ a 144.0) 2 3) " square feet.")
;
;In the following line, change the word "units" to whatever units
;you are using - meters, millimeters, feet, etc.
;
(strcat (rtos a 2 3) " square units.")))))
(princ)
)
(strcat "POLYAREA.LSP (c) "
"\n\n Type POLYAREA to start"))
(princ)

please, i need all results in meter square only, so anybody can modify it, thank you all for help

6. i used it but something missing because i drew with the polyline a closed shape including some arcs but couldnt calculate its area ie: like a closed barrel-vault or a closed dome but couldnt give me its area, it is saying zero knowing that it is closed.
I think it visually closed but not closed by Close option (look properties window for this polyline). Now this check is removed an result in square meters (if drawing units is mm):

Code:
```(defun c:sarea(/ aSum cSet)
(setq aSum 0)
(if(setq cSet(ssget '((0 . "*POLYLINE,SPLINE,CIRCLE,ELLIPSE"))))
(setq aSum(+ aSum(vlax-curve-GetArea c)))
); end foreach
); end if
(princ(strcat "\nTotal area = " (rtos(/ aSum 1000000)) " m2"))
(princ)
); end of c:sarea```

7. Registered forum members do not see this ad.

This lisp calculate a total area of selected entities by layer
Code:
```(defun c:SAL (/ m ss clist temp)
;;command SAL - Sum Area by Layer
(defun sort (lst predicate)
(mapcar '(lambda (x) (nth x lst)) (vl-sort-i lst predicate))
) ;_ end of defun
(defun combine (inlist is-greater is-equal / sorted current result)
(setq sorted (sort inlist is-greater))
(setq current (list (car sorted)))
(foreach item (cdr sorted)
(if (apply is-equal (list item (car current)))
(setq current (cons item current))
(progn
(setq result (cons current result))
(setq current (list item))
) ;_ end of progn
) ;_ end of if
) ;_ end of foreach
(cons current result)
) ;_ end of defun
(defun marea (lst / sum_len)
(setq sum_len 0)
(foreach item (mapcar 'car lst)
(setq
sum_len (+ sum_len
(if (vlax-property-available-p item 'Area)
(vla-get-area item)
) ;_  if
) ;_  +
) ;_ end of setq
) ;_ end of foreach
(if (not (zerop sum_len))
(princ
(strcat "\n\t" (cdar lst) " = " (rtos (* sum_len m) 2 4))
) ;_ end of princ
) ;_ end of if
) ;_ end of defun
(if (null *M*)
(setq *M* 1)
) ;_ end of if
(initget 6)
(and
(princ "\nEnter scale factor <")
(princ *M*)
(princ ">: ")
(or (setq m (getreal)) (setq m *M*))
(setq *M* m)
(setq ss (ssget '((0 . "*POLYLINE,SPLINE,CIRCLE,ELLIPSE"))))
(setq ss (mapcar
(function vlax-ename->vla-object)
(vl-remove-if
(function listp)
(mapcar
(ssnamex ss)
) ;_  mapcar
) ;_ vl-remove-if
) ;_ end of mapcar
) ;_ end of setq
(mapcar '(lambda (x)
(setq temp (cons (cons x (vla-get-layer x)) temp))
) ;_ end of lambda
ss
) ;_ end of mapcar
(setq clist (combine temp
'(lambda (a b)
(> (cdr a) (cdr b))
) ;_ end of lambda
'(lambda (a b)
(eq (cdr a) (cdr b))
) ;_ end of lambda
) ;_ end of combine
) ;_ end of setq
(princ
"\n\n  Total area by layer :"
) ;_ end of princ
(mapcar 'marea clist)
) ;_ end of and
(princ)
) ;_  defun```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts