Automatic area calculation?

Automatic area calculation?

raymondcheng0922
Enthusiast Enthusiast
814 Views
5 Replies
Message 1 of 6

Automatic area calculation?

raymondcheng0922
Enthusiast
Enthusiast

autolisp read the total area of ​​two groups 

groups 1 x group 2 x100%=Answer%

 

0 Likes
Accepted solutions (1)
815 Views
5 Replies
Replies (5)
Message 2 of 6

Sea-Haven
Mentor
Mentor

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

0 Likes
Message 3 of 6

raymondcheng0922
Enthusiast
Enthusiast

(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)
)

0 Likes
Message 4 of 6

Sea-Haven
Mentor
Mentor

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 ?

 

 

 

 

 

0 Likes
Message 5 of 6

raymondcheng0922
Enthusiast
Enthusiast

raymondcheng0922_1-1682047625043.png

 

 

 

0 Likes
Message 6 of 6

Sea-Haven
Mentor
Mentor
Accepted solution

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"))))

 

 

 

0 Likes