Jump to content

Selection of items by volume


pizarro

Recommended Posts

  • Obtain selection set of all 3D Solids (ssget)
  • Iterate over selection set (examples)
  • Convert each entity to a VLA Object (vlax-ename->vla-object)
  • Query Volume property of the VLA Object
  • Use an if statement with test expression to check if volume is within range
  • Construct new selection set (ssadd) of target entities, or remove entities which do not meet the criteria from the set (ssdel)
  • Select resulting set (sssetfirst)
Edited by Lee Mac
  • Like 1
Link to comment
Share on other sites

 


(vl-load-com)

;; Select Solids By Volume
(defun c:ssbv ( / ss min max solids)
 
  ;; selects all solids
  (setq ss (ssget "X" '( (100 . "AcDb3dSolid") )))
  ;; user imput: min & max volume
  (setq min (getreal "\nMinimum volume: "))
  (setq max (getreal "\nMaximum volume: "))
  (ssvb min max ss)
  (princ)
)

(defun ssvb (min max ss / i solid boxObj volume solids)
  (setq i 0)
  (setq solids (ssadd))
  (repeat (sslength ss)
    (setq solid (ssname ss i))
    (setq boxObj (vlax-ename->vla-object solid))
    (setq volume (vla-get-Volume boxObj))
    (if (and (>= volume min) (<= volume max) ) (progn
      (ssadd (ssname ss i) solids)
    ))
    (setq i (+ i 1))
  )
  (if solids
    (sssetfirst nil solids)
  )
)

Link to comment
Share on other sites

okay, thanks.

 


(vl-load-com)

;; Select Solids By Volume
(defun c:ssbv ( / ss mini maxi solids)
  ;; selects all solids
  (setq ss (ssget "X" '( (100 . "AcDb3dSolid") )))
  ;; user imput: mini & maxi volume
  (setq mini (getreal "\nMinimum volume: "))
  (setq maxi (getreal "\nMaximum volume: "))
  (ssvb mini maxi ss)
  (princ)
)

(defun ssvb (mini maxi ss / i solid boxObj volume solids)
  (setq i 0)
  (setq solids (ssadd))
  (repeat (sslength ss)
    (setq solid (ssname ss i))
    (setq boxObj (vlax-ename->vla-object solid))
    (setq volume (vla-get-Volume boxObj))
    (if (<= mini volume maxi) (progn
      (ssadd (ssname ss i) solids)
    ))
    (setq i (+ i 1))
  )
  (if solids
    (sssetfirst nil solids)
  )
)

Link to comment
Share on other sites

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