Selection behavior assistance

Selection behavior assistance

stev98312
Enthusiast Enthusiast
571 Views
7 Replies
Message 1 of 8

Selection behavior assistance

stev98312
Enthusiast
Enthusiast


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

 

0 Likes
Accepted solutions (2)
572 Views
7 Replies
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor
Accepted solution

one thought I have but only let's user select window once and then the program continues so no more additional selections. Replace these lines of code:

  (if
    (and (setq sel (ssget))
         (setq box (LM:ssboundingbox sel))
    )

with these:

  (princ "\nSelect Objects by Window")
  (setq p1 (getpoint "\nFirst Corner: "))
  (setq p2 (getcorner p1 "\nSecond Corner: "))
  (if
    (and (setq sel (ssget "_W" p1 p2))
         (setq box (LM:ssboundingbox sel))
    )

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 8

komondormrex
Mentor
Mentor

function wp_ssget will always select objects inside a window polygon, based on the coordinates of the single ssget crossing window or just window. other single ssget selections will return nil.

 

(defun wp_ssget (/ text_sset sset_data)
 	(if (setq text_sset (ssget ":s"))
 		(if (and 
 				 (= -1 (car (setq sset_data (last (ssnamex text_sset)))))
 				 (= 4 (length (cdr sset_data)))
 			)
 			(ssget "_wp" (mapcar 'cadr (cdr sset_data))) 
 			nil
 		)
 	)
)

 

 

0 Likes
Message 4 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

I think I got it working. Not as easy as one could think.

 

(defun :windowselect ( / s i l o)
  (setq s (ssadd))
  (while (progn
	   (setvar 'ERRNO 0)
	   (setq o (entsel "\nSelect objects by window: "))
	   (not (and (not o) (= 52 (getvar 'ERRNO))))) ;; right click to quit
    (if o
      (setq l (cons (car o) l))	;; single point selection
      (progn 			;; window selection. getpoint by grrread
	(command "_.select" "_si" "_w" (cadr (grread t 15 0)) pause) ;; single window selection
	(if (setq s (ssget "_p"))
	  (repeat (setq i (sslength s))
	    (setq l (cons (ssname s (setq i (1- i))) l))))))
    (foreach e l (redraw e 3))) ;; highlight current selection
  (if l
    (progn
      (foreach e (reverse l)
	(redraw e 4)
	(ssadd e s))
      (command "_.select" s "") ;; entire selection for select "previous" option
      s)))
0 Likes
Message 5 of 8

Kent1Cooper
Consultant
Consultant

The big thing that's not clear to me is:

 

Are you wanting the entire selection to be always by a single window only, but with only Window style, not Crossing, regardless of the direction between picked corners?  It looks like Messages 2 & 3 are made to do that.

 

But currently your (ssget) in the code lets you do multiple selections under all the options and methods [individual picks, Fence, lasso, Remove option, in addition to both kinds of windowing].  Are you wanting that, except to have any variety of windowing always use only Window style and never Crossing style?  [I don't know of a way to force that limitation.]  In quick trial, it seems Message 4 allows multiple selections, by individual picks and windowing with that limitation and Fence selection, but doesn't seem to allow other options, like lassoing or Remove.

 

If you want all the options but windowing to never use Crossing mode, it may not be possible, and may just be a situation where some training is needed, so people are conscious of the need to simply never do windowing [or lassoing] from right to left.

Kent Cooper, AIA
0 Likes
Message 6 of 8

komondormrex
Mentor
Mentor

may be coded like this one

0 Likes
Message 7 of 8

stev98312
Enthusiast
Enthusiast

OKay. A few ways to accomplish this modification.

@paullimapa- Thank you for such a simple solution. Easy to read, comprehend and incorporate.

@komondormrex- Couldn't get that one working. No response from the code.

@ВeekeeCZ- Your WindowSelect is much more programming than I thought would be necessary, but it works and I have a couple other projects I think it'll be perfect for, once I can pick it apart to see how it does what it does.

I want to see if I can incorporate it into this program, too, for the leaning experience.

@Kent1Cooper- Apologies. I could have been more clear on my objective. "Are you wanting the entire selection to be always by a single window only, but with only Window style, not Crossing, regardless of the direction between picked corners?" Yes. The current (ssget) is as presented in the original program.

 

Thank you all for your help and ideas.

Steve

 

 

 

0 Likes
Message 8 of 8

paullimapa
Mentor
Mentor

glad to have helped...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes