marco0412 Posted November 13, 2018 Posted November 13, 2018 Hey there, I am new with "lisp" so I am having problems to creating a lisp for my final exam at college. I need to create a lisp that starts with a circle, than inscribe a triangle inside the circle and circumscribe a square. thank you Quote
Grrr Posted November 13, 2018 Posted November 13, 2018 (edited) Heres a low-level solution (with command-calls) so your professor would believe you: (defun C:test ( / e enx c p r ) (if (and (progn (setq e (entlast)) (command "_.CIRCLE" "\\" "\\") (/= e (entlast)) ); progn (member '(0 . "CIRCLE") (setq enx (entget (entlast)))) (setq c (getvar 'cmdecho)) (setvar 'cmdecho 0) ); and (command "_.POLYGON" "3" "_non" (setq p (cdr (assoc 10 enx))) "I" "_non" (polar p (* 0.5 PI) (setq r (cdr (assoc 40 enx)))) "_.RECTANGLE" "_non" (mapcar '- p (list r r)) "_non" (mapcar '+ p (list r r)) ); command ); if (and c (setvar 'cmdecho c)) (princ) ); defun Hope he doesn't browse lisp forums much (or goes under the nickname of "Lee Mac") EDIT: ActiveX solution (dunno if I matched the required result, and if this is the desired behavior) : (defun C:test ( / p1 p2 AddClosedLwPoly spc cir prm prmf ll ur lw ) (cond ( (not vlax-get-acad-object) (alert (vl-list->string '(83 111 114 114 121 32 112 114 111 102 101 115 115 111 114 44 32 65 99 116 105 118 101 88 32 105 115 32 114 101 113 117 105 114 101 100 33) ) ) ) ( (and (setq p1 (getpoint "\nSpecify center: ")) (setq p2 (getpoint p1 "\nSpecify radius: "))) (setq AddClosedLwPoly '((spc vL / r ) (vlax-put (setq r (vlax-invoke spc 'AddLightWeightPolyline vL)) 'Closed :vlax-true) r)) (setq spc (vla-get-Block (vla-get-ActiveLayout (vla-get-ActiveDocument (vlax-get-acad-object))))) (setq cir (vlax-invoke spc 'AddCircle p1 (distance p1 p2))) (setq prm (vlax-curve-getParamAtPoint cir p2)) (setq prmf (/ (vlax-curve-getEndParam cir) 3.)) (AddClosedLwPoly spc (apply 'append (mapcar '(lambda (x) (reverse (cdr (reverse (vlax-curve-getPointAtParam cir (+ prm x)))))) (list 0 prmf (* prmf 2))))) (vla-GetBoundingBox cir 'll 'ur) (mapcar 'set '(ll ur) (mapcar 'vlax-safearray->list (list ll ur))) (vlax-invoke (AddClosedLwPoly spc (append ('((x) (list (car x) (cadr x))) ll) ('((x1 x2) (list (car x1) (cadr x2))) ll ur) ; ul ('((x) (list (car x) (cadr x))) ur) ('((x1 x2) (list (car x2) (cadr x1))) ll ur) ; lr ); append ) 'Rotate (mapcar '(lambda (a b) (* 0.5 (+ a b))) ll ur) (angle p1 p2) ; required rotation on the square, aligned to the picked points? ); vlax-invoke ); (and ...) ); cond ); defun C:test (vl-load-com) (princ) Edited November 13, 2018 by Grrr Quote
ronjonp Posted November 13, 2018 Posted November 13, 2018 1 hour ago, Grrr said: Heres a low-level solution (with command-calls) so your professor would believe you: Haha .. I wouldn't believe your "low level" solution came from a novice. Quote
Grrr Posted November 13, 2018 Posted November 13, 2018 3 minutes ago, ronjonp said: Haha .. I wouldn't believe your "low level" solution came from a novice. Oh.. well I started with the three command-calls, and then the self-criticism kicked in 1 Quote
ronjonp Posted November 13, 2018 Posted November 13, 2018 (edited) Hahaha .. this would be my believable version (command "circle" "0,0,0" "1") (command "polygon" "3" "0,0,0" "I" "1") (command "polygon" "4" "0,0,0" "c" "1") Edited November 13, 2018 by ronjonp 1 Quote
ronjonp Posted November 15, 2018 Posted November 15, 2018 Another for extra credit (defun c:foo (/ p d) (cond ((null (tblobjname "block" "Cheater")) (entmake '((0 . "BLOCK") (100 . "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbBlockReference") (2 . "Cheater") (10 0. 0. 0.) (70 . 0) ) ) (entmake '((0 . "LWPOLYLINE") (100 . "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbPolyline") (90 . 4) (70 . 129) (10 -1. 1.) (10 -1. -1.) (10 1. -1.) (10 1. 1.) ) ) (entmake '((0 . "LWPOLYLINE") (100 . "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbPolyline") (90 . 3) (70 . 129) (43 . 0.) (38 . 0.) (39 . 0.) (10 0. 1.) (10 -0.866025403784439 -0.5) (10 0.866025403784439 -0.5) ) ) (entmake '((0 . "CIRCLE") (100 . "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbCircle") (10 0. 0. 0.) (40 . 1.) ) ) (entmake '((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0"))) ) ) (and (setq p (getpoint "\nSpecify center point for circle: ")) (setq d (getdist p "\nSpecify radius of circle ")) (entmakex (list '(0 . "insert") '(2 . "Cheater") (cons 10 p) (cons 41 d) (cons 42 d) (cons 43 d)) ) ) (princ) ) Quote
Grrr Posted November 15, 2018 Posted November 15, 2018 1 hour ago, ronjonp said: Another for extra credit Looks like thats the best solution for creating a predefined geometry - with a hardcoded dxf lists. A bit easier structure for me would be to mapcar the entmake - (mapcar 'entmake (append '(((0 . "BLOCK") (100 . "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbBlockReference") (2 . "Cheater") (10 0. 0. 0.) (70 . 0) )) '( ; My geometry here... ((0 . "LWPOLYLINE") (100 . "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbPolyline") (90 . 4) (70 . 129) (10 -1. 1.) (10 -1. -1.) (10 1. -1.) (10 1. 1.) ) ((0 . "LWPOLYLINE") (100 . "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbPolyline") (90 . 3) (70 . 129) (43 . 0.) (38 . 0.) (39 . 0.) (10 0. 1.) (10 -0.866025403784439 -0.5) (10 0.866025403784439 -0.5) ) ((0 . "CIRCLE") (100 . "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbCircle") (10 0. 0. 0.) (40 . 1.) ) ) '(((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0"))) ) ) Theres also a 3rd way to get the triangle, with polar, angle and vla-IntersectWith 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.