Jump to content

Recommended Posts

Posted

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

Posted

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

 

Posted

Thanks works brilliantly, I tested it on approx. 1million solids and it gave the correct answer. 

Posted

No worries it should work for more than 3 point solids also.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...