Message 1 of 13
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
How to Autolisp calculate area ratio of two groups?
Solved! Go to Solution.
How to Autolisp calculate area ratio of two groups?
Solved! Go to Solution.
(defun C:area-ratio ( / ent1 ent2 area1 area2 total)
(setq ent1 (entsel "
Select the first group of objects: "))
(setq area1 (vl-cmdf "_.area" ent1))
(setq ent2 (entsel "
Select the second group of objects: "))
(setq area2 0)
(foreach ent ent2
(setq area2 (+ area2 (vl-cmdf "_.area" ent)))
)
(setq total (+ area1 area2))
(setq first-ratio (* 100.0 (/ area1 total)))
(setq second-ratio (* 100.0 (/ area2 total)))
(setq pt (getpoint "
Specify the insertion point for the output: "))
(setq output (strcat "The area of the first group is " (rtos first-ratio 2) "% of the total area."))
(setq output (strcat output (strcat "\nThe area of the second group is " (rtos second-ratio 2) "% of the total area.")))
(entmake (list (cons 0 "TEXT") (cons 10 pt) (cons 1 output)))
)
@raymondcheng0922 wrote:
How to Autolisp calculate area ratio of two groups?
Are you referring to AutoCAD GROUP selection type or group of objects ? ( Polylines/Circles/Hatch...) ?
Two sets of polygons total area
Exsamlpe
What is the percentage of one of the 8 unit buildings?
@raymondcheng0922 wrote:
Two sets of polygons total area
(defun C:area-ratio (/ _sel firstGroup area1 area2 secondGroup total first-ratio second-ratio pt output )
(defun _sel (ss / ent i totalArea)
(setq totalArea 0)
(repeat (setq i (sslength ss))
(setq ent (ssname ss (setq i (1- i))))
(setq totalArea (+ totalArea (getpropertyvalue ent "Area")))
)
totalArea
)
(if (and
(princ "\nFirst group of objects: ")
(setq firstGroup (ssget '((0 . "LWPOLYLINE"))))
(princ "\nSecond group of objects: ")
(setq secondGroup (ssget '((0 . "LWPOLYLINE"))))
(setq pt (getpoint "\nSpecify the insertion point for the output: "))
)
(progn
(setq area1 (_sel firstGroup))
(setq area2 (_sel secondGroup))
(setq total (+ area1 area2))
(setq first-ratio (* 100.0 (/ area1 total)))
(setq second-ratio (* 100.0 (/ area2 total)))
(setq output (strcat "The area of the first group is "
(rtos first-ratio 2)
"% of the total area."
)
)
(setq output (strcat output
(strcat "\nThe area of the second group is "
(rtos second-ratio 2)
"% of the total area."
)
)
)
(entmakex (list (cons 0 "MTEXT")
(cons 100 "AcDbEntity")
(cons 100 "AcDbMText")
(cons 10 pt)
(cons 1 output)
)
)
(princ (Strcat "\n" output))
)
)
(princ)
)
Command: AREA-RATIO
First group of objects:
Select objects: Specify opposite corner: 2 found
Select objects: < presss enter/spacebar >
Second group of objects:
Select objects: Specify opposite corner: 2 found
Select objects: < presss enter/spacebar >
Specify the insertion point for the output:
The area of the first group is 58.0943% of the total area.
The area of the second group is 41.9057% of the total area.
HTH
Just ask, can it be combined with the attached LSP
@raymondcheng0922 wrote:
Just ask, can it be combined with the attached LSP
I guess we can do that. how you would want the result to look? The highlighted as field value?
The area of the first group is 58.0943% of the total area.
The area of the second group is 41.9057% of the total area.
Like you think 。thank you
Thanks for the demo, it works elsewhere, very useful
@raymondcheng0922 wrote:
Thanks for the demo, it works elsewhere, very useful
Are you responding to my post or some other random help you got from someplace/someone else?
Just replying for your help, but no one else has a solution
In fact, can my own lsp calculate part of it, and use other lsp? Calculate part call LengthAreaField V1-4.lsp?