sadhu Posted July 22, 2016 Share Posted July 22, 2016 Hello, I'd like to include in a lisp routine the "rectangle selection effect" that exists in autocad. When you click any point on the screen and then a second point this effect appears. Something like this but with a "rectangle effect" instead of a line. (setq pt1 (getpoint "Select point 1... ")) (setq pt2 (getpoint pt1 "Opposite corner... ")) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 22, 2016 Share Posted July 22, 2016 (setq pt2 (getcorner pt1 "\nOpposite corner... ")) Quote Link to comment Share on other sites More sharing options...
sadhu Posted July 22, 2016 Author Share Posted July 22, 2016 Thank you Tharwat. Simple as that it was. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 22, 2016 Share Posted July 22, 2016 Yeah ... You are welcome. Quote Link to comment Share on other sites More sharing options...
Grrr Posted July 24, 2016 Share Posted July 24, 2016 Decided to do a daily practice: (defun C:test ( / oldclp pt1 LoopFlag UserIn TypeUserIn ReturnChar vsz SS SSn in1 in2 ) (sssetfirst nil nil) (while T (if (setq pt1 (getpoint "\nSpecify first point" )) (progn (setq oldclp (getvar 'clipromptlines)) (setvar 'clipromptlines 1) (redraw) (princ "\nSpecify second point: ") (setq LoopFlag T) (while LoopFlag (setq UserIn (grread T)) (setq TypeUserIn (car UserIn)) (setq ReturnChar (cadr UserIn)) (cond ((= TypeUserIn 5) ; cursor is moved (princ "\nSpecify second point: ") (setq vsz (* (getvar 'viewsize) 10)) (or (setq in1 (inters pt1 (polar pt1 (angtof "90") vsz) ReturnChar (polar ReturnChar (angtof "0") vsz))) (setq in1 (inters pt1 (polar pt1 (angtof "90") vsz) ReturnChar (polar ReturnChar (angtof "180") vsz))) (setq in1 (inters pt1 (polar pt1 (angtof "270") vsz) ReturnChar (polar ReturnChar (angtof "0") vsz))) (setq in1 (inters pt1 (polar pt1 (angtof "270") vsz) ReturnChar (polar ReturnChar (angtof "180") vsz))) ) (or (setq in2 (inters pt1 (polar pt1 (angtof "0") vsz) ReturnChar (polar ReturnChar (angtof "90") vsz))) (setq in2 (inters pt1 (polar pt1 (angtof "0") vsz) ReturnChar (polar ReturnChar (angtof "270") vsz))) (setq in2 (inters pt1 (polar pt1 (angtof "180") vsz) ReturnChar (polar ReturnChar (angtof "90") vsz))) (setq in2 (inters pt1 (polar pt1 (angtof "180") vsz) ReturnChar (polar ReturnChar (angtof "270") vsz))) ) (if (and pt1 in1 in2 ReturnChar) (progn (redraw) (grvecs (list 1 pt1 in1 1 pt1 in2 1 ReturnChar in1 1 ReturnChar in2 ) ) ) (redraw) ) ) ((= TypeUserIn 3) ; LMB is pressed (if oldclp (setvar 'clipromptlines oldclp)) (setq LoopFlag nil) (if SS (progn (setq SSn SS) (sssetfirst nil nil))) (if (setq SS (ssget "_CP" (list pt1 in1 ReturnChar in2))) (progn (setq SS (acet-ss-union (list SSn SS))) ; requires express tools! (sssetfirst nil SS) ) (setq SS nil) ) ) (T nil) );cond );while LoopFlag ) ) ) (princ) ) Its based on what I've learned from Tharwat, Lee Mac, CAB... Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 24, 2016 Share Posted July 24, 2016 Its based on what I've learned from Tharwat, Lee Mac, CAB... Quickie one (defun c:sel (/ p1 gr p2 p3) ;; Tharwat - Emulate cursor selection set ;; (if (setq p1 (getpoint "\n First point :")) (while (eq (car (setq gr (grread t 15 0))) 5) (redraw) (grvecs (list -3 p1 (setq p2 (list (car (cadr gr)) (cadr p1) 0.)) p2 (cadr gr) (cadr gr) (setq p3 (list (car p1) (cadr (cadr gr)) 0.)) p3 p1 ) ) ) ) (redraw) (princ) ) Quote Link to comment Share on other sites More sharing options...
Grrr Posted July 24, 2016 Share Posted July 24, 2016 Quickie one (defun c:sel (/ p1 gr p2 p3) ;; Tharwat - Emulate cursor selection set ;; (if (setq p1 (getpoint "\n First point :")) (while (eq (car (setq gr (grread t 15 0))) 5) (redraw) (grvecs (list -3 p1 (setq p2 (list (car (cadr gr)) (cadr p1) 0.)) p2 (cadr gr) (cadr gr) (setq p3 (list (car p1) (cadr (cadr gr)) 0.)) p3 p1 ) ) ) ) (redraw) (princ) ) Nice one! Now I see that I might had to use the X and Y values to find pt2 and pt3. Still my (inters) method might work as an alternative way. Also I didn't knew that grvecs could work this way, though I was reading the HELP file. ...and your code is alot shorter Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 24, 2016 Share Posted July 24, 2016 Always try to give the user an option to choose which way to go with or to cancel the program safely, but in your program you forced the user to hit ESC button to end the program. Quote Link to comment Share on other sites More sharing options...
Grrr Posted July 24, 2016 Share Posted July 24, 2016 Always try to give the user an option to choose which way to go with or to cancel the program safely, but in your program you forced the user to hit ESC button to end the program. Yes, I know.. this is just a habbit of mine (I test the code's behaviour multiple times in ACAD, before I decide to post it).. and because I'm lazy to re-run the command. Quote Link to comment Share on other sites More sharing options...
sadhu Posted July 26, 2016 Author Share Posted July 26, 2016 Thanks again Tharwat. Very helpful. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 26, 2016 Share Posted July 26, 2016 Thanks again Tharwat. Very helpful. You are most welcome. Quote Link to comment Share on other sites More sharing options...
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.