3dwannab Posted October 21, 2013 Posted October 21, 2013 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. Quote
tzframpton Posted October 21, 2013 Posted October 21, 2013 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. Quote
3dwannab Posted October 21, 2013 Author Posted October 21, 2013 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. Quote
jdiala Posted October 21, 2013 Posted October 21, 2013 (edited) 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 October 21, 2013 by jdiala Quote
Bhull1985 Posted October 21, 2013 Posted October 21, 2013 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 Quote
jdiala Posted October 21, 2013 Posted October 21, 2013 Hey Jdialathat 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. Quote
3dwannab Posted October 21, 2013 Author Posted October 21, 2013 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. Quote
jdiala Posted October 22, 2013 Posted October 22, 2013 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) ) Quote
3dwannab Posted October 22, 2013 Author Posted October 22, 2013 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. What I want. Result Quote
wimal Posted October 23, 2013 Posted October 23, 2013 (command "._isolateobjects" nss "") In CAD 2006 the above command is not avilable. what can I use insted of ISOLATEOBJECTS Quote
jdiala Posted October 23, 2013 Posted October 23, 2013 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 "") ) Quote
3dwannab Posted October 23, 2013 Author Posted October 23, 2013 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. Quote
3dwannab Posted October 24, 2013 Author Posted October 24, 2013 It's jdiala you should be thanking Quote
wimal Posted October 27, 2013 Posted October 27, 2013 (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) Quote
marko_ribar Posted October 27, 2013 Posted October 27, 2013 I think that that's typo mistake, if I am to be asked I would change "_C" to "_W" and be satisfied with result... Quote
wimal Posted October 27, 2013 Posted October 27, 2013 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. Quote
jdiala Posted October 27, 2013 Posted October 27, 2013 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 Quote
Lee Mac Posted October 27, 2013 Posted October 27, 2013 Thank you for your compliments jdiala - though I too still learn from others 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. Quote
jdiala Posted October 28, 2013 Posted October 28, 2013 Nice code Lee. You take care of UCS and ctab which I failed to consider. Lesson learned again from you. Thank you. Quote
Recommended Posts
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.