Jump to content
3dwannab

Selecting similar to what is visable on screen

Recommended Posts

3dwannab

I have the Ctrl+Q set up to select similar. Quite handy when used with another shortcut I've set up Ctrl+H to hide that selection or any other command I wish to invoke after.

 

This works great but I was hoping to know if it's possible for the same standard command of AutoCADs select similar can be done by LISP, only difference being that it only selects whats visible on the monitor.

 

I think it's a long shot asking but worth asking :]. It would be handy for deleting similar stuff just on the screen without having to shift select (de-select) the other items selected.

Thanks in advance.

Share this post


Link to post
Share on other sites
tzframpton

One non-LISP alternative is to highlight everything visible on your monitor, then use the Isolate Objects tool to confine only the objects you see. Then you can run the Select Similar tool without the unwanted items that were out of view on your monitor.

Share this post


Link to post
Share on other sites
3dwannab

Trust someone to come up with a workaround/solution that was staring me in the face. :] Thank you.

 

I had Ctrl+Shift+E set up to select similar and isolate and Ctrl+E to unisolate. Just set up Ctrl+Alt+E to isolate. It's one little extra step more than I hoped but none the less just as effective.

Share this post


Link to post
Share on other sites
jdiala

This:

 

(defun C:test (/  sel_set_win minv maxv slist ss i  nss)
 (defun sel_set_win (/ c tss)
   (if (not nss) (setq nss (ssadd)))
     (setq tss (ssget "_C" minv maxv slist))
     (repeat (setq c (sslength tss))
       (ssadd (ssname tss (setq c (1- c))) nss)  
     )
 )
(setq minv (getvar 'extmin) maxv (getvar 'extmax)) 
(setq ss (ssget ":L" ))
(repeat (setq i (sslength ss))
 (if slist (setq slist nil))
 (if (= "INSERT" (cdr (assoc 0 (entget (ssname ss (setq i (1- i)))))))
     (setq slist (list (cons 0 "INSERT") (cons 2 (cdr (assoc 2 (entget (ssname ss i)))))))
     (setq slist (list 
                (cons 0 (cdr (assoc 0 (entget (ssname ss i)))))
		(cons 8 (cdr (assoc 8 (entget (ssname ss i)))))
             ))
 )
(sel_set_win)
)
(command "._isolateobjects" nss "")
)

Edited by jdiala

Share this post


Link to post
Share on other sites
Bhull1985

Hey Jdiala

that very nice routine of yours there I've found, after quick testing, deletes all other inserts than the one selected, within the current window of view

how would you modify to remove all other blocks references with the same name as the supplied selection but leave all other inserts in view alone, while leaving the selected block reference in place as per your example above

thanks

Share this post


Link to post
Share on other sites
jdiala
Hey Jdiala

that very nice routine of yours there I've found, after quick testing, deletes all other inserts than the one selected, within the current window of view

how would you modify to remove all other blocks references with the same name as the supplied selection but leave all other inserts in view alone, while leaving the selected block reference in place as per your example above

thanks

 

The code above was modified form

 

(command "._erase" nss "")
to
(command "._isolateobjects" nss "")

 

I'm not really sure want the OP wanted if, want to delete object posted on #1 or isolate on post 3.

 

bhull, I have go right now. If no one provide a code by then I'll provide you with one.

Share this post


Link to post
Share on other sites
3dwannab
The code above was modified form

 

(command "._erase" nss "")
to
(command "._isolateobjects" nss "")

 

I'm not really sure want the OP wanted if, want to delete object posted on #1 or isolate on post 3.

 

bhull, I have go right now. If no one provide a code by then I'll provide you with one.

Great, thanks. I have yet to test it, will do at work tomorrow. I only wanted to select anything similar like the existing command only what is visible on the monitor depending on where in the modelspace I am at the time.

 

By changing 'command "._isolateobjects'" to 'command "select"

 

Will that work for my usage? Only selecting means this way it allows me too enter into any command available when objects are selected.

Share this post


Link to post
Share on other sites
jdiala

bhull1985, Try this. Unlike the ":L" option on ssget which was used on the first code which removes entities out of the current view. The code below, your selection window will be the current view after you invoke the command.

 

(defun C:test (/  i ss vc scs hv l wh b p *error* c)
(defun *error* (m)
(command "_.undo" "end")
(setvar 'cmdecho c)
(princ m)
)

(setq vc (getvar 'viewctr)
      scs (getvar 'screensize)
      hv (/ (getvar 'viewsize) 2.)
      l    nil
      wh  (* hv (/ (car scs) (cadr scs)))
   c   (getvar 'cmdecho))
(setvar 'cmdecho 0)	   
(command "_.undo" "_begin")      
(if      
(setq ss (ssget ":L" '((0 . "INSERT"))))
  (repeat (setq i (sslength ss))
    (if
      (not
        (member (setq bn (cdr (assoc 2 (entget (ssname ss (setq i (1- i))))))) l))
          (setq l (cons bn l))
     )
   )
 )
 (mapcar 
   (function 
     (lambda (x)     
       (if
         (setq ss 
           (ssget "_X" 
             (list 
               (cons 0 "INSERT") 
               (cons 2 x)
             )
           )
         )
         (repeat 
	    (setq i (sslength ss))
             (setq i (1- i)
                   p (cdr (assoc 10 (entget (setq b (ssname ss i)))))
	      )
        (if 
             (not 
		    (and
                 (> (car p) (- (car vc)  wh))
                 (> (cadr p) (- (cadr vc) hv))
                 (< (car p) (+ (car vc)  wh))
                 (< (cadr p) (+ (cadr vc) hv))
               )
		  )
             (entdel b)
           )   
         )
    )
  )
)  
l
 )
(command "_.undo" "_end")
(setvar 'cmdecho c)
(princ) 
)

Share this post


Link to post
Share on other sites
3dwannab

My apologies for not testing with the code you posted containing the:

(command "._isolateobjects" nss "")

 

but it still gets similar items on all the model space, not what's visible on the monitor. See attached. I only what the green lines of the internal stairs picked. It's picking up the external stairs at the top right. Thanks.

 

screen.jpg

What I want.

 

screen extents.jpg

Result

Share this post


Link to post
Share on other sites
wimal

(command "._isolateobjects" nss "")

In CAD 2006 the above command is not avilable. what can I use insted of ISOLATEOBJECTS

Share this post


Link to post
Share on other sites
jdiala
My apologies for not testing with the code you posted containing the:

(command "._isolateobjects" nss "")

 

but it still gets similar items on all the model space, not what's visible on the monitor. See attached. I only what the green lines of the internal stairs picked. It's picking up the external stairs at the top right. Thanks.

 

Try this:

 

(defun C:test (/ vc scs hv wh i l nss ss tssi)
;;; JDiala 10-23-13 ;;;
;;;; Cadtutor.net ;;;;;
(setq vc (getvar 'viewctr)
      scs (getvar 'screensize)
      hv (/ (getvar 'viewsize) 2.)
      wh (* hv (/ (car scs) (cadr scs)))
      l   nil
      nss (ssadd)
 ) 
 (mapcar 
   (function
     (lambda (x) 
       (repeat 
         (setq i 
           (sslength 
             (setq tss 
               (ssget "_W" 
                 (list (- (car vc) wh) (- (cadr vc) hv) 0.0)  
                 (list (+ (car vc) wh) (+ (cadr vc) hv) 0.0) 
                 (list (cons 0 (if (= (car x) "INSERT") "INSERT" (car x))) 
                   (if (= (car x) "INSERT")
                       (cons 2 (cadr x))
                       (cons 8 (cadr x))
                   )
                 )
               )
             )
           )
         ) 
         (ssadd (ssname tss (setq i (1- i))) nss)
       )
     )
   )
 (progn
   (setq ss (ssget ))
   (repeat (setq i (sslength ss))
     (setq i (1- i) 
           e (ssname ss i))
     (cond
       ( (= l nil)
         (if (= "INSERT" (cdr (assoc 0 (entget e))))
             (setq l (cons (list "INSERT" (cdr (assoc 2 (entget e)))) l))
             (setq l (cons (list (cdr (assoc 0 (entget e))) (cdr (assoc 8 (entget e)))) l )) 
         )
       )
       ( (not 
           (member 
             (if (= "INSERT" (cdr (assoc 0 (entget e))))
                 (list "INSERT" (cdr (assoc 2 (entget e))))
                 (list (cdr (assoc 0 (entget e))) (cdr (assoc 8 (entget e))))
             ) l
           )
         )
         (if (= "INSERT" (cdr (assoc 0 (entget e))))
             (setq l (cons (list "INSERT" (cdr (assoc 2 (entget e)))) l))
             (setq l (cons (list (cdr (assoc 0 (entget e))) (cdr (assoc 8 (entget e)))) l )) 
         )
       )
       (t (setq l l))
     )
   )
 )
)
(command "_.isolateobjects" nss "")
)

Share this post


Link to post
Share on other sites
3dwannab

Okay that's strange. I've tested that old code again and it works. Sorry for been such a pain. I don't know where I went wrong. I've changed the:

(command "_.isolateobjects" nss "")

To suit my needs:

(command "_.pselect" nss "")

Can't thank you enough. Better than the built in function in my opinion. This way you can zoom extents and do that or work in a specific area without having to deselect more than you need.

 

KUDOS.

Share this post


Link to post
Share on other sites
wimal

Thanks a lot pselect is working.

Share this post


Link to post
Share on other sites
3dwannab

It's jdiala you should be thanking ;)

Share this post


Link to post
Share on other sites
wimal

(defun C:test (/  sel_set_win minv maxv slist ss i  nss)   (defun sel_set_win (/ c tss)     (if (not nss) (setq nss (ssadd)))       (setq tss [b][color=red](ssget "_C" minv maxv slist)[/color][/b])       (repeat (setq c (sslength tss))         (ssadd (ssname tss (setq c (1- c))) nss)         )   ) (setq minv (getvar 'extmin) maxv (getvar 'extmax))  (setq ss (ssget ":L" )) (repeat (setq i (sslength ss))   (if slist (setq slist nil))   (if (= "INSERT" (cdr (assoc 0 (entget (ssname ss (setq i (1- i)))))))       (setq slist (list (cons 0 "INSERT") (cons 2 (cdr (assoc 2 (entget (ssname ss i)))))))       (setq slist (list                      (cons 0 (cdr (assoc 0 (entget (ssname ss i)))))             (cons 8 (cdr (assoc 8 (entget (ssname ss i)))))                  ))   )     (sel_set_win) ) (command "._pselect" nss "") )

Mr.jdiala's above code is working with cad 2006 perfectly.

Please can you explain me function of following part of the code

(ssget "_C" minv maxv slist)

Share this post


Link to post
Share on other sites
marko_ribar

I think that that's typo mistake, if I am to be asked I would change "_C" to "_W" and be satisfied with result...

Share this post


Link to post
Share on other sites
wimal

No even C or W the code is correct. But I need to understand the function of the code.I mean how it filter the correct

object inside the window minv and maxv

Please explain some LISP expert.

Share this post


Link to post
Share on other sites
jdiala
No even C or W the code is correct. But I need to understand the function of the code.I mean how it filter the correct

object inside the window minv and maxv

Please explain some LISP expert.

 

Note: I'm not a lisp expert.

I used maximum extents of the drawing which is extmin and extmax variables. Since option "_C" will only select on what is visible on the screen it doesn't matter if the 2 points for my selection is outside of the screen.

 

for complete explanation Read This...

from a lisp expert, Lee-Mac

Share this post


Link to post
Share on other sites
Lee Mac

Thank you for your compliments jdiala - though I too still learn from others :thumbsup:

 

Here is another way to write the program:

([color=BLUE]defun[/color] c:test ( [color=BLUE]/[/color] enx idx itm lst sel )
   ([color=BLUE]if[/color]
       ([color=BLUE]setq[/color] sel
           ([color=BLUE]ssget[/color]
               ([color=BLUE]list[/color]
                   ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'cvport))
                       ([color=BLUE]cons[/color] 410 ([color=BLUE]getvar[/color] 'ctab))
                      '(410 . [color=MAROON]"Model"[/color])
                   )
               )
           )
       )
       ([color=BLUE]progn[/color]
           ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] idx ([color=BLUE]sslength[/color] sel))
               ([color=BLUE]setq[/color] enx ([color=BLUE]entget[/color] ([color=BLUE]ssname[/color] sel ([color=BLUE]setq[/color] idx ([color=BLUE]1-[/color] idx)))))
               ([color=BLUE]if[/color] ([color=BLUE]equal[/color] '(0 . [color=MAROON]"INSERT"[/color]) ([color=BLUE]assoc[/color] 0 enx))
                   ([color=BLUE]setq[/color] itm
                       ([color=BLUE]list[/color]
                          '(-4 . [color=MAROON]"<AND"[/color])
                          '(0 . [color=MAROON]"INSERT"[/color])
                           ([color=BLUE]assoc[/color] 2 enx)
                           ([color=BLUE]assoc[/color] 8 enx)
                          '(-4 . [color=MAROON]"AND>"[/color])
                       )
                   )
                   ([color=BLUE]setq[/color] itm
                       ([color=BLUE]list[/color]
                          '(-4 . [color=MAROON]"<AND"[/color])
                           ([color=BLUE]assoc[/color] 0 enx)
                           ([color=BLUE]assoc[/color] 8 enx)
                          '(-4 . [color=MAROON]"AND>"[/color])
                       )
                   )
               )
               ([color=BLUE]or[/color] ([color=BLUE]member[/color] itm lst)
                   ([color=BLUE]setq[/color] lst ([color=BLUE]cons[/color] itm lst))
               )
           )
           ([color=BLUE]if[/color]
               ([color=BLUE]setq[/color] sel
                   ([color=BLUE]apply[/color] '[color=BLUE]ssget[/color]
                       ([color=BLUE]append[/color] '([color=MAROON]"_C"[/color]) ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]trans[/color] x 0 1)) (LM:ViewportExtents))
                           ([color=BLUE]list[/color]
                               ([color=BLUE]append[/color]
                                  '((-4 . [color=MAROON]"<OR"[/color]))
                                   ([color=BLUE]apply[/color] '[color=BLUE]append[/color] lst)
                                  '((-4 . [color=MAROON]"OR>"[/color]))
                                   ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'cvport))
                                       ([color=BLUE]list[/color] ([color=BLUE]cons[/color] 410 ([color=BLUE]getvar[/color] 'ctab)))
                                      '((410 . [color=MAROON]"Model"[/color]))
                                   )
                               )
                           )
                       )
                   )
               )
               ([color=BLUE]command[/color] [color=MAROON]"_.isolateobjects"[/color] sel [color=MAROON]""[/color])
           )
       )
   )
   ([color=BLUE]princ[/color])
)

[color=GREEN];; Viewport Extents  -  Lee Mac[/color]
[color=GREEN];; Returns two WCS points describing the lower-left and[/color]
[color=GREEN];; upper-right corners of the active viewport.[/color]

([color=BLUE]defun[/color] LM:ViewportExtents ( [color=BLUE]/[/color] c h v )
   ([color=BLUE]setq[/color] c ([color=BLUE]trans[/color] ([color=BLUE]getvar[/color] 'viewctr) 1 0)
         h ([color=BLUE]/[/color] ([color=BLUE]getvar[/color] 'viewsize) 2.0)
         v ([color=BLUE]list[/color] ([color=BLUE]*[/color] h ([color=BLUE]apply[/color] '[color=BLUE]/[/color] ([color=BLUE]getvar[/color] 'screensize))) h)
   )
   ([color=BLUE]list[/color] ([color=BLUE]mapcar[/color] '[color=BLUE]-[/color] c v) ([color=BLUE]mapcar[/color] '[color=BLUE]+[/color] c v))
)
([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

Note: the above is incompatible with dynamic block references.

Share this post


Link to post
Share on other sites
jdiala

Nice code Lee. You take care of UCS and ctab which I failed to consider. Lesson learned again from you. Thank you.

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...