autolisp read the total area of two groups
groups 1 x group 2 x100%=Answer%
Solved! Go to Solution.
Solved by Sea-Haven. Go to Solution.
(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)
)
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 ?
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.