- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This neat program came to the top of the stack recently and I've been trying it, but in testing found one undesirable - selection from right to left invokes the usual crossing selection, which can make for some surprises when the odd line or two extends to the horizon.
Using Autocad 2022
In further testing, I discovered when the program runs and is waiting for user selection to begin, I can enter the word WINDOW in the command line and, regardless of direction, selection is only of objects completely enclosed by the selection box. Just the thing!
Alternatively, at this same point in the program, I can click on the SELECT WINDOW button on a toolbar for the same results and again, regardless of direction, selection is only of objects completely enclosed by the selection box.
I cannot, though, for the last few days of searching for ideas and trial-and-error, find or figure a way to add this to the program.
I'm wanting to eliminate the need for those extra steps and to avoid ever dealing with crossing selection characteristics for this program.
The intent is to share this with co-workers, but it would be better if the selection type was always WINDOW and never CROSSING.
Is there a way to add this trait to the program?
;;
;; Original program by LeeMac 23OCT2013
;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/the-smallest-rectangle-enclosing-selected-set-of-objects/td-p/3791519
;; Message 10
;;
;; Mods by SteveJ 24JAN2024 to replace an old program that really didn't
;; work all that well:
;; 0. Renamed from 'test' to TBOX to replace old program of same name.
;; 1. Hard set offset from selected objects based on text size.
;; 2. In LM:ssboundingbox routine, changed l, u and r in variables
;; to upper case, mostly to eliminate 1/l confusion and figured
;; while I was there, might as well do the others.
;; Works for ANY entity, including block references, and that's a most useful bonus.
;; Also removed lines of code made nonessential by my changes.
(defun c:TBOX (/ box off sel)
(if (member (getvar "textsize") '(0.08 0.12 0.14 0.16)); IF text height is set to one of these
(setq bbox:offset 0.08); THEN set offset = 0.08 = 1/12 scale
(setq bbox:offset 0.96); ELSE set offset = 0.96 = full scale
)
(setq off bbox:offset)
(if
(and (setq sel (ssget))
(setq box (LM:ssboundingbox sel))
)
(entmake
(list
'(000 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
'(090 . 4) ; Number of vertices
'(070 . 1) ; Closed Polyline
(list 10 (- (caar box) off) (- (cadar box) off))
(list 10 (+ (caadr box) off) (- (cadar box) off))
(list 10 (+ (caadr box) off) (+ (cadadr box) off))
(list 10 (- (caar box) off) (+ (cadadr box) off))
)
)
)
(princ)
)
;; Selection Set Bounding Box - Lee Mac
;; Returns the lower-left and upper-right WCS points of a rectangle
;; bounding all objects in a supplied selection set
(defun LM:ssboundingbox (ss / i L1 L2 LL UR)
(repeat (setq i (sslength ss))
(vla-getboundingbox (vlax-ename->vla-object (ssname ss (setq i (1- i))))
'LL
'UR
)
(setq L1 (cons (vlax-safearray->list LL) L1)
L2 (cons (vlax-safearray->list UR) L2)
)
)
(mapcar '(lambda (a b) (apply 'mapcar (cons a b))) '(min max) (list L1 L2))
)
(vl-load-com)
(princ)
;(c:TBOX)
;;Possibilities??
;;(command "_Select" "W" var1 var2) or some equivalent...?
;;Window
;;default Autocad macro for Select Window toolbar button is:
;;$M=$(if,$(getvar,cmdactive),,_select;)_w
Thanks for any ideas,
Steve
Solved! Go to Solution.