cyberactive Posted February 1 Posted February 1 Hello, I have a routine but it fails when entering the last measurement, what it does is create a closed polygon by clicking on a base point, then it asks me to enter the front side and then returns to the base point to enter the side, but when drawing i (defun c:acin (/ 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 (setq p1 (getpoint "\nPica un punto base: ")) (progn (setq p2 (getpoint p1 "\nIngresa la medida del frente: ")) (not (grdraw p1 p2 3 1)) (setq p3 (getpoint p1 "\nIngresa la medida del lado desde el punto base: ")) (if (vl-consp p3) (foo (list p1 p2 p3 (polar p3 (angle p2 p1) (_dist p1 p2)))) (if (eq (type p3) 'STR) (progn (setq ang (cond ((eq p3 "I") (+ (/ pi 2.) (angle p2 p1))) ((eq p3 "D") (+ (* pi 1.5) (angle p2 p1))) )) (setq p3 (polar p1 ang (getreal "\nIngresa la medida del lado desde el punto base: "))) (foo (list p1 p2 p3 (polar p3 (angle p2 p1) (_dist p1 p2)))) ) ) ) ) ) (redraw) (princ) ) Quote
mhupp Posted February 1 Posted February 1 Its seems to be working for me but the rectangle is a little lopsided. (getpoint will only return a list so this if statement is only going to run foo. (defun c:acin (/ 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)))) (setq p1 (getpoint "\nPica un punto base: ")) (setq p2 (getpoint p1 "\nIngresa la medida del frente: ")) (not (grdraw p1 p2 3 1)) (setq p3 (getpoint p1 "\nIngresa la medida del lado desde el punto base: ")) (if (vl-consp p3) (foo (list p1 p2 p3 (polar p3 (angle p2 p1) (_dist p1 p2)))) ;si p3 es una lista (if (eq (type p3) 'STR) ;si p3 no es una lista, ejecute esto (progn (setq ang (cond ((eq p3 "I") (+ (/ pi 2.) (angle p2 p1))) ((eq p3 "D") (+ (* pi 1.5) (angle p2 p1))) ) ) (setq p3 (polar p1 ang (getreal "\nIngresa la medida del lado desde el punto base: "))) (foo (list p1 p2 p3 (polar p3 (angle p2 p1) (_dist p1 p2)))) ) ) ) (redraw) (princ) ) Quote
cyberactive Posted February 1 Author Posted February 1 The problem is when I enter the second data it takes the final vertex and is very inclined Quote
cyberactive Posted February 1 Author Posted February 1 https://ibb.co/xgdk0vs https://ibb.co/wM8Vc93 Quote
cyberactive Posted February 1 Author Posted February 1 This is how it should look https://ibb.co/Svkv7ps Quote
mhupp Posted February 1 Posted February 1 (edited) calculating the midpoint of p2 and p3 add this after P3 (setq mpt (mapcar '/ (mapcar '+ P2 P3) '(2 2 2))) change foo (foo (list p1 p2 (polar p1 (angle p1 mpt) (* (_dist p1 mpt) 2)) p3)) Edited February 1 by mhupp 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.