Selection Set Bounding Box

Function Syntax (LM:ssboundingbox <s>)
Current Version 1.1
Donate
Arguments
Symbol Type Description
s Selection Set Selection set for which to return the bounding box
Returns
Type Description
List List of lower-left & upper-right WCS coordinates of bounding box

Function Description

This function will return a list of the lower-left and upper-right coordinates (in WCS) of the rectangular frame describing the bounding box of all objects in the supplied selection set.

Select all
;; Selection Set Bounding Box  -  Lee Mac
;; Returns a list of the lower-left and upper-right WCS coordinates of a
;; rectangular frame bounding all objects in a supplied selection set.
;; s - [sel] Selection set for which to return bounding box

(defun LM:ssboundingbox ( s / a b i m n o )
    (repeat (setq i (sslength s))
        (if
            (and
                (setq o (vlax-ename->vla-object (ssname s (setq i (1- i)))))
                (vlax-method-applicable-p o 'getboundingbox)
                (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list o 'a 'b))))
            )
            (setq m (cons (vlax-safearray->list a) m)
                  n (cons (vlax-safearray->list b) n)
            )
        )
    )
    (if (and m n)
        (mapcar '(lambda ( a b ) (apply 'mapcar (cons a b))) '(min max) (list m n))
    )
)

Example Calling Function

Select all
(defun c:test ( / b s )
    (if
        (and
            (setq s (ssget))
            (setq b (LM:ssboundingbox s))
        )
        (entmake
            (append
               '(
                    (000 . "LWPOLYLINE")
                    (100 . "AcDbEntity")
                    (100 . "AcDbPolyline")
                    (090 . 4)
                    (070 . 1)
                )
                (mapcar '(lambda ( x ) (cons 10 (mapcar '(lambda ( y ) ((eval y) b)) x)))
                   '(
                        (caar   cadar)
                        (caadr  cadar)
                        (caadr cadadr)
                        (caar  cadadr)
                    )
                )
            )
        )
    )
    (princ)
)
(vl-load-com)

textsize

increase · reset · decrease

Designed & Created by Lee Mac © 2010