calculate the area of a face of a 3dsolid

calculate the area of a face of a 3dsolid

Juan-Emil_Saayman
Participant Participant
617 Views
2 Replies
Message 1 of 3

calculate the area of a face of a 3dsolid

Juan-Emil_Saayman
Participant
Participant

Hi 

 

I want to be able to determine the surface area of a selected face of a 3dsolid. I've written a lisp routine, but I cant get get it to select the face that I want to calculate. 

 

(defun c:area3dface ()
  (setq ss (ssget "_:L" '((0 . "3DSOLID"))))
  (if ss
    (progn
      (setq obj (ssname ss 0))
      (if (= (cdr (assoc 0 (entget obj))) "3DSOLID")
        (progn
          (setq pt (getpoint "\nSelect point on face to calculate area: "))
          (setq face (vlax-curve-getclosests (vlax-ename->vla-object obj) (vlax-3d-point pt) 1e-6))
          (if face
            (progn
              (setq area (vla-get-Area (vlax-ename->vla-object (car face))))
              (princ (strcat "\nArea of selected face: " (rtos area)))
            )
            (princ "\nNo face selected.")
          )
        )
        (princ "\nSelected object is not a 3DSolid.")
      )
    )
    (princ "\nNo 3DSolid object selected.")
  )
  (princ)
)

 

Please could somebody help me to fix this code.  

0 Likes
Accepted solutions (1)
618 Views
2 Replies
Replies (2)
Message 2 of 3

yangguoshe
Advocate
Advocate

You can explode the 3D solid first to query the area of a single plane, and then “undo” back to  3dsolid

0 Likes
Message 3 of 3

hmsilva
Mentor
Mentor
Accepted solution

@Juan-Emil_Saayman to calculate the area of a face of a 3dsolid we can also use something like this

(defun c:demo (/ *error* area face lastent obj)
    (defun *error* (msg)
	(command-s "_.undo" "_back")
	(cond ((not msg))
	      ((member msg '("Function cancelled" "quit / exit abort")))
	      ((princ (strcat "\n** Error: " msg " ** ")))
	)
	(princ)
    )
    (command "_.undo" "_mark")
    (setq lastent (entlast))
    (setvar 'SUBOBJSELECTIONMODE 3)
    (command "SOLIDEDIT" "_F" "_C" pause "" "@" "@" "" "")
    (setq face (entlast))
    (setq obj (vlax-ename->vla-object face))
    (if	(and (not (eq lastent face))
	     (wcmatch (vla-get-objectname obj) "AcDbRegion")
	)
	(progn
	    (setq area (vla-get-area obj))
	    (alert (strcat "Face area is:  " (rtos area 2 2)))
	)
    )
    (*error* nil)
    (princ)
)

 

Hope this helps,
Henrique

EESignature

0 Likes