therock005 Posted April 26, 2010 Posted April 26, 2010 I'm looking for a simple routine that completes a square given 3 points. The only condition is of course that the opposite sides are equal in length and parallel. Quote
lpseifert Posted April 26, 2010 Posted April 26, 2010 Just how do the 3 points relate to the square? Corners? A square by definition has 4 sides of equal length with 4 interior angles of 90 degrees. this may not be possible given 3 points. It might be clearer if you were to post an example. Quote
therock005 Posted April 26, 2010 Author Posted April 26, 2010 Sorry i didint mean a perfect sqaure with equal all 4 sides and right angles. I meant a 4 sided polygon, with opposite sides equal and parallel (no matter what the angles may be). EDIT: Ok and just so there's no confusion here's what i mean. Here are 3 points and here's the part you supposedly create by joing them. The line in red is the missing part that should be filled. So this routine should create this 4 sided polygon given you supply the 3 points in the correct order. Quote
lpseifert Posted April 26, 2010 Posted April 26, 2010 here's a quickey... I hope you study and try to learn from it. (defun c:test (/ oldsnap pt1 pt2 pt3) (setq oldsnap (getvar "osmode")) (setvar "osmode" 0) (setq pt1 (getpoint "\nPick 1st point: ") pt2 (getpoint pt1 "\nPick 2nd point: ") pt3 (getpoint pt2 "\nPick 3rd point: ")) (entmake (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 4) (cons 70 1) (cons 10 pt1) (cons 10 pt2) (cons 10 pt3) (cons 10 (polar pt3 (angle pt2 pt1)(distance pt2 pt1))) ) ) (setvar "osmode" oldsnap) (princ) ) Quote
alanjt Posted April 26, 2010 Posted April 26, 2010 Good stuff Larry, but why'd you turn the OSnaps off? They don't have an affect entmake. Quote
lpseifert Posted April 26, 2010 Posted April 26, 2010 Force of habit I guess... I figured that osnap might affect the getpoint Quote
alanjt Posted April 26, 2010 Posted April 26, 2010 Force of habit I guess...I figured that osnap might affect the getpoint OSnaps on for getpoint are fine. If not, you wouldn't be able to snap to anything. Quote
lpseifert Posted April 26, 2010 Posted April 26, 2010 Let me re-phrase... I figured that using a running osnap might return an unintentional point (99% of the time I leave osnaps off, and use the keyboard/toolbar as needed) Quote
alanjt Posted April 26, 2010 Posted April 26, 2010 Let me re-phrase...I figured that using a running osnap might return an unintentional point It wouldn't hurt what you posted. Actually, as long as you placed "_non" before each point, you could have used command (not that I'm suggesting that) and it wouldn't have hurt anything. (99% of the time I leave osnaps off, and use the keyboard/toolbar as needed) Same here. Quote
lpseifert Posted April 26, 2010 Posted April 26, 2010 you could have used command No no... I'm afraid Lee Mac would whack me across the knuckles if I tried that. (just joking) Quote
therock005 Posted April 26, 2010 Author Posted April 26, 2010 Works great but as the others noted it disables my osnaps. Is it possible to temporarily enable the node osnap just for this action and when the command finishes to rest to the previous state of osnaps? Quote
therock005 Posted April 26, 2010 Author Posted April 26, 2010 done, i found the node code was 8 from another topic so instead o zero i made it 8 and it now works as i wanted. Thank You man, i appreciate it. EDIT: It seems that you edited your message and pointed it out, but it's ok i did a little searching as well and came up with the answer. Quote
alanjt Posted April 26, 2010 Posted April 26, 2010 I'd just take out all the OSMode toggling code out. Quote
alanjt Posted April 26, 2010 Posted April 26, 2010 Artistic license LoL Works for me. [undocumented feature] Quote
Lee Mac Posted April 26, 2010 Posted April 26, 2010 No no... I'm afraid Lee Mac would whack me across the knuckles if I tried that. And so you should be ... Quote
Lee Mac Posted April 26, 2010 Posted April 26, 2010 No OSnap on last pick, but just for the fun of it: (defun c:sq ( / LWPoly RemoveIfOdd GR I LST P P1 P2 P3 P4 ) (vl-load-com) ;; Lee Mac ~ 26.04.10 (defun LWPoly ( lst cls ) (entmakex (append (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 (length lst)) (cons 70 cls)) (mapcar (function (lambda (p) (cons 10 p))) lst)))) (defun RemoveIfOdd ( lst ) ( (lambda ( i ) (vl-remove-if (function (lambda ( x ) (= 1 (boole 1 1 (setq i (1+ i)))))) lst)) -1)) (if (and (setq p1 (getpoint "\nPick First Point: ")) (setq p2 (getpoint "\nPick Second Point: " p1))) (progn (while (and (= 5 (car (setq gr (grread t 13 0)))) (listp (setq p3 (cadr gr)))) (redraw) (setq p4 (polar p3 (angle p2 p1) (distance p1 p2))) (grvecs (cons -3 (setq p (list p1 p2 p2 p3 p3 p4 p4 p1))))) (LWPoly (RemoveIfOdd (cdr p)) 1) (redraw))) (princ)) Quote
alanjt Posted April 26, 2010 Posted April 26, 2010 And so you should be ... . ...................... Quote
alanjt Posted April 27, 2010 Posted April 27, 2010 No OSnap on last pick, but just for the fun of it: Nice coding. Such a shame the third pick doesn't have OSnap capabilities. GrRead's lack of OSnap functionality makes it almost useless. 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.