Community
Visual LISP, AutoLISP and General Customization
cancel
Showing results for
Show  only  | Search instead for
Did you mean:

## Automatic area calculation?

5 REPLIES 5
SOLVED
Message 1 of 6
418 Views, 5 Replies

## Automatic area calculation?

autolisp read the total area of ​​two groups

groups 1 x group 2 x100%=Answer%

5 REPLIES 5
Message 2 of 6

Explain more, post a dwg showing answer. Must have groups.

Message 3 of 6

(defun c:area-percentage (/ ss1 ss2 area1 area2 result)
(setq ss1 (ssget "X" '((8 . "GROUP1"))))
(setq ss2 (ssget "X" '((8 . "GROUP2"))))
(setq area1 0.0)
(setq area2 0.0)

(if (setq ent (ssname ss1 0))
(setq area1 (vla-get-Area (vlax-ename->vla-object ent)))
)

(if (setq ent (ssname ss2 0))
(setq area2 (vla-get-Area (vlax-ename->vla-object ent)))
)

(setq result (* (/ area1 area2) 100.0))
(princ (strcat "The result is " (rtos result)))
(princ)
)

Message 4 of 6

1st a Group is a collection of objects to imitate being picked as 1 object.

(setq ss1 (ssget "X" '((8 . "GROUP1")))) this will get all objects on layer Group1, so (ssname ss1 0) only gets 1 object even though there may be more. Use entsel for single pick. (setq ent (car (entsel "\nPick object 1 "))).

So do you mean a "GROUP" get area of all objects ?

Message 5 of 6

Message 6 of 6

Need to select the objects on layer "Group1" then add all areas of the objects, then get area 2, then multiply by 100.

``````(defun c:area-percentage (/ ss1 ss2 area1 area2 x)
(setq ss1 (ssget "X" '((8 . "GROUP1"))))
(setq ss2 (ssget "X" '((8 . "GROUP2"))))
(setq area1 0.0)
(setq area2 0.0)
(if (or (= ss1 nil)(= ss2 nil))
(alert "No objects on layer Groups ")
(progn
(repeat (setq x (sslength ss1))
(setq area1 (+ area1 (* (vla-get-Area (vlax-ename->vla-object (ssname ss1 (setq x (1- x))))) 100.)))
)
(repeat (setq x (sslength ss2))
(setq area2 (+ area2 (* (vla-get-Area (vlax-ename->vla-object (ssname ss2 (setq x (1- x))))) 100.)))
)
)
)
(princ (strcat "The result is " (rtos (* area1 area2) 2 0)))
(princ)
)
(c:area-percentage)``````

I would look at not using "X" but rather select objects then can repeat for various object sets.

``````(prompt "Select objects on layer GROUP1 ")
(setq ss1 (ssget '((8 . "GROUP1"))))
(prompt "Select objects on layer GROUP2 ")
(setq ss2 (ssget '((8 . "GROUP2"))))``````

Can't find what you're looking for? Ask the community or share your knowledge.