masao_8 Posted June 14 Posted June 14 (edited) Is it possible to use the grread function to deselect objects by holding down the SHIFT key+left click? Edited June 14 by masao_8 Quote
Steven P Posted June 14 Posted June 14 I think you would need to test for 'shift' being pressed and the test for a left mouse entity selection. Do a 'princ' on your grread loop to display what you are doing, shift and select something - which should give you what you want to test for. 2 Quote
mhupp Posted June 15 Posted June 15 Isn't that how CAD works already? you select something either by mouse clicke or window it will be highlighted hold shift to deselect it the same way. I know if you have to many things selected they are no longer highlighted. 1 1 Quote
SLW210 Posted June 15 Posted June 15 1 hour ago, mhupp said: Isn't that how CAD works already? you select something either by mouse clicke or window it will be highlighted hold shift to deselect it the same way. I know if you have to many things selected they are no longer highlighted. Doesn't that depend on PICKADD value? I do believe the default is select to add and shift select to deselect from selection set. To that end, it needs to be clarified from OP what they need, my WAG is something being already done with grread and need to deselect. AFAIK (and that's very little, mostly from my previous thread ) The left click is doable with grread, but it would ignore the SHIFT (also CTRL, etc.), so probably would need something else to show the SHIFT key is pressed. Which reminds me I need to get back to work on that and the centerline on rivers, roads, etc. problem when I get regular work caught up. 1 Quote
pkenewell Posted June 15 Posted June 15 Perhaps you could use the undocumented (acet-sys-shift-down) express tools function within the grread loop? Then you would have to manipulate highlighting with (redraw [3/4]) and use (ssadd) and (ssdel) to update the selection set. 2 Quote
pkenewell Posted June 16 Posted June 16 (edited) @masao_8 Here is a solution for a simple single selection add and SHIFT-Select to remove. Perhaps this will give you a basis for starting: ;; Function to do a simple Select/Deselect using grread. ;; By PJK - 6/16/2026 (defun pjk-grread-Select (/ done en grl grc grv ss) (if acet-load-expresstools (acet-load-expresstools)) (setq ss (ssadd)) (princ "\nSelect to add objects or SHIFT+Select to remove from selection set: ") (while (not done) (setq grl (grread T 15 2) grc (car grl) grv (cadr grl) ) (cond ((= grc 3) (if (setq en (car (nentselp grv))) (if (acet-sys-shift-down) (progn (if (ssmemb en ss)(ssdel en ss)) (redraw en 4) ) (progn (ssadd en ss) (redraw en 3) ) ) ) ) ((= grc 2) (setq done (if (vl-position grv '(13 32)) T nil)) ) ((= grc 25)(setq done T)) ) ) (if (> (sslength ss) 0) (progn (foreach i (mapcar 'cadr (ssnamex ss))(redraw i 4)) ss ) nil ) ) Edited June 16 by pkenewell 1) Added right-click completion to the loop. 2) added redraw of selection set on completion of the routine and returns nil if the selection set is empty. 4 Quote
masao_8 Posted 23 hours ago Author Posted 23 hours ago thanks all!! @pkenewell thanks you. this is good. but i want to use "ssget" has "quick iniget". use express tools can do it,but not express tools how to do it. (defun _redrawss (ss mode / i) (if (and ss (= (type ss) 'PICKSET) (> (sslength ss) 0)) (repeat (setq i (sslength ss)) (redraw (ssname ss (setq i (1- i))) mode) ) ) ) (defun _getwindowselection (msg p1 filter flag / gr p3 p2 p4 col winflag) (princ msg) (setq p3 nil) (while (/= 3 (car (setq gr (grread t 13 0)))) (if (= 5 (car gr)) (progn (redraw) (setq p3 (cadr gr)) (if (and p1 p3) (progn (setq p2 (list (car p3) (cadr p1) (caddr p3)) p4 (list (car p1) (cadr p3) (caddr p3)) col (if (or (eq flag "_C") (minusp (- (car p3) (car p1)))) -256 256) ) (grvecs (list col p1 p2 p1 p4 p2 p3 p3 p4)) ) ) ) ) ) (redraw) (if (and p1 p3) (progn (setq winflag (cond (flag) ((minusp (- (car p3) (car p1))) "_C") (t "_W") ) ) (if filter (ssget winflag p1 p3 (list filter)) (ssget winflag p1 p3) ) ) nil ) ) ;;BYLAYER (defun get-real-linetype (ed / lt lay layed) (setq lt (assoc 6 ed)) (if (or (null lt) (= (cdr lt) "BYLAYER")) (progn (setq lay (cdr (assoc 8 ed))) (if (setq layed (tblsearch "LAYER" lay)) (cdr (assoc 6 layed)) "CONTINUOUS" ) ) (cdr lt) ) ) ;;BYLAYER (defun get-real-color (ed / col lay layed) (setq col (assoc 62 ed)) (if (or (null col) (= (cdr (assoc 62 ed)) 256)) ; 256 = BYLAYER (progn (setq lay (cdr (assoc 8 ed))) (if (setq layed (tblsearch "LAYER" lay)) (cdr (assoc 62 layed)) 7 ) ) (cdr col) ) ) ;; (defun c:CDIA (/ base-ent base-ed base-ltype base-color ss express gr g1 g2 p1 pick filt i e) ;; select circle (princ "\n-> select circle...") (if (null (setq base-ent (entsel))) (progn (princ "\n-> not select。") (princ)) (progn (setq base-ed (entget (car base-ent))) (if (/= (cdr (assoc 0 base-ed)) "CIRCLE") (progn (princ "\n-> not circle。") (princ)) (progn (setq base-ltype (get-real-linetype base-ed)) (setq base-color (get-real-color base-ed)) (princ (strcat "\n->linetype: " base-ltype ",color: " (itoa base-color))) ;; Express Tools "SHIFT" (setq express (and (vl-position "acetutil.arx" (arx)) (not (vl-catch-all-error-p (vl-catch-all-apply 'acet-sys-shift-down nil))) ) ) ;; (setq ss (ssadd)) ;; (setq filt (list (cons 0 "CIRCLE") (cons 6 base-ltype) (cons 62 base-color) ) ) (princ "\nSelect objects: ") ;; (while (/= 2 (car (setq gr (grread t 13 2)))) (setq g1 (car gr) g2 (cadr gr)) (_redrawss ss 3) (cond ((= g1 5) nil) ; ((= g1 3) ; ;; click (if (setq pick (ssget g2 filt)) (progn (setq pick (ssname pick 0)) (cond ((and express (acet-sys-shift-down)) ; SHIFT remove (if (ssmemb pick ss) (progn (ssdel pick ss) (redraw pick 4)) ) ) (t (if (not (ssmemb pick ss)) (ssadd pick ss) ) ) ) ) ;; (if (setq pick (_getwindowselection "\nSpecify Opposite Corner: " g2 nil nil)) (cond ((and express (acet-sys-shift-down)) ; SHIFT + remove (repeat (setq i (sslength pick)) (setq e (ssname pick (setq i (1- i)))) (if (and (ssmemb e ss) (wcmatch (cdr (assoc 0 (entget e))) "CIRCLE")) (progn (ssdel e ss) (redraw e 4)) ) ) ) (t ; (repeat (setq i (sslength pick)) (setq e (ssname pick (setq i (1- i)))) (if (and (= (cdr (assoc 0 (entget e))) "CIRCLE") (= (get-real-linetype (entget e)) base-ltype) (= (get-real-color (entget e)) base-color) (not (ssmemb e ss)) ) (ssadd e ss) ) ) ) ) ) ) (princ "\nSelect objects: ") ) ) ) ;; (setq g2 (cadr gr)) (cond ((wcmatch (strcase (chr g2)) "W") (if (setq p1 (getpoint "\nSpecify First Corner for Window: ")) (if (setq pick (_getwindowselection "\nSpecify Opposite Corner: " p1 nil "_W")) (repeat (setq i (sslength pick)) (setq e (ssname pick (setq i (1- i)))) (if (and (= (cdr (assoc 0 (entget e))) "CIRCLE") (= (get-real-linetype (entget e)) base-ltype) (= (get-real-color (entget e)) base-color) (not (ssmemb e ss)) ) (ssadd e ss) ) ) ) ) ) ((wcmatch (strcase (chr g2)) "C") (if (setq p1 (getpoint "\nSpecify First Corner for Crossing: ")) (if (setq pick (_getwindowselection "\nSpecify Opposite Corner: " p1 nil "_C")) (repeat (setq i (sslength pick)) (setq e (ssname pick (setq i (1- i)))) (if (and (= (cdr (assoc 0 (entget e))) "CIRCLE") (= (get-real-linetype (entget e)) base-ltype) (= (get-real-color (entget e)) base-color) (not (ssmemb e ss)) ) (ssadd e ss) ) ) ) ) ) ((wcmatch (strcase (chr g2)) "B") (if (setq p1 (getpoint "\nSpecify First Corner for Box: ")) (if (setq pick (_getwindowselection "\nSpecify Opposite Corner: " p1 nil nil)) (repeat (setq i (sslength pick)) (setq e (ssname pick (setq i (1- i)))) (if (and (= (cdr (assoc 0 (entget e))) "CIRCLE") (= (get-real-linetype (entget e)) base-ltype) (= (get-real-color (entget e)) base-color) (not (ssmemb e ss)) ) (ssadd e ss) ) ) ) ) ) ) (_redrawss ss 4) ; ;; (if (> (sslength ss) 0) (progn (princ (strcat "\n->total " (itoa (sslength ss)) " circles,add textmark...")) (setq i 0) (while (< i (sslength ss)) (setq ent (ssname ss i)) (setq ed (entget ent)) (setq center (cdr (assoc 10 ed))) (setq radius (cdr (assoc 40 ed))) (entmake (list '(0 . "TEXT") (cons 8 (cdr (assoc 8 ed))) ; (cons 10 center) ; (cons 11 center) ; '(40 . 2.5) ; (cons 1 (strcat "%%C" (rtos (* radius 2) 2 2))) '(7 . "STANDARD") '(71 . 0) '(72 . 1) ; '(73 . 2) ; ) ) (setq i (1+ i)) ) (princ "\n-> Finish!") ) (princ "\n-> not circle。") ) ) ) ) ) (princ) ) ;; (princ "\n CDIA。") (princ) Quote
masao_8 Posted 10 hours ago Author Posted 10 hours ago 13 hours ago, masao_8 said: thanks all!! @pkenewell thanks you. this is good. but i want to use "ssget" has "quick iniget". use express tools can do it,but CAD not express tools how to use this code. (defun _redrawss (ss mode / i) (if (and ss (= (type ss) 'PICKSET) (> (sslength ss) 0)) (repeat (setq i (sslength ss)) (redraw (ssname ss (setq i (1- i))) mode) ) ) ) (defun _getwindowselection (msg p1 filter flag / gr p3 p2 p4 col winflag) (princ msg) (setq p3 nil) (while (/= 3 (car (setq gr (grread t 13 0)))) (if (= 5 (car gr)) (progn (redraw) (setq p3 (cadr gr)) (if (and p1 p3) (progn (setq p2 (list (car p3) (cadr p1) (caddr p3)) p4 (list (car p1) (cadr p3) (caddr p3)) col (if (or (eq flag "_C") (minusp (- (car p3) (car p1)))) -256 256) ) (grvecs (list col p1 p2 p1 p4 p2 p3 p3 p4)) ) ) ) ) ) (redraw) (if (and p1 p3) (progn (setq winflag (cond (flag) ((minusp (- (car p3) (car p1))) "_C") (t "_W") ) ) (if filter (ssget winflag p1 p3 (list filter)) (ssget winflag p1 p3) ) ) nil ) ) ;;BYLAYER (defun get-real-linetype (ed / lt lay layed) (setq lt (assoc 6 ed)) (if (or (null lt) (= (cdr lt) "BYLAYER")) (progn (setq lay (cdr (assoc 8 ed))) (if (setq layed (tblsearch "LAYER" lay)) (cdr (assoc 6 layed)) "CONTINUOUS" ) ) (cdr lt) ) ) ;;BYLAYER (defun get-real-color (ed / col lay layed) (setq col (assoc 62 ed)) (if (or (null col) (= (cdr (assoc 62 ed)) 256)) ; 256 = BYLAYER (progn (setq lay (cdr (assoc 8 ed))) (if (setq layed (tblsearch "LAYER" lay)) (cdr (assoc 62 layed)) 7 ) ) (cdr col) ) ) ;; (defun c:CDIA (/ base-ent base-ed base-ltype base-color ss express gr g1 g2 p1 pick filt i e) ;; select circle (princ "\n-> select circle...") (if (null (setq base-ent (entsel))) (progn (princ "\n-> not select。") (princ)) (progn (setq base-ed (entget (car base-ent))) (if (/= (cdr (assoc 0 base-ed)) "CIRCLE") (progn (princ "\n-> not circle。") (princ)) (progn (setq base-ltype (get-real-linetype base-ed)) (setq base-color (get-real-color base-ed)) (princ (strcat "\n->linetype: " base-ltype ",color: " (itoa base-color))) ;; Express Tools "SHIFT" (setq express (and (vl-position "acetutil.arx" (arx)) (not (vl-catch-all-error-p (vl-catch-all-apply 'acet-sys-shift-down nil))) ) ) ;; (setq ss (ssadd)) ;; (setq filt (list (cons 0 "CIRCLE") (cons 6 base-ltype) (cons 62 base-color) ) ) (princ "\nSelect objects: ") ;; (while (/= 2 (car (setq gr (grread t 13 2)))) (setq g1 (car gr) g2 (cadr gr)) (_redrawss ss 3) (cond ((= g1 5) nil) ; ((= g1 3) ; ;; click (if (setq pick (ssget g2 filt)) (progn (setq pick (ssname pick 0)) (cond ((and express (acet-sys-shift-down)) ; SHIFT remove (if (ssmemb pick ss) (progn (ssdel pick ss) (redraw pick 4)) ) ) (t (if (not (ssmemb pick ss)) (ssadd pick ss) ) ) ) ) ;; (if (setq pick (_getwindowselection "\nSpecify Opposite Corner: " g2 nil nil)) (cond ((and express (acet-sys-shift-down)) ; SHIFT + remove (repeat (setq i (sslength pick)) (setq e (ssname pick (setq i (1- i)))) (if (and (ssmemb e ss) (wcmatch (cdr (assoc 0 (entget e))) "CIRCLE")) (progn (ssdel e ss) (redraw e 4)) ) ) ) (t ; (repeat (setq i (sslength pick)) (setq e (ssname pick (setq i (1- i)))) (if (and (= (cdr (assoc 0 (entget e))) "CIRCLE") (= (get-real-linetype (entget e)) base-ltype) (= (get-real-color (entget e)) base-color) (not (ssmemb e ss)) ) (ssadd e ss) ) ) ) ) ) ) (princ "\nSelect objects: ") ) ) ) ;; (setq g2 (cadr gr)) (cond ((wcmatch (strcase (chr g2)) "W") (if (setq p1 (getpoint "\nSpecify First Corner for Window: ")) (if (setq pick (_getwindowselection "\nSpecify Opposite Corner: " p1 nil "_W")) (repeat (setq i (sslength pick)) (setq e (ssname pick (setq i (1- i)))) (if (and (= (cdr (assoc 0 (entget e))) "CIRCLE") (= (get-real-linetype (entget e)) base-ltype) (= (get-real-color (entget e)) base-color) (not (ssmemb e ss)) ) (ssadd e ss) ) ) ) ) ) ((wcmatch (strcase (chr g2)) "C") (if (setq p1 (getpoint "\nSpecify First Corner for Crossing: ")) (if (setq pick (_getwindowselection "\nSpecify Opposite Corner: " p1 nil "_C")) (repeat (setq i (sslength pick)) (setq e (ssname pick (setq i (1- i)))) (if (and (= (cdr (assoc 0 (entget e))) "CIRCLE") (= (get-real-linetype (entget e)) base-ltype) (= (get-real-color (entget e)) base-color) (not (ssmemb e ss)) ) (ssadd e ss) ) ) ) ) ) ((wcmatch (strcase (chr g2)) "B") (if (setq p1 (getpoint "\nSpecify First Corner for Box: ")) (if (setq pick (_getwindowselection "\nSpecify Opposite Corner: " p1 nil nil)) (repeat (setq i (sslength pick)) (setq e (ssname pick (setq i (1- i)))) (if (and (= (cdr (assoc 0 (entget e))) "CIRCLE") (= (get-real-linetype (entget e)) base-ltype) (= (get-real-color (entget e)) base-color) (not (ssmemb e ss)) ) (ssadd e ss) ) ) ) ) ) ) (_redrawss ss 4) ; ;; (if (> (sslength ss) 0) (progn (princ (strcat "\n->total " (itoa (sslength ss)) " circles,add textmark...")) (setq i 0) (while (< i (sslength ss)) (setq ent (ssname ss i)) (setq ed (entget ent)) (setq center (cdr (assoc 10 ed))) (setq radius (cdr (assoc 40 ed))) (entmake (list '(0 . "TEXT") (cons 8 (cdr (assoc 8 ed))) ; (cons 10 center) ; (cons 11 center) ; '(40 . 2.5) ; (cons 1 (strcat "%%C" (rtos (* radius 2) 2 2))) '(7 . "STANDARD") '(71 . 0) '(72 . 1) ; '(73 . 2) ; ) ) (setq i (1+ i)) ) (princ "\n-> Finish!") ) (princ "\n-> not circle。") ) ) ) ) ) (princ) ) ;; (princ "\n CDIA。") (princ) Quote
Tsuky Posted 1 hour ago Posted 1 hour ago I don't know if I understood exactly what the need was, but here is my proposal. Moving the cursor over entities adds to the selection if the mode is active (left-click) and pressing + or - toggles to add or remove. (defun C:AutoSel ( / oldpcka key_mod ss tmp key_sel e_sel) (setq oldpcka (getvar "PICKADD") key_mod 'ssadd) (setvar "PICKADD" 2) (or (setq ss (ssget "_I")) (setq ss (ssget "_P")) ) (if ss (sssetfirst nil ss) (setq ss (ssadd))) (princ "\n[+/-]: AutoSelect ADD/REMOVE [Left-Click]: AutoSelect ON/OFF [Right-Click]: Quit AutoSelect ") (princ "\nAutoSelect <<OFF>>") (while (or (= 5 (car (setq tmp (grread t 5 2)))) (= 3 (car tmp)) (member tmp '((2 43) (2 45)))) (cond ((= 2 (car tmp)) (cond ((eq (cadr tmp) 43) (setq key_mod 'ssadd) (princ "\nMode add select") ) ((eq (cadr tmp) 45) (setq key_mod 'ssdel) (princ "\nMode remove select") ) ) ) ((= 3 (car tmp)) (if (null key_sel) (progn (setq key_sel T) (princ "\nAutoSelect <<ON>>") ) (progn (setq key_sel nil) (princ "\nAutoSelect <<OFF>>") ) ) ) ((= 5 (car tmp)) (cond ((and key_sel (setq e_sel (nentselp (cadr tmp)))) (cond ((eq 'ENAME (type (car (last e_sel)))) ((eval key_mod) (car (last e_sel)) ss) ) ((eq "VERTEX" (cdr (assoc 0 (entget (car e_sel))))) ((eval key_mod) (cdr (assoc 330 (entget (car e_sel)))) ss) ) (T ((eval key_mod) (car e_sel) ss)) ) (sssetfirst nil ss) ) (T nil) ) ) (T (princ "\nAbnormal command shutdown ")) ) ) (setvar "PICKADD" oldpcka) (princ "\nEnd of command. ") (prin1) ) 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.