mhy3sx Posted March 7, 2023 Share Posted March 7, 2023 Hi. This code create rectangle with 3 ways 1) By picking 3 points 2) Pick 2 points and give the length of the side (to the direction you want) 3) Pick 2 points and create rectangle Left or Right of the p1,p2 line The problem is option 1 and 2 because we have p1,p2,p3 , and p1p2 line is not vertical with p2p3 line. Can anyone help me to adjust given p3 (as depth of the rectangle) and create a p4 incase p2p4 line be vertical to p1p2 line? (defun c:test (/ foo _dist p1 p2 p3 ang) (defun foo (l) (entmake (append '((0 . "LWPOLYLINE") (100 . "AcDbEntity") (100 . "AcDbPolyline") (90 . 4) (70 . 129)) (mapcar (function (lambda (p) (cons 10 (reverse (cdr (reverse (trans p 1 0))))))) l) ) ) ) (defun _dist (a b) (distance (list (car a) (cadr a)) (list (car b) (cadr b)))) (if (and (setq p1 (getpoint "\nGive point1: ")) (setq p2 (getpoint p1 "\nGive point2: ")) (not (grdraw p1 p2 3 1)) ) (if (setq p3 (initget 0 "Left Right") p3 (getpoint p2 "\nGive point3 or length of the side or square [Left (L)/ Right (R)]: ") ) (cond ((vl-consp p3) (foo (list p1 p2 p3 (polar p3 (angle p2 p1) (_dist p1 p2))))) ((eq (type p3) 'STR) (cond ((eq p3 "Left") (setq ang (+ (/ pi 2.) (angle p1 p2)))) ((eq p3 "Right") (setq ang (+ (* pi 1.5) (angle p1 p2)))) ) (foo (list p1 p2 (polar p2 ang (_dist p1 p2)) (polar p1 ang (_dist p1 p2)))) ) ) ) ) (redraw) (princ) ) Thanks Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted March 7, 2023 Share Posted March 7, 2023 Wait, what result do you want? - Typing L or R makes a square. You're happy with that one, right? - giving a third point, or giving a length gives a trapezium. You want a rectangle instead, right? Quote Link to comment Share on other sites More sharing options...
mhy3sx Posted March 7, 2023 Author Share Posted March 7, 2023 Hi Emmanuel Delay. Yes I want rectangle Quote Link to comment Share on other sites More sharing options...
Steven P Posted March 7, 2023 Share Posted March 7, 2023 (edited) Using the rectang command instead of making polylines will create a right angled polygone (rectangle or square) Something like this: (defun c:rectest ( / templine ) (defun RtD (r) (* 180.0 (/ r pi))) (setq p1 (getpoint "Select Point 1")) (princ "\nSelect point for angle ") (command "line" p1 pause "") ; gives a visual idea of angle (setq templine (entlast)) (setq p2 (cdr (assoc 11 (entget (entlast))))) (entdel templine) (setq p1-p2-ang (RtD (angle p1 p2))) (command "rectang" p1 "R" p1-p2-ang pause ) ) ; end defun Can use the Rectang options such as Dimensions to specify face lengths, of select corners using a mouse click, entering an absolute point (eg 10,10 ) or a relative point (eg @10,10) Edited March 7, 2023 by Steven P Quote Link to comment Share on other sites More sharing options...
Steven P Posted March 7, 2023 Share Posted March 7, 2023 Only problem with mine above is it sets the Rectangle angle to the new angle, ideally I would like it reset to what it was before... anyone know what the system variable is? Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted March 7, 2023 Share Posted March 7, 2023 Keeping mostly to the original code... Instead of getpoint I use getdist. Then you can give a point or enter a distance. Now, rectangle to the left or to the right... A positive distance will make a rectangle to the right as seen from p1-p2 line. - If you flip p1 and p2 you'll get the rectangle to the other side. - Or you enter a negative distance, this also flips the rectangle (defun c:test (/ foo _dist p1 p2 p3 ang p3_ p4_) ;; #@param l is a list of points. Foo makes any closed polyline. (defun foo (l) (entmake (append '((0 . "LWPOLYLINE") (100 . "AcDbEntity") (100 . "AcDbPolyline") (90 . 4) (70 . 129)) (mapcar (function (lambda (p) (cons 10 (reverse (cdr (reverse (trans p 1 0))))))) l) ) ) ) (defun _dist (a b) (distance (list (car a) (cadr a)) (list (car b) (cadr b)))) (if (and (setq p1 (getpoint "\nGive point1: ")) (setq p2 (getpoint p1 "\nGive point2: ")) (not (grdraw p1 p2 3 1)) ) (if (setq p3 (initget 0 "Left Right") p3 (getdist p2 "\nGive point3 or length of the side or square [Left (L)/ Right (R)]: ") ) (cond ((vl-consp p3) (foo (list p1 p2 p3 (polar p3 (angle p2 p1) (_dist p1 p2))))) ((eq (type p3) 'STR) (cond ((eq p3 "Left") (setq ang (+ (/ pi 2.) (angle p1 p2))) ) ((eq p3 "Right") (setq ang (+ (* pi 1.5) (angle p1 p2))) ) ) (setq p3_ (polar p2 ang (_dist p1 p2))) (setq p4_ (polar p1 ang (_dist p1 p2))) (foo (list p1 p2 p3_ p4_)) ) ;; p3 is now a distance ((eq (type p3) 'REAL) (setq ang (+ (* pi 1.5) (angle p1 p2))) (setq p3_ (polar p2 ang p3)) (setq p4_ (polar p1 ang p3)) (foo (list p1 p2 p3_ p4_)) ) ) ) ) (redraw) (princ) ) 1 Quote Link to comment Share on other sites More sharing options...
mhy3sx Posted March 7, 2023 Author Share Posted March 7, 2023 Thanks, Emmanuel Delay works perfect now 1 Quote Link to comment Share on other sites More sharing options...
tombu Posted March 7, 2023 Share Posted March 7, 2023 Lots of lisp for 3-Point Rectangles out there, Lee Mac's using his GrSnap utility works pretty sweet: http://www.lee-mac.com/3pointrectangle.html 1 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 7, 2023 Share Posted March 7, 2023 My $0.05 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.