# Thread: Looking for Lsp which can calculate sum of polygon and closed polyline area?

1. ## Looking for Lsp which can calculate sum of polygon and closed polyline area?

Registered forum members do not see this ad.

First of me, Hi to everyone! Glad to be part of this.
I am pretty new to this forum so as to AutoCad software, I am GIS maniac.

Currently working on some urban plan and my company need to calculate area of existing polygons, hatches and polylines. A lot of people worked on same project and that is why we have different types of geometry.
I can manually change all of this to closed polylines but there is over 2000 polygons and hatches.
Is there any lsp which can calculate all types of geometry? I tried many but they are just calculating closed polylines.

Thank you very much and sorry for bad english

2. This program does not require the polyline to be closed: Total Area

3. Something I am working on at moment

Code:
```; Total HATCH area labeller
(Defun C:AHAT (/ arean area2 lay col en hobj Hp num rp sset)
(setq Hp (ENTGET (CAR (ENTSEL "\nPICK HATCH "))))
(SETQ LAY (CDR (ASSOC 8 HP)))
(setq sset (ssget  (list (cons 0 "hatch") (CONS 8 LAY))))
(setq arean 0)
(setq area2 0)
(REPEAT (setq num (sslength sset))
(setq en (ssname sset (setq num (- num 1))))
(SETQ COL (CDR (ASSOC 62 (entget EN)))) ; by layer check
(SETQ ARNEW (vla-get-area (vlax-ename->vla-object en)))
(IF (= COL NIL)
(setq AREAN (+ AREAN ARNEW))
(SETQ AREA2 (+ AREA2 ARNEW))
)
)
(ALERT (STRCAT "AREA IS ..." (RTOS AREAN 2 2)"\N\NAREA2 IS ..." (RTOS AREA2 2 2)))
(princ)
)```

4. BIGAL, you inspired me to write this:
Code:
```; Total area of hatches with certain pattern
(defun C:test ( / SH enx SS i Lst )
(setvar 'errno 0)
(while (/= 52 (getvar 'errno))
(setq SH (car (entsel "\nSelect source hatch pattern to filter by <exit>: ")))
(cond
((= 7 (getvar 'errno)) (princ) (setvar 'errno 0))
((and SH (/= "HATCH" (cdr (assoc 0 (setq enx (entget SH))))) (princ "\nThis is not a \"HATCH\".")))
(
(and
SH
(princ (strcat "\nSelect hatches with \"" (cdr (assoc 2 enx)) "\" pattern to sum their area: "))
(setq SS (ssget (list (assoc 0 enx) (assoc 2 enx))))
(repeat (setq i (sslength SS))
(setq Lst (cons (vla-get-Area (vlax-ename->vla-object (ssname SS (setq i (1- i))))) Lst))
)
(not (alert (strcat "\nTotal area of the hatch with \"" (cdr (assoc 2 enx)) "\" pattern is: " (rtos (apply '+ Lst) 2 2) " units.")))
)
(setvar 'errno 52)
)
)
)
(princ)
)```

5. @Grrr/BIGAL: Be aware of the issue of querying the ActiveX Area property of a hatch object with a self-intersecting boundary

6. Originally Posted by Lee Mac
@Grrr/BIGAL: Be aware of the issue of querying the ActiveX Area property of a hatch object with a self-intersecting boundary
Oh right, I didn't considered this scenario!
Leaving my inspiration as a concept (thankfuly I don't need to use it for real).

7. Registered forum members do not see this ad.

Thank you.
I have not expected this kind of help. With this lisp-s and little editing of some,I managed to get total area. I do not have many experience of making codes but I edited code of Princ(or Grr and get results with different lsp for mpolygons,then different for hatches and then for polylines.
Anyway thank you very much!
Kumbra!