Jump to content
pizarro

Selection of items by volume

Recommended Posts

pizarro

Lisp to select solids among a given volume. Example: select solids that are between 25 mm³ and 60 mm³

Share this post


Link to post
Share on other sites
Lee Mac
Posted (edited)
  • 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

Share this post


Link to post
Share on other sites
Emmanuel Delay

 


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

Share this post


Link to post
Share on other sites
Lee Mac
Posted (edited)

@Emmanuel Delay Note that min & max are protected symbols and should not be redefined.

 

Also, FWIW:

(and (>= volume min) (<= volume max))    ==    (<= min volume max)

 

Edited by Lee Mac
  • Like 1

Share this post


Link to post
Share on other sites
Emmanuel Delay

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

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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