bsimpson Posted May 29, 2020 Posted May 29, 2020 Hi, I am trying to find the 2D area of multiple 2D solids in a drawing. How do I do this? The attached drawing shows the green 2D solids which I need a combined area of. example_cadtutorial.dwg Quote
BIGAL Posted May 29, 2020 Posted May 29, 2020 The only problem I had was there is 13428 objects. So no way of checking answer. A boundary around would be a good check will see if I have time. ; get area of solids ; By AlanH May 2020 info@alanh.com.au (defun c:testarea ( / tot co-ords co-ordsxy getcoords ss-pts2area) ; pline co-ords example (defun getcoords (ent) (vlax-safearray->list (vlax-variant-value (vlax-get-property (vlax-ename->vla-object ent) "Coordinates" ) ) ) ) (defun ss-pts2area (l) (/ (apply (function +) (mapcar (function (lambda (x y) (- (* (car x) (cadr y)) (* (car y) (cadr x))))) (cons (last l) l) l)) 2.) ) ; convert now to xyz note solid reports a Z so 3 (defun co-ords2xy () (setq co-ordsxy '()) (progn (setq I 0) (repeat (/ (length co-ords) 3) (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords)(nth (+ I 2) co-ords) )) (setq co-ordsxy (cons xy co-ordsxy)) (setq I (+ I 3)) ) ) ) ; program starts here (vl-load-com) (setq tot 0.0) (if (/= (setq ss (ssget (list (cons 0 "SOLID")))) nil) (repeat (setq x (sslength ss)) (setq co-ords (getcoords (ssname ss (setq x (- x 1))))) (co-ords2xy) (setq tot (+ (abs (ss-pts2area co-ordsxy)) tot)) ) ) (Alert (strcat "Total is " (rtos tot 2 2))) (princ) ) Quote
bsimpson Posted May 30, 2020 Author Posted May 30, 2020 Thanks works brilliantly, I tested it on approx. 1million solids and it gave the correct answer. Quote
BIGAL Posted May 30, 2020 Posted May 30, 2020 No worries it should work for more than 3 point solids also. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.