- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Group,
When programming cnc lathes I sometimes layout the shape of the cutting insert in my drawing to ensure it will have the appropriate clearances to turn a particular feature. I got tired of drawing the inserts "long hand", so I cobbled together this basic lisp which works for me. The lisp is currently limited to diamond shaped inserts.
I have little experience with lisp programming, and am interested in how the code can be cleaned up a little. Any direction you may provide would be appreciated!
BTW, if you test run the lisp, common inserts that I use typically have:
IC: Ø.375, Ø.500, or Ø.625
Insert angle: 35°, 55°, or 80°
Corner radius: .008", .016", .031", .047", or .062"
Best regards,
Chris
(defun c:nmg ()
(setq InsertIC (getreal "\nEnter IC radius :"))
(setq InsertAng (getreal "\nEnter insert angle :"))
(setq InsertRad (getreal "\nEnter corner radius :"))
(setq StartPt (getpoint "\nStart Point corner of insert: "))
(setvar "ORTHOMODE" 1)
(setq AlignIns (getpoint "\nPick Direction: "))
;divide angle by 2
(setq HalfAng (/ InsertAng 2))
;get radians of angle
(setq HalfAngRdn (dtr HalfAng))
;get tangent of angle
(setq HalfAngTan (tan HalfAngRdn))
;calculate length of side
(setq SideLen (+ (* InsertIC HalfAngTan) (/ InsertIC HalfAngTan)))
;define insert corner points
(setq pt2 (polar StartPt 0 SideLen))
(setq pt3 (polar pt2 (dtr InsertAng) SideLen))
(setq pt4 (polar pt3 (dtr 180) SideLen))
(command "pline" StartPt pt2 pt3 pt4 StartPt "")
(command "._FILLET" "P" "R" InsertRad "L")
(setvar 'OSMODE 4)
(command "ROTATE" "L" "" "APP" StartPt AlignIns "R" "APP" StartPt AlignIns StartPt AlignIns)
(setvar 'OSMODE 39)
)
;; Tangent - Lee Mac
;; Args: x - real
(defun tan (x)
(if (not (equal 0.0 (cos x) 1e-10))
(/ (sin x) (cos x))
)
)
;;
;This function converts Degrees to Radians.
(defun dtr (dr)
;define degrees to radians function
(* pi (/ dr 180.0))
;divide the angle by 180 then
;multiply the result by the constant PI
)
Solved! Go to Solution.