Still, I'd here add choice to choose between 2 options (to retain selection, or to remove it like you wanted)... Perhaps that's the reason why @Kent1Cooper haven't edited his solution... Anyway, to me it seems to have sense to let the user decide how to act... So here is revision I took... Note that (ssget) now has mode "_:L" since only entities on unlocked layer(s) can be relibaly erased like you wanted, and beside that I, and perhaps some other user, predominantly work with unlocked layers...
;|
DrawBoundingBoxMult.lsp [command name: DBBM]
To Draw the Bounding Box around Multiple objects. Finds overall extent
of object(s) selected, and draws a Rectangle around that collective box.
Works in non-World UCS if XYZ axes parallel to WCS [i.e. origin may
be different but with same orientation].
Kent Cooper, last edited 1 February 2017
|;
(defun C:DBBM ( / ss minpt maxpt eLL eUR LL UR ch ); = Draw Bounding Box, Multiple
(or (not (vl-catch-all-error-p (vl-catch-all-apply (function vlax-get-acad-object) nil))) (vl-load-com))
(prompt "\nSelect entities to Draw the Bounding Box around them all...")
(if (setq ss (ssget "_:L"))
(progn ; then
(repeat (setq n (sslength ss))
(vla-getboundingbox (vlax-ename->vla-object (ssname ss (setq n (1- n)))) 'minpt 'maxpt)
(setq
eLL (safearray-value minpt)
eUR (safearray-value maxpt)
LL (if LL (mapcar (function min) eLL LL) eLL)
UR (if UR (mapcar (function max) eUR UR) eUR)
); setq
); repeat
(initget 1 "M reMove T reTain")
(setq ch (getkword "\nDou you want to reMove selected objects or reTain them [reMove/reTain] : "))
(if (or (= ch "M") (= ch "reMove"))
(vl-cmdf "_.rectangle" "_non" (trans LL 0 1) "_non" (trans UR 0 1) "_.erase" ss "")
(vl-cmdf "_.rectangle" "_non" (trans LL 0 1) "_non" (trans UR 0 1))
)
); progn
(prompt "\nNothing selected."); else
); if
(princ)
); defun
HTH.
M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)