Discus84 Posted 1 hour ago Posted 1 hour ago Hi, is there a script to create a rectangular bounding box around selected objects? Regards, Lu Quote
Discus84 Posted 1 hour ago Author Posted 1 hour ago Google AI... (defun C:BBOX ( / ss index ent vlaObj minPt maxPt minExt maxExt pt1 pt2 ) (vl-load-com) (princ "\nSelect objects to enclose in a bounding box: ") ;; Prompt user to select objects (if (setq ss (ssget)) (progn (setq index 0) ;; Loop through all selected objects (repeat (sslength ss) (setq ent (ssname ss index)) (setq vlaObj (vlax-ename->vla-object ent)) ;; Safely catch objects that do not support a bounding box (if (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list vlaObj 'minPt 'maxPt)))) (progn (setq pt1 (vlax-safearray->list minPt) pt2 (vlax-safearray->list maxPt)) ;; Initialize or update the overall minimum and maximum coordinates (if (not minExt) (setq minExt pt1 maxExt pt2) (setq minExt (mapcar 'min pt1 minExt) maxExt (mapcar 'max pt2 maxExt)) ) ) ) (setq index (1+ index)) ) ;; Draw the bounding box if valid coordinates were collected (if (and minExt maxExt) (progn ;; Deactivate Object Snap temporarily to ensure precision (setq oldOsmode (getvar "OSMODE")) (setvar "OSMODE" 0) ;; Draw a standard rectangle using the global coordinates (command "_.rectangle" minExt maxExt) ;; Restore original Object Snap settings (setvar "OSMODE" oldOsmode) (princ "\nBounding box successfully created!") ) (princ "\nError: Could not calculate bounding box for selected objects.") ) ) (princ "\nNo objects selected.") ) (princ) ) (princ "\nType BBOX to run the command.") (princ) 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.