Skip to content

Instantly share code, notes, and snippets.

@autokludge
Last active November 11, 2022 04:35
Show Gist options
  • Save autokludge/4c3e3cb0567908daa15783fc22f13e61 to your computer and use it in GitHub Desktop.
Save autokludge/4c3e3cb0567908daa15783fc22f13e61 to your computer and use it in GitHub Desktop.
Acute-Chamfer
; draws chamfer of given length between two edges
; adapted from Lee_Mac post at
;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-available-for-angle-between-two-lines/m-p/3241256/highlight/true#M300565
(defun c:oddcham ( / _SelectIf e1 e2 f in l1 l2 s1 s2 )
(defun _SelectIf ( msg pred )
(
(lambda ( f / e )
(while
(progn (setvar 'ERRNO 0) (setq e (car (entsel msg)))
(cond
( (= 7 (getvar 'ERRNO))
(princ "\nMissed, try again.")
)
( (eq 'ENAME (type e))
(if (and f (null (f e)))
(princ "\nInvalid Object.")
)
)
)
)
)
e
)
(eval pred)
)
)
(setq f (lambda ( x ) (eq "LINE" (cdr (assoc 0 (entget x))))))
;(setq f (lambda ( x ) (eq "LWPOLYLINE" (cdr (assoc 0 (entget x)))))) maybe this for Polyline;
(if
(and
(setq l1 (_SelectIf "\nSelect 1st Line: " 'f))
(setq l2 (_SelectIf "\nSelect 2st Line: " 'f))
)
(progn
(setq l1 (entget l1)
l2 (entget l2)
s1 (cdr (assoc 10 l1))
s2 (cdr (assoc 10 l2))
e1 (cdr (assoc 11 l1))
e2 (cdr (assoc 11 l2))
in (inters s1 e1 s2 e2 nil)
close1 s1
close2 s2
)
(if (null in)
(princ "\nLines are Parallel.")
(progn
(if (< (distance in e1) (distance in s1))
(setq close1 e1)
(setq e1 s1)
)
(if (< (distance in e2) (distance in s2))
(setq close2 e2)
(setq e2 s2)
)
(setq angbetween (LM:GetInsideAngle e1 in e2))
(setq halfangbetween (/ angbetween 2))
(setq chamferlength (getreal "Chamfer Length? "))
(setq halfchamferlength (/ chamferlength 2))
(setq circrad (/ halfchamferlength (sin halfangbetween)))
(setq l1ang (angle in e1))
(setq l2ang (angle in e2))
(setq champ1 (list
(+ (car in) (* circrad (cos l1ang)))
(+ (cadr in) (* circrad (sin l1ang)))))
(setq champ2 (list
(+ (car in) (* circrad (cos l2ang)))
(+ (cadr in) (* circrad (sin l2ang)))))
(SETQ OSMODE (GETVAR 'OSMODE))
(SETVAR 'OSMODE 0)
(command "line" champ1 champ2 "")
(setq newline (entlast))
(command "_trim" newline "" (osnap close1 "_nea") "")
(command "_trim" newline "" (osnap close2 "_nea") "")
(SETVAR 'OSMODE OSMODE)
(princ (strcat "\nAngle: " (angtos angbetween)))
)
)
)
)
(princ)
)
;; Get Inside Angle - Lee Mac
;; Returns the smaller angle subtended by three points with vertex at p2
(defun LM:GetInsideAngle ( p1 p2 p3 )
( (lambda ( a ) (min a (- (+ pi pi) a)))
(rem (+ pi pi (- (angle p2 p1) (angle p2 p3))) (+ pi pi))
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment