pizarro Posted April 10, 2019 Posted April 10, 2019 Lisp to select solids among a given volume. Example: select solids that are between 25 mm³ and 60 mm³ Quote
Lee Mac Posted April 10, 2019 Posted April 10, 2019 (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 April 10, 2019 by Lee Mac 1 Quote
Emmanuel Delay Posted April 12, 2019 Posted April 12, 2019 (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) ) ) Quote
Lee Mac Posted April 12, 2019 Posted April 12, 2019 (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 April 12, 2019 by Lee Mac 1 Quote
Emmanuel Delay Posted April 12, 2019 Posted April 12, 2019 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) ) ) 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.