marineman Posted September 7, 2018 Posted September 7, 2018 Hello, I’ve just started to learn AutoLisp and made my first code to draw this figure. The Inputs are A, B and C , but instead of straight line, I’d like this to be an arc with radius (A+B)/2+50. I can't understand how to use Autocad commands into my AutoLisp code ( for example Autocad command ARC with start end and radius). Is that too difficult to be done? Could you recommend me any useful books I can start proper learning. The information which I’ve used so far is miscellaneous from different websites and I think I am getting lost… Thank you for your cooperation! Quote
Grrr Posted September 8, 2018 Posted September 8, 2018 The first shape is not that hard to create, but I'm not sure about the one with the arc, is it possible for it to have that radius and be coincident to the ends of the 'C' lines? (defun C:test ( / a b c p ) (and (progn (initget 6) (setq a (getreal "\nA: "))) (progn (initget 6) (setq b (getreal "\nB: "))) (progn (initget 6) (setq c (getreal "\nC: "))) (setq p (getpoint "\nSpecify insertion point: ")) (entmakex (append '( (0 . "LWPOLYLINE") (100 . "AcDbEntity") (100 . "AcDbPolyline") (90 . 5) (70 . 1) (43 . 0.0) (38 . 0.0) (39 . 0.0) ) (list (cons 10 (mapcar '+ p (list b 0)))) '( (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) ) (list (cons 10 (mapcar '+ p (list b c)))) '( (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) ) (list (cons 10 (mapcar '+ p (list c a)))) '( (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) ) (list (cons 10 (mapcar '+ p (list 0 a)))) '( (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) ) (list (cons 10 (mapcar '+ p '(0.0 0.0)))) '( (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (210 0.0 0.0 1.0) ) ); list ); entmakex ); and (princ) ); defun As for the learning, I would start with very simple attempts (that might not be quite connected to my goal) and be consistent on the lisp forums (checking out/analysing the simpliest codes). Quote
David Bethel Posted September 8, 2018 Posted September 8, 2018 (edited) You probably could have used some a bit easier for starter <g> I tried to have this use very simple autolisp calls Find the chord distance, angle and mid point With known radius and half chord length, find the distance from chord mid point to center Calculate the center point. (defun c:foo (/ ac ab cd ch ca cm ra) (initget 7) (setq a (getdist "\nA: ")) (initget 7) (setq b (getdist "\nB: ")) (initget 7) (setq c (getdist "\nC: ")) (redraw) (command "_.ZOOM" "_W" (list -2 -2) (list (+ a 2) (+ b 2))) (setq ac (list a c) bc (list c b) cd (distance ac bc) ch (* cd 0.5) ca (angle ac bc) cm (mapcar '(lambda (a b) (* (+ a b) 0.5)) ac bc) ra (+ (/ (+ a b) 2.0) 50)) (grdraw '(0 0) (list a 0) 1) (grdraw '(0 0) (list 0 b) 2) (grdraw (list a 0) ac 3) (grdraw (list 0 b) bc 3) (grdraw ac bc 4) (grdraw cm (polar cm (- ca (* pi 0.5)) cd) 5) (setq cl (sqrt (- (* ra ra) (* ch ch)))) (setq ce (polar cm (- ca (* pi 0.5)) cl)) (command "_.ARC" "_c" ce bc ac) (prin1 (entget (entlast))) (prin1)) -David Edited September 8, 2018 by David Bethel formatting, 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.