Bounding Box

Function Syntax (LM:boundingbox <obj>)
Current Version 1.0
Donate
Arguments
Symbol Type Description
obj VLA-Object VLA-Object for which to return the rectangular bounding box
Returns
Type Description
List WCS point list describing rectangular bounding box of object, else nil

Program Description

This simple function is a wrappr for the Visual LISP ActiveX getboundingbox method and will return, if possible, a list of the coordinates (in WCS) of the rectangular frame describing the bounding box of the supplied VLA-Object.

The function is only applicable to 2D objects residing in the WCS plane, and the rectangular bounding box returned is orthogonal to the WCS coordinate axes and ordered anticlockwise from the lower-left corner.

Select all
;; Bounding Box  -  Lee Mac
;; Returns the point list describing the rectangular frame bounding the supplied object.
;; obj - [vla] VLA-Object

(defun LM:boundingbox ( obj / a b lst )
    (if
        (and
            (vlax-method-applicable-p obj 'getboundingbox)
            (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list obj 'a 'b))))
            (setq lst (mapcar 'vlax-safearray->list (list a b)))
        )
        (mapcar '(lambda ( a ) (mapcar '(lambda ( b ) ((eval b) lst)) a))
           '(
                (caar   cadar)
                (caadr  cadar)
                (caadr cadadr)
                (caar  cadadr)
            )
        )
    )
)

Example Calling Function

The following example will prompt the user to select an object and, following a valid selection, will generate an LWPolyline describing the bounding box of the selected object.

Select all
(defun c:test ( / ent )
    (if (setq ent (car (entsel)))
        (entmake
            (append
               '(
                    (000 . "LWPOLYLINE")
                    (100 . "AcDbEntity")
                    (100 . "AcDbPolyline")
                    (090 . 4)
                    (070 . 1)
                )
                (mapcar '(lambda ( p ) (cons 10 p)) (LM:boundingbox (vlax-ename->vla-object ent)))
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

textsize

increase · reset · decrease

Designed & Created by Lee Mac © 2010