(defun C:gear ()/ a( L) h; K X& E" Y& Z
(setq numt nil' \4 z% P; t5 L' R8 j! ]& H9 d
diap nil
$ j* D: q* o/ B! e prsa nil" }7 |1 I6 f Y& x6 L" l
pnts nil# e' d/ b9 o3 B
test nil
. r1 e( o/ v4 M8 w pwd nil$ m1 u$ }6 f/ Y
)( {: H. ?$ `( K1 z: [# D: n
' N! B7 Q4 E6 L* A8 ? d' C
(setq numt (getint "Number of teeth:<24>"))
# {8 F& t2 g& R) R8 N (if (= numt nil)
/ m9 T* i1 o& v( O T1 ]# c* l (setq numt 24)
& y# H2 u* w* g' R ), l5 v' ]; ]( A1 x
(setq diap (getreal "Modulus of gear:<0.5> "))# N. F/ _' p; W7 B- S
(if (= diap nil)
) x- ~2 N* l( u: c* f (setq diap (/ 1 0.5))( M' n5 M# H5 Y, ]' J) m
(setq diap (/ 1 diap))
: Z. Y5 U$ O k+ Y )- B2 Y- W$ d, E" q! c
(setq prsa (getreal "Pressure angle:<20.0> "))
# Q8 H; a( I# D# [2 h (if (= prsa nil)* @3 ?& {8 i& F9 R% v
(setq prsa 20.0)
$ \) m2 j; A5 k/ j) _0 @/ D; _; p2 z )) ~1 ]& A2 U2 i/ t' S
(setq pnts (getint "number of points on curve:<40> "))
l& J: j- x4 R: p (if (= pnts nil)
3 N8 c( k0 j7 z) G (setq pnts 40)2 L U/ g. K0 J' `! k6 N8 S
)
4 Q! G" j. `9 R5 F1 K( ?; I3 k4 h/ j; H( E8 p
; (setq pwd (getreal "Please input password:"))2 j A( v9 ]8 f" i) D
; (if (/= pwd 8833)
5 d. n. \0 K, X$ o B! G9 ]; (setq numt 0) N8 Z) m3 e" ]+ M$ w) W5 l0 Q
; )
# `* g1 p B6 d; ]; f+ T+ m H; (if (= pwd nil)
# H. n3 @8 E; l- K0 q }, K; (setq numt 0)
2 `% b9 E6 x! S' e+ d; )
, s4 P9 C+ n6 a$ \( R" e& r, F( G;
4 z: @2 H' N P- B" {. S$ Y( U (command "osnap" "non")
V# @/ d4 |; c2 `, u1 G( ]! } (setvar "cmdecho" 0)
4 L) w4 D# T; j5 k: x (setq oldvar (getvar "pickbox"))
1 Y! m7 [4 u! e' {$ R" o" k (setvar "pickbox" 0), `9 t1 q! e8 V9 z, g8 L& H% r
(setvar "aperture" 1)
- |" n7 R3 @, M4 U' s (command "osmode" "0" )- G, D, ]* q2 _
;3 q$ I( l5 [- W
(setq prsa (/ (* prsa pi) 180.0))
# e$ e; ^9 B2 z2 D- ? (setq pitd (/ numt diap))
. E' u# q5 d/ ^% Y8 _ (setq outd (/ (+ numt 2) diap))0 w4 Z- Z3 A8 T* |1 ?* a" R
(setq basr (/ (* pitd (cos prsa)) 2))& r2 {1 O% s. [- p! M: R
(setq orad (/ outd 2.0))
6 F. [' ?: y) g% z! X, v6 K( l (setq z (- (expt orad 2.0) (expt basr 2.0)))4 ]0 f3 X# J" N# K2 \& B
(setq x (sqrt z))0 D' ^' j% U- U3 M# P
(setq paodd (atan (/ x basr)))7 }: `! l! N" [% c
(setq incr (/ paodd pnts))
2 u4 ^0 W' ~4 ~* g, r (setq p 0.0)" y; o0 `. _ Q8 d
(setq pitr (/ pitd 2.0))
, t2 r# F( c; n4 y. X: g (setq pang (/ 360. (* numt 4.0)))
0 _3 j$ S1 N7 T8 o (setq pang (/ (* pang pi) 180.0))
& `) w# N: i" j8 @. F- J Z (graphscr)% g/ B: [5 D# J0 A& b$ G& i) {
(setq p2 (getpoint "center of gear:"))
! M1 w6 @) u, D0 [& X$ ~2 X/ a (setq y2 (cadr p2))
! x) {' i f; L/ L% h4 V! S t (setq x2 (car p2))/ `: K$ x) X k
(setq r0 (/ (/ (- numt 2.5) diap) 2))
5 C* c+ e2 _- L0 B2 K4 P& j8 ]" @ (setq r1 (/ 0.2 diap))- K5 Y. G- {- l6 {) x
(setq h (sqrt (- (* (+ r1 r0) (+ r1 r0)) (* r1 r1))))
5 \& e& b5 z; y6 N* Z (setq ang0 (/ (* pi 2) numt))
+ O2 ]7 }2 W& m U
+ c4 g: G7 z( ?1 L) Q (setq y5 (+ y2 basr))3 u: R, l+ f. h8 }* a4 n0 |$ @8 E
(setq p5 (list x2 y5)) B+ C6 P. v+ R9 }" Y
(setq y55 (+ y2 r0)). H& J4 v) P( e) ~- ]0 N- H- {. F
(setq p55 (list x2 y55))3 j6 d& f5 p1 X
(setq p88 (list (+ x2 2) (+ y5 2)))
+ a. Q! u5 g* X1 n& w' P3 `8 G (setq a3 (/ (* pi 5) 4))3 `* R2 g: l: W# o1 B! T
(setq a4 (/ pi 4))% n- E/ I9 a, O$ d) a( I
(setq pz3 (polar p2 a3 (* orad 1.5)))" v4 B. [% P( `6 T* w5 a3 q
(setq pz4 (polar p2 a4 (* orad 1.5)))- F: E' w0 H! |
(command "zoom" "w" pz3 pz4)% w% D; j( |( _7 P, i) s
;
8 ~! `5 e. a) U- c3 S (setq clay (getvar "CLAYER"))
5 D8 D E- G" s: ]5 L (setq sblip (getvar "BLIPMODE"))
; a, \/ ?* `+ Q/ Z (setq ts (tblsearch "LAYER" "CEN"))
% m# e. F1 c/ U+ A3 M (if (null ts)
" ^3 p8 T7 S* C9 k( C' _/ |! e2 f (progn: j8 r: L3 `% F; @' }6 d$ B5 | w
(prompt "\nCreating new layer - CEN. ") " N# s* g3 U1 Z5 C- k$ _, X3 z
(setvar "BLIPMODE" 0)) }2 c0 K, e$ A: w
(command "LAYER" "M" "CEN" "LT" "CENTER" "CEN" "C" "RED" "CEN" "")
2 o i$ A; e2 j" o: x3 x )/ m8 m, ~6 Z( @3 W
(progn
9 G+ v8 C l; v- A4 [ (if (> (cdr (assoc 70 ts)) 0) (command "LAYER" "T" "CEN" "ON" "CEN" "U" "CEN" ""))* K7 o% l" J- e3 J% Z( f1 g: A
(command "LAYER" "S" "cen" "")
$ v5 H/ p- {) p+ z1 K7 I9 P )
0 I" M$ c( Z9 A )& e& ^; V# |- E; A+ h1 l9 M. P
(command "circle" p2 pitr)8 I' @9 k# m2 ]8 W' w+ S
(setvar "BLIPMODE" sblip)
1 u! c& j3 a6 Z7 g0 ]. t (command "LAYER" "S" clay "")
; ?4 R# x. }5 n4 w5 @& I;3 O3 ]0 [' \$ w( k( \9 q8 r4 J) i8 \2 S3 }
(setq a1 (- (/ pi 2 ) 0.1))
$ s# ?* V, T8 w/ t- [' ^ (setq a2 (+ (/ pi 2) 0.1))7 v% |4 G l9 W9 e
(setq pz1 (polar p2 a1 basr))
- Y# ^3 H5 c' O (setq pz2 (polar p2 a2 orad))% n, F4 ^9 x; o# z
(command "zoom" "w" pz1 pz2)
' D5 G; w" Y8 [& y (setq s (ssadd))
, Q' T0 z3 Q, X) ~1 D (setq le (entlast))0 v% a8 K" \# [% b: Q# x' g
(setq test 0); y1 T/ K4 M5 W4 v8 h1 l
/ t4 ^7 d: ]9 x0 z- k! t% F o (command "pline" p5): T! x4 o$ L. h; S& w% k& u6 a
(setq p (+ incr p ))
y+ ?5 s" T1 k% \6 s, C- \! w (while (> pnts 0)' j: m$ G7 R' W" K: t" n
(setq e1 (sin p))
& m% i/ C2 K9 y4 e4 O( y' W2 R; W (setq e2 (cos p))
9 S9 c1 J J `, t! Z, D (setq e (/ e1 e2))
7 c2 Z# l, R- E+ P A Q (setq j (- e p))( S/ g1 h: h: G. a
(setq x1 (* (/ (sin j) (cos p)) basr))
v+ g$ F1 z2 m( n+ H( f (setq y1 (* (/ (cos j) (cos p)) basr)); }, X; r) t8 ?% ~! h3 y1 \) H1 _
(setq x3 (+ x2 x1))
) V0 ]6 D A# M (setq y3 (+ y2 y1))
/ p& N: C0 w A( D5 z. } (setq p3 (list x3 y3))
7 K: E) p5 G5 \3 d (command p3): @" ]5 u% @* @& f; U
(setq p (+ incr p))
( Y; w! P; t' s* D (setq pnts (- pnts 1))
, v- y, k! N( l (if (/= test 1)
0 i: u0 P) ?9 ~/ N0 a0 z (progn: j$ M# ^5 [! l( s
(setq hyp (sqrt (+ (expt x1 2) (expt y1 2))))
' d' D# g' ^+ Z" d; X/ Q (if (> hyp pitr)
2 R- M- \) \0 R+ u) ~8 V. a+ a (progn& j2 D% B9 J+ i; r! E/ A
(setq pint p3)
I0 B% Y2 `0 m (setq test 1)
3 Q- N% H$ n7 W8 B2 y+ F )- M0 j+ j. N* Y: G/ ^9 Z; W
)
6 U5 i0 d" N3 e1 n8 k( p9 r );endif) O" o6 t& g- g4 U2 L* K4 W
);endif
& X' ^% }" o' \" b( }: p- @9 S )# E8 _4 V( A2 _# C, ]& D4 M- U4 |
(command "")" s9 }# {' a4 p" `) p; ?
(setq L2 (ssget "L"))
; T! R% |& `5 A" S% d- C (initget "Y y N n")2 X# y! G c! g* E
(setq ans (getkword "\n Finish the gear ?:<Y> "))) q$ W( M) ], Y; G& Z8 |
(if (/= ans "N")# Z* H, t: y* @, F
(progn6 l- C7 M. y4 u% O
(command "zoom" "w" pz1 pz2)3 z' u; j) J3 Y2 u' Q3 q
(setq p11 (osnap pint "inter")): X! i2 U* s0 m1 U# j
(setq ang (angle p2 p11)): E- \' e* t& g) \& ~
(setq angi (- ang pang))1 R4 z9 ]& g: K
(setq p12 (polar p2 angi 1.0))
# T/ E% ~$ Z+ c$ X! F/ d+ Y;
6 r! ]* h% f( }+ T* t0 a4 `- f (if (< (* 0.94 numt (/ 1 diap)) (* h 2.0005))! K; m- L) k2 u% C$ _ o
(progn
8 \% `7 r: b7 j (if (< numt 42)
1 g8 E4 z, K4 f5 J5 B4 [/ O (progn
# r* `4 |% u( I: p (setq p56 (list x2 (+ y2 r0)))
% }% S9 s6 u" l4 c (command "line" p56 p5 "")' a+ E. b' V" Z$ g( E
(setq L33 (entlast))
/ I6 [4 v# f5 e+ [1 }+ R& g (command "zoom" "w" p77 p88)
! z7 P) y3 L. _1 L6 ] (command "mirror" L2 L33 "" p2 p12 "")# e6 y1 z. C+ G( c$ z. _
(setq adj1 (- angi (/ pi 2))): w. a2 J2 }4 E5 k8 [ q- S4 i
(setq adj2 (- (/ pi 2)(* pang 4)))2 i9 p8 s9 e1 v7 M2 e
(setq p17 (polar p2 (+ angi adj1) r0))3 P/ P# k' v8 }' x6 w
(setq p16 (polar p2 adj2 r0)): x3 A" D0 Y0 a
(command "arc" p16 "c" p2 p17)
T* q5 u( k* r1 p ) ;end progn
1 W1 G' Y% n, h. c6 X w5 a( i (progn9 S! H; x$ m9 B8 w. H
(command "zoom" "w" p77 p88)' {8 w" f6 l" u" G% N
(command "mirror" L2 "" p2 p12 "")
2 U" D; [1 w! O( ` (setq pL1 (entlast))
9 M: d- y8 u5 `3 r (setq adj1 (- angi (/ pi 2)))
( q N4 {* ?% S8 `4 u. ^ (setq adj2 (- (/ pi 2)(* pang 4)))
" a, r6 E; W# D+ ]/ } (setq p17 (polar p2 (+ angi adj1) r0))
: S& @: j, o0 q( ~4 T7 B6 {5 ? (setq p16 (polar p2 adj2 r0))
9 y' Z& [% I) o. y6 D ] (if (> numt 101)
7 N9 c: s y/ M9 H4 V v0 Y4 s (command "arc" p17 "c" p2 p16)( r4 j( T# P( x" z7 d- v- }
(command "arc" p16 "c" p2 p17))
8 `3 [% O9 n. @* w8 M) D (setq arc4 (entlast))1 q% O; ?5 D8 q5 a+ g2 ^& ^
(setq p171 (polar p17 0.7854 (/ 0.4 diap)))
, w% t! X" K% `( o+ V2 y5 @ (setq p172 (polar p17 3.9 (/ 0.4 diap)))
8 |! n' Z, N4 ?! _; C) I (if (> numt 101)1 x1 q9 _. t8 H5 b- c; [
(setq p18 (polar p2 (+ angi adj1 ang0) r0))6 v1 _. J) n2 ^; ^! f$ F" x/ Q- R
(setq p18 (polar p2 (+ adj2 ang0) r0)))3 b2 n# R3 r# ?4 y9 J2 ~* g
(setq p181 (polar p18 2.3 (/ 0.4 diap)))
' O$ Q: K, y. e) c1 T4 Q# ]1 k, [ (setq p182 (polar p18 5.5 (/ 0.4 diap))): R( H- K. X) g6 x5 U, y
(command "zoom" "w" p171 p172)5 }$ D! y5 ~. G6 j2 B
(if (> numt 101)
% u! l) C* f; w* n) |( Q# a (command "extend" pL1 "" p16 "")
" s& h D+ c( ^: D/ m9 }. a3 J% w (command "extend" pL1 "" p17 ""))
$ p" f# _" l7 }+ P (setq ang0 (/ (* ang0 180) pi))
' W! r# e( B3 I (command "rotate" arc4 "" p2 ang0)
' N* D% I) f ^- H2 L; S$ Z9 T (command "zoom" "w" p181 p182)
1 S3 O6 M; ~8 o- R7 e (command "extend" L2 "" p18 "")& ?* A7 K& N. p
(command "zoom" "w" pz1 pz2)( y" w" W" h+ @9 Y; S9 Y6 O1 n7 B
(command "trim" arc4 "" p5 "")
O# m. G( M8 q (command "erase" pl1 "")1 ~0 p& s6 Z$ }+ Z% {) A! y0 @
(command "mirror" L2 "" p2 p12 "")
$ [+ y4 |$ {* L7 m! [. h0 | ) ;end progn
; N% a% D+ i! Y& v& q: Y ) ;end if- I ?: h- k2 ~% i0 {* M" G
) ;end progn8 E9 B1 w) n1 \' o
(progn % Z5 I" ?+ L* x* U+ J
(setq ang12 (- (/ pi 2) (angle p2 p12)))
7 c0 \0 a/ c8 e/ w) e* |# @ (setq ang57 (atan (/ r1 h)))
) ~9 |. s8 K3 @. [0 ?5 P" `& m (setq ang58 (- ang0 (* ang12 2) (* ang57 2)))
$ u9 Q# B- h+ q; ^1 _. e# y (setq ang577 (+ (/ pi 2) ang57))
- w. d- x: S% f4 x) L9 C' l (setq ang588 (+ ang577 ang58))2 T7 m- }% @, {1 ?* G
(setq p57 (polar p2 ang577 (+ r1 r0)))
) \+ q2 R7 }3 i2 U: x1 N (setq p577 (polar p2 ang577 r0))
' S) g% s5 N8 D" r4 p# L (setq p588 (polar p2 ang588 r0))
$ o, o# ]- b8 X (setq p56 (list x2 (+ y2 h)))
1 V2 m0 p9 z: h5 e (command "arc" p577 "c" p57 p56)
$ j5 X$ _& d) t' I (setq arc1 (entlast))# Q( B) E8 v ?. }% ]
(command "arc" p577 "c" p2 p588)
+ D0 t) c% k- U (setq arc2 (entlast))
+ f t# ]! {" |0 S% E (command "line" p56 p5 "")2 y& r7 a/ z( _' z
(setq L33 (entlast))
0 y+ [: ~+ s) G (command "zoom" "w" p77 p88)- i) X3 y4 |, G8 o4 ^( u3 z! k
(command "mirror" arc1 arc2 L2 L33 "" p2 p12 "")
% T6 T7 p; J2 { Z( M (command "erase" arc2 "")
7 `# ?' `+ U, k# J/ B( E' I2 }1 ]9 t ) ;end progn
7 {8 o+ g; o( ~" n$ F ) ;end if
& O& B3 ], G6 j) H; ' C1 N9 R( l, i: W5 _
(setq beta (angle p2 p3))1 m6 M3 D8 D9 m7 q
(setq ang2 (- (* angi 2) beta))
. P7 S( s/ u8 n6 D# I (setq p15 (polar p2 ang2 orad)). r- Z1 K, Y: Q( F0 f
(command "arc" p15 "c" p2 p3)+ I( |: c7 i* Y( A; w. b% ~
(while (setq le (entnext le))1 O( f. R& L4 E/ Y* G0 R
(ssadd le s)2 b8 O U( b2 b
)
2 o: p" E- G8 k" G+ ` (command "array" s "" "p" p2 numt "" ""); g' ~, U4 ~) P+ m; x
(setq q1 (nth 0 p2))9 G5 X. r" X1 T0 w( A* Z2 I" m) G* [
(setq q2 (nth 1 p2)); W. t0 N9 ^* N0 J% y2 K
(setq q5 (+ q1 pitr 2))
4 s: x9 k5 @9 M( ] (setq q6 (- q2 pitr 2))9 g; a. p4 J; `4 Y1 j1 w; ~: D
(setq q3 (- q1 pitr 2))
! o8 z3 B/ T$ R' ?4 ^$ p2 u) M (setq q4 (+ q2 pitr 2))
$ a$ t! t; f6 v" r (setq q1 (list q5 q6))
, }* O; m8 K7 P- C0 a! C (setq q2 (list q3 q4))
1 T8 |& p5 Y. u) X4 y8 X (command "zoom" "w" q1 q2)0 l& l% b6 l# P9 P6 B( K
)
/ W! w: _+ r% |3 o )2 q/ w* {& _; m! `+ ^) e
(setvar "pickbox" 5)# o0 L0 I0 g8 }# n. K/ S+ [5 ^1 d% q
(setvar "aperture" 5)' u3 S G2 C- k1 J# f- R# \
(setvar "osmode" 37)5 L3 n: e1 h7 ^3 t( E
# R& l0 p$ g4 Y L3 X% C; M }
(princ "Finish gear ")% G$ i' ]' g A& t* L" A9 Y$ X
(princ numt)
/ \5 q( y4 L* w3 C9 w& v/ V& W (princ "T")
! f4 \8 m1 l$ q) R (princ)
/ u" T3 X9 I" z c )4 l# Q7 F1 a' O5 V* H2 ^7 y5 `
0 e8 @1 F) C1 P4 p+ V* G$ [) U |