DuanJinHui Posted August 30, 2014 Posted August 30, 2014 Hello. Cadtutor's friends I have an idea, want to use lisp to do these things. Someone can help me ? 1.Enter the length of "L" , Then Pick up two perpendicular lines ,maybe is Plines. Draw a isosceles triangle, and hatch. eg. 2. Enter the length of "L" , Then Pick up two perpendicular lines ,maybe is Plines. Draw a right triangle, and hatch. eg. Maybe need to choose which side . Quote
Tharwat Posted August 30, 2014 Posted August 30, 2014 Welcome to CADTutor Try this routine , and press TAB button to step through triangle shapes . (defun c:Test (/ *error* i a b c hp gr e p) ;; Tharwat Al Shoufi ;; ;; Date: 31.08.2014 ;; ;; Dynamic Triangle ;; (defun *error* (msg) (redraw) (if hp (setvar 'HPNAME hp) ) (if (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")) ) ) (if (and (setq *length* (cond ((getdist (strcat "\n Specify Length of triangle <" (rtos (cond (*length*) ((setq *length* 1.0)) ) 2 2 ) ">: " ) ) ) (*length*) ) ) (setq p (getpoint "\n Specify base point :")) ) (progn (setq hp (getvar 'HPNAME) i 1 a (polar p 0. (/ *length* 2.)) b (polar a pi *length*) c (polar p (* pi 0.5) *length*) ) (grvecs (list -3 a b b c c a)) (princ "\n Press TAB to step into shapes :") (while (eq (cadr (setq gr (grread nil 14 0))) 9) (redraw) (if (eq (cadr gr) 9) (cond ((eq i 0) (setq a (polar p 0. (/ *length* 2.)) b (polar a pi *length*) c (polar p (* pi 0.5) *length*) ) (grvecs (list -3 a b b c c a)) ) ((eq i 1) (setq a (polar p 0. *length*) b (polar p (* pi 0.5) *length*) c p ) (grvecs (list -3 a b b c c a)) ) ((eq i 2) (setq a (polar p 0. *length*) b (polar p (* pi 1.5) *length*) c p ) (grvecs (list -3 a b b c c a)) ) ((eq i 3) (setq a (polar p pi (/ *length* 2.)) b (polar a 0. *length*) c (polar p (* pi 1.5) *length*) ) (grvecs (list -3 a b b c c a)) ) ((eq i 4) (setq a (polar p pi *length*) b (polar p (* pi 1.5) *length*) c p ) (grvecs (list -3 a b b c c a)) ) ((eq i 5) (setq a (polar p pi *length*) b (polar p (* pi 0.5) *length*) c p ) (grvecs (list -3 a b b c c a)) ) ) ) (if (eq i 5) (setq i 0) (setq i (1+ i)) ) ) (if (or (member (car gr) '(3 25)) (member (cadr gr) '(32 13))) (if (setq e (entmakex (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(90 . 3) '(70 . 1) (cons 10 a) (cons 10 b) (cons 10 c) ) ) ) (progn (setvar 'HPNAME "SOLID") (command "_.-hatch" "S" e "" "") ) ) ) ) ) (*error* nil) (princ) ) Quote
DuanJinHui Posted August 31, 2014 Author Posted August 31, 2014 Welcome to CADTutor Try this routine , and press TAB button to step through triangle shapes . (defun c:Test (/ *error* i a b c hp gr e p) ;; Tharwat Al Shoufi ;; ;; Date: 31.08.2014 ;; ;; Dynamic Triangle ;; (defun *error* (msg) (redraw) (if hp (setvar 'HPNAME hp) ) (if (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")) ) ) (if (and (setq *length* (cond ((getdist (strcat "\n Specify Length of triangle <" (rtos (cond (*length*) ((setq *length* 1.0)) ) 2 2 ) ">: " ) ) ) (*length*) ) ) (setq p (getpoint "\n Specify base point :")) ) (progn (setq hp (getvar 'HPNAME) i 1 a (polar p 0. (/ *length* 2.)) b (polar a pi *length*) c (polar p (* pi 0.5) *length*) ) (grvecs (list -3 a b b c c a)) (princ "\n Press TAB to step into shapes :") (while (eq (cadr (setq gr (grread nil 14 0))) 9) (redraw) (if (eq (cadr gr) 9) (cond ((eq i 0) (setq a (polar p 0. (/ *length* 2.)) b (polar a pi *length*) c (polar p (* pi 0.5) *length*) ) (grvecs (list -3 a b b c c a)) ) ((eq i 1) (setq a (polar p 0. *length*) b (polar p (* pi 0.5) *length*) c p ) (grvecs (list -3 a b b c c a)) ) ((eq i 2) (setq a (polar p 0. *length*) b (polar p (* pi 1.5) *length*) c p ) (grvecs (list -3 a b b c c a)) ) ((eq i 3) (setq a (polar p pi (/ *length* 2.)) b (polar a 0. *length*) c (polar p (* pi 1.5) *length*) ) (grvecs (list -3 a b b c c a)) ) ((eq i 4) (setq a (polar p pi *length*) b (polar p (* pi 1.5) *length*) c p ) (grvecs (list -3 a b b c c a)) ) ((eq i 5) (setq a (polar p pi *length*) b (polar p (* pi 0.5) *length*) c p ) (grvecs (list -3 a b b c c a)) ) ) ) (if (eq i 5) (setq i 0) (setq i (1+ i)) ) ) (if (or (member (car gr) '(3 25)) (member (cadr gr) '(32 13))) (if (setq e (entmakex (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(90 . 3) '(70 . 1) (cons 10 a) (cons 10 b) (cons 10 c) ) ) ) (progn (setvar 'HPNAME "SOLID") (command "_.-hatch" "S" e "" "") ) ) ) ) ) (*error* nil) (princ) ) Mr.Tharwat. Thanks for your help. But, maybe like this, how to handle ? Quote
Tharwat Posted August 31, 2014 Posted August 31, 2014 Mr.Tharwat. Thanks for your help. But, maybe like this, how to handle ? Not a problem at all , try the modification and let me know (defun c:Test (/ *error* i a b c hp gr e p p1 ang) ;; Tharwat Al Shoufi ;; ;; Date: 31.08.2014 ;; ;; Dynamic Triangle ;; ;; Resision - 01 Direction ;; ;; of triangle added ;; (defun *error* (msg) (redraw) (if hp (setvar 'HPNAME hp) ) (if (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")) ) ) (if (and (setq *length* (cond ((getdist (strcat "\n Specify Length of triangle <" (rtos (cond (*length*) ((setq *length* 1.0)) ) 2 2 ) ">: " ) ) ) (*length*) ) ) (setq p (getpoint "\n Specify base point :")) (setq p1 (getpoint "\n Specify Direction :" p)) ) (progn (setq hp (getvar 'HPNAME) i 1 ang (angle p p1) a (polar p (+ ang (* pi 1.5)) (/ *length* 2.)) b (polar p (+ ang (* pi 0.5)) (/ *length* 2.)) c (polar p ang *length*) ) (grvecs (list -3 a b b c c a)) (princ "\n Press TAB to step into shapes :") (while (eq (cadr (setq gr (grread nil 14 0))) 9) (redraw) (if (eq (cadr gr) 9) (cond ((eq i 0) (setq a (polar p (+ ang (* pi 1.5)) (/ *length* 2.)) b (polar p (+ ang (* pi 0.5)) (/ *length* 2.)) c (polar p ang *length*) ) (grvecs (list -3 a b b c c a)) ) ((eq i 1) (setq a (polar p (+ ang (* pi 1.5)) *length*) b (polar p ang *length*) c p ) (grvecs (list -3 a b b c c a)) ) ((eq i 2) ;; ;; (setq a (polar p (+ ang (* pi 1.5)) *length*) b (polar p (+ ang pi) *length*) c p ) (grvecs (list -3 a b b c c a)) ) ((eq i 3) ;; ;; (setq a (polar p (+ ang (* pi 1.5)) (/ *length* 2.)) b (polar a (+ ang (* pi 0.5)) *length*) c (polar p (+ ang pi) *length*) ) (grvecs (list -3 a b b c c a)) ) ((eq i 4) ;; ;; (setq a (polar p (+ ang (* pi 0.5)) *length*) b (polar p (+ ang pi) *length*) c p ) (grvecs (list -3 a b b c c a)) ) ((eq i 5) ;; ;; (setq a (polar p ang *length*) b (polar p (+ ang (* pi 0.5)) *length*) c p ) (grvecs (list -3 a b b c c a)) ) ) ) (if (eq i 5) (setq i 0) (setq i (1+ i)) ) ) (if (and (or (member (car gr) '(3 25)) (member (cadr gr) '(32 13))) (setq e (entmakex (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(90 . 3) '(70 . 1) (cons 10 a) (cons 10 b) (cons 10 c) ) ) ) ) (progn (setvar 'HPNAME "SOLID") (command "_.-hatch" "S" e "" "")) ) ) ) (*error* nil) (princ) ) Quote
DuanJinHui Posted August 31, 2014 Author Posted August 31, 2014 Not a problem at all , try the modification and let me know (defun c:Test (/ *error* i a b c hp gr e p p1 ang) ;; Tharwat Al Shoufi ;; ;; Date: 31.08.2014 ;; ;; Dynamic Triangle ;; ;; Resision - 01 Direction ;; ;; of triangle added ;; (defun *error* (msg) (redraw) (if hp (setvar 'HPNAME hp) ) (if (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")) ) ) (if (and (setq *length* (cond ((getdist (strcat "\n Specify Length of triangle <" (rtos (cond (*length*) ((setq *length* 1.0)) ) 2 2 ) ">: " ) ) ) (*length*) ) ) (setq p (getpoint "\n Specify base point :")) (setq p1 (getpoint "\n Specify Direction :" p)) ) (progn (setq hp (getvar 'HPNAME) i 1 ang (angle p p1) a (polar p (+ ang (* pi 1.5)) (/ *length* 2.)) b (polar p (+ ang (* pi 0.5)) (/ *length* 2.)) c (polar p ang *length*) ) (grvecs (list -3 a b b c c a)) (princ "\n Press TAB to step into shapes :") (while (eq (cadr (setq gr (grread nil 14 0))) 9) (redraw) (if (eq (cadr gr) 9) (cond ((eq i 0) (setq a (polar p (+ ang (* pi 1.5)) (/ *length* 2.)) b (polar p (+ ang (* pi 0.5)) (/ *length* 2.)) c (polar p ang *length*) ) (grvecs (list -3 a b b c c a)) ) ((eq i 1) (setq a (polar p (+ ang (* pi 1.5)) *length*) b (polar p ang *length*) c p ) (grvecs (list -3 a b b c c a)) ) ((eq i 2) ;; ;; (setq a (polar p (+ ang (* pi 1.5)) *length*) b (polar p (+ ang pi) *length*) c p ) (grvecs (list -3 a b b c c a)) ) ((eq i 3) ;; ;; (setq a (polar p (+ ang (* pi 1.5)) (/ *length* 2.)) b (polar a (+ ang (* pi 0.5)) *length*) c (polar p (+ ang pi) *length*) ) (grvecs (list -3 a b b c c a)) ) ((eq i 4) ;; ;; (setq a (polar p (+ ang (* pi 0.5)) *length*) b (polar p (+ ang pi) *length*) c p ) (grvecs (list -3 a b b c c a)) ) ((eq i 5) ;; ;; (setq a (polar p ang *length*) b (polar p (+ ang (* pi 0.5)) *length*) c p ) (grvecs (list -3 a b b c c a)) ) ) ) (if (eq i 5) (setq i 0) (setq i (1+ i)) ) ) (if (and (or (member (car gr) '(3 25)) (member (cadr gr) '(32 13))) (setq e (entmakex (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(90 . 3) '(70 . 1) (cons 10 a) (cons 10 b) (cons 10 c) ) ) ) ) (progn (setvar 'HPNAME "SOLID") (command "_.-hatch" "S" e "" "")) ) ) ) (*error* nil) (princ) ) dear sir, nice program. perfect. Thank you so much! Quote
Tharwat Posted August 31, 2014 Posted August 31, 2014 dear sir, nice program. perfect. Thank you so much! You are welcome . It was really fun to write that code . 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.