(defun c:gear(/)
(
setq
p0 (getpoint"輸入齒輪中心p0: ")
m (getreal"輸入齒輪模數M: ")
z (getint"輸入齒輪齒數Z: ")
ha 1
c 0.25
a (/ pi 9)
ra(/ (* (+ z (+ ha ha)) m) 2)
rf(/ (* (- z (+ (+ ha ha) c)) m) 2)
r(/ ( * m z) 2)
rb ( * r (cos a))
ri rb
ang 0
g (polar p0 ang rb)
)
(command "circle" p0 ra)
(command "circle" p0 rf)
(command "circle" p0 r)
(command "line" g)
(while (< ri ra)
(setq
ang ( + ang(/ pi 360))
ri ( / rb (cos ang))
cta ( - (/ (sin ang) (cos ang)) ang)
g(polar p0 cta ri)
)
(command g)
)
(command )
)
二、螺旋源程序
(defun errMsg (s)
(if (/= s "function cancelled") (princ (strcat "\nError: " s)))
; 當命令執行時出現錯誤
(setvar "cmdecho" ocmdold) ; 例如用戶按下了CTRL + C
(setvar "osmode" osmold)
(setq *error* olderr) ; 恢復舊的錯誤處理
(princ)
)
(defun c:3Dthread (/ radouter threadpitch threadlength threadangle
ptStart innerdiafactor radmid radinner ocmdold osmold 4H 5H 6H h6 g6)
;-------------------------------------------------------------------
; 獲取公制外徑大小、螺距總長
; 然后計算一系列幾何點
; 并且關閉對象捕捉、命令回顯
;-------------------------------------------------------------------
(setq 4H (list 0.0015 0.002 0.002 0.0025 0.003 0.0035 0.004 0.005 0.006 0.007
0.008 0.009 0.010))
(setq 5H (list 0.002 0.0025 0.003 0.004 0.0045 0.0055 0.0065 0.0075 0.009 0.010
0.0115 0.0125 0.0135))
(setq 6H (list 0.003 0.004 0.0045 0.0055 0.0065 0.008 0.0095 0.011 0.0125 0.0145
0.016 0.018 0.020))
(setq h6 (list -0.003 -0.004 -0.0045 -0.0055 -0.0065 -0.008
-0.0095 -0.011 -0.0125 -0.0145 -0.016 -0.018 -0.020))
(setq g6 (list -0.005 -0.008 -0.0095 -0.0115 -0.0135 -0.017
-0.0195 -0.023 -0.0265 -0.0295 -0.033 -0.036 -0.0515))
(setq osmold (getvar "osmode")) &nbs