(defun C:gear (), ~# f/ Y. f* D, c" I) C: s4 N
(setq numt nil- ?+ J" b* n* D& `9 E& T& I0 q/ W
diap nil 2 t% Z7 b: X6 t; l* q A
prsa nil
2 T9 O$ c( d8 G9 Z6 N4 U pnts nil5 ?5 _; }; J Q: R' V5 q
test nil
$ J: g# I) Q8 y9 I pwd nil- A( p2 q/ |% \2 s: f
)
( Y$ P6 G# ]- q7 _: L4 E- V- a 8 m# L, [1 A7 q5 ^; n; E7 F
(setq numt (getint "Number of teeth:<24>"))$ \# E% m5 T+ n( J1 w/ q
(if (= numt nil), S+ i9 s! D1 A
(setq numt 24)3 g. q) ^8 J ~$ S2 Y
); K+ Z Z$ M/ }4 m! A% E
(setq diap (getreal "Modulus of gear:<0.5> "))3 G6 X+ c. J0 T
(if (= diap nil)2 m' k/ `/ u( u8 ^# ?
(setq diap (/ 1 0.5))
6 c+ V3 n4 n( P: T' Z (setq diap (/ 1 diap))
7 k! D/ y/ X' e( e8 C7 n X )( r4 ^! m+ y$ x5 K0 @3 Y
(setq prsa (getreal "Pressure angle:<20.0> "))
1 Z T) ~7 `0 F/ c4 S (if (= prsa nil)3 K( q- L! u. u! I" m' q5 I
(setq prsa 20.0). _5 V+ o: l) {- t) e& p8 d
)
. }+ X, T0 }7 b: l (setq pnts (getint "number of points on curve:<40> "))1 g3 s, L, J* d* A2 g3 u# i0 n
(if (= pnts nil)% `% o3 i0 G; N& M$ H$ _
(setq pnts 40)* F& U7 K% M9 A4 l
)
- W* \% |4 w' N. q
" p; d* l5 ?8 ] U2 K: G7 P; (setq pwd (getreal "Please input password:")). `1 z/ x7 T6 J$ `
; (if (/= pwd 8833)! V$ _) @5 ]* @7 o8 m
; (setq numt 0)3 c. f5 V1 D2 R! a4 k
; )8 v+ U. D7 ?( }& b
; (if (= pwd nil)
[, R- S# U2 s- [7 e. b7 I; (setq numt 0)' P0 n: l# v" q9 e9 n# P
; )
% C! o' D4 a+ k6 a* r;: B# l2 Z4 J. `! |% M6 ~1 s7 |
(command "osnap" "non")
/ ?1 Z$ T# D7 w! p, v (setvar "cmdecho" 0)5 i c P, I0 ^% Y
(setq oldvar (getvar "pickbox"))
' Q2 W, X6 Y+ c; S (setvar "pickbox" 0), l- G# u7 n8 T9 Z- A
(setvar "aperture" 1)9 F0 o2 v( X$ S1 U
(command "osmode" "0" )
8 T4 ^. P/ m% ]: F0 a;
/ ^/ S# ]& D: A: h3 Q, h. F* I* J (setq prsa (/ (* prsa pi) 180.0))
3 d: `; W6 g) R# T8 R6 q% ` (setq pitd (/ numt diap)). F$ S# }) C0 j1 ]1 O1 Q
(setq outd (/ (+ numt 2) diap))6 A; T9 T7 I5 w/ D' p* Y
(setq basr (/ (* pitd (cos prsa)) 2))
2 h3 b& D6 C! F. L/ u* F+ p (setq orad (/ outd 2.0))
. E* X5 Q8 B% Q (setq z (- (expt orad 2.0) (expt basr 2.0)))
9 Y2 u4 i7 F$ ^, s: k% w) } (setq x (sqrt z))
. f# D9 k. b$ _/ k& r, m2 G+ P (setq paodd (atan (/ x basr)))$ T7 w) p4 D3 z
(setq incr (/ paodd pnts)); |; ?& v4 S. ~% L5 s
(setq p 0.0)' [& M$ J! r2 X* P- `3 z7 u
(setq pitr (/ pitd 2.0))9 r2 ~) {; I1 k$ k+ G( q9 V% h1 M
(setq pang (/ 360. (* numt 4.0)))+ B; |8 g& Q* k9 n
(setq pang (/ (* pang pi) 180.0))9 H X0 F0 V, l
(graphscr)
/ F2 V7 A8 g+ K% u) w, ~6 u' z E" k (setq p2 (getpoint "center of gear:"))& X' Q/ P f7 `" j E
(setq y2 (cadr p2))
5 E y. U7 H5 L7 J f/ r' o* R (setq x2 (car p2))$ Q p# V. h6 l: {
(setq r0 (/ (/ (- numt 2.5) diap) 2))- u% `7 s* z6 k" P, Y1 s% P' R
(setq r1 (/ 0.2 diap))
! }7 v3 X' r( Y; q% b (setq h (sqrt (- (* (+ r1 r0) (+ r1 r0)) (* r1 r1))))) I1 J1 ^8 v; W% W
(setq ang0 (/ (* pi 2) numt))
! {3 X; Q9 S2 Q) ?. e( V' D! [5 b6 R. J- i' I5 `; t- i
(setq y5 (+ y2 basr))
3 D& m; I V; z: N+ ]3 |0 g (setq p5 (list x2 y5))
% u6 ^: ~- M: X9 E2 D9 u (setq y55 (+ y2 r0))
6 O! j/ ^8 O: L& U3 k! c (setq p55 (list x2 y55))* q- {: t& |; S# H
(setq p88 (list (+ x2 2) (+ y5 2)))' k4 P9 w4 e% U8 F3 [% G% ^1 W
(setq a3 (/ (* pi 5) 4))
* j- g C$ I3 T) p! s. n% f B (setq a4 (/ pi 4))$ e) y* w, ~+ Y2 B
(setq pz3 (polar p2 a3 (* orad 1.5)))
I% y5 D: `! b# o, t$ z (setq pz4 (polar p2 a4 (* orad 1.5)))
/ E+ m! Z$ q5 K (command "zoom" "w" pz3 pz4)9 p+ r# z6 F% l+ |
;6 P6 S' e3 A1 X S* V+ j
(setq clay (getvar "CLAYER"))+ h( X! q) n3 e' i5 x. v }
(setq sblip (getvar "BLIPMODE"))
9 O& Z0 v8 O% O" G (setq ts (tblsearch "LAYER" "CEN"))' C8 j) M: X! n4 V- y
(if (null ts)5 |, h, n8 M w/ e' r8 K$ | X& q
(progn% X" D8 b/ g/ A& T2 l9 E
(prompt "\nCreating new layer - CEN. ")
4 A7 B/ p' w# E I+ Z0 a (setvar "BLIPMODE" 0)
2 K# l3 |: B( e3 o+ e% J; s (command "LAYER" "M" "CEN" "LT" "CENTER" "CEN" "C" "RED" "CEN" "") " \4 v% Y2 w+ l: \$ m5 u- D
)
- m% D' j, U8 J& ?: m/ k (progn
, l& F& i6 s+ h- c; S1 l (if (> (cdr (assoc 70 ts)) 0) (command "LAYER" "T" "CEN" "ON" "CEN" "U" "CEN" ""))
9 z3 T/ c: U# j! p (command "LAYER" "S" "cen" "")' x' P1 V8 O3 Y* E" ?! |& W' E. Z
)
# C0 n: X% J) {$ q4 |; m; w )7 A6 k2 \6 ]- k% ]
(command "circle" p2 pitr)$ A8 I' ~9 Y( n( Y( g" q
(setvar "BLIPMODE" sblip)
8 ~" z: x% L% b; h' o8 P& y (command "LAYER" "S" clay "")
! w- Z k1 A* D0 K* v4 I;
$ Y- I3 Q. L$ \* | (setq a1 (- (/ pi 2 ) 0.1))& C# Z& ^ {: g" w
(setq a2 (+ (/ pi 2) 0.1))
5 C6 b. }* O, p! b$ F (setq pz1 (polar p2 a1 basr))+ Z }( h( {9 y! U. K
(setq pz2 (polar p2 a2 orad)). ~2 K4 d7 Q/ \) r- f$ a) G
(command "zoom" "w" pz1 pz2)7 _7 N. _" f& l, t: ?+ g
(setq s (ssadd))8 d/ A* n+ J# s
(setq le (entlast))' ?2 j4 b! |' B( X% [
(setq test 0)- e" p, A& ]% W4 I
( h# X9 V* b) _5 `# f6 G: @5 N (command "pline" p5)
^$ j8 _3 U' p X (setq p (+ incr p ))
& n5 e- {5 w6 N" E0 n (while (> pnts 0)
, X! K; r, n5 c9 E& O1 ] (setq e1 (sin p))
8 C* n- A& n3 V5 f% b2 F, ~ (setq e2 (cos p))
) d; o4 c# I8 Z9 w (setq e (/ e1 e2))
" K) C! R. ^* z; f4 ? ^ (setq j (- e p))
- V, \+ N- y* Q9 H3 c (setq x1 (* (/ (sin j) (cos p)) basr))
{1 a0 ]1 c4 Q6 I- q/ Z! { (setq y1 (* (/ (cos j) (cos p)) basr))1 L! G4 X6 s) t
(setq x3 (+ x2 x1))
1 D7 j7 u+ a2 d( r. O2 ~$ F8 e (setq y3 (+ y2 y1))+ p: ]3 E$ @! ~ ~6 {! c' p, G
(setq p3 (list x3 y3))
/ n, d- x1 ]2 B! K; M& p" R7 s (command p3)
3 P) n1 d' p! [9 V* c; h (setq p (+ incr p))5 R. ?& N0 |) ]( g: n
(setq pnts (- pnts 1))8 C' C# Z0 l& ^9 H
(if (/= test 1)5 L# D* R. |7 }2 [8 _! W% }
(progn9 ?- v0 K8 B- z s: u5 J6 a
(setq hyp (sqrt (+ (expt x1 2) (expt y1 2))))
+ H6 V6 t6 u( ^2 n$ v- s9 v (if (> hyp pitr): D/ ]% r: B. \! t9 _9 P
(progn
: _" b1 N/ R) \! X( | (setq pint p3)
8 d7 s; u9 B0 o0 I* k: \: @% U9 y (setq test 1)/ S" a$ S) s ~3 x( v s9 Y" w# A
)
/ H6 b, U0 U4 n' ]/ r% s' \ )
3 Q8 S# }$ X" H );endif) L) c: k) W+ \
);endif% o: ~. |4 B0 e
)7 Q) G% f4 l1 D
(command "")* ~ P0 O# n$ h; [ e0 f i
(setq L2 (ssget "L"))! [0 n. K1 r2 I4 P1 M/ ?
(initget "Y y N n")
1 ?4 a3 z! F6 {( S3 { (setq ans (getkword "\n Finish the gear ?:<Y> ")), x b3 \: Q. r% n
(if (/= ans "N")
: k Z' F) g, t) @- V6 i3 b (progn
! y% M5 ]3 d1 ?& i% j* D (command "zoom" "w" pz1 pz2)
% x8 O8 {! [2 w. \0 H v (setq p11 (osnap pint "inter"))
3 p* s3 U h! L, B" M (setq ang (angle p2 p11))* P4 E/ d E3 p7 p6 \1 q' H& R
(setq angi (- ang pang))
' }( `6 G- p9 r8 |5 P (setq p12 (polar p2 angi 1.0))
' Y# v; o0 g3 s6 U8 z9 K;
# l' M* w3 X+ B) p5 ` (if (< (* 0.94 numt (/ 1 diap)) (* h 2.0005))4 k: X/ R0 h: [6 }
(progn
8 F) C V' p* z) |8 g3 B2 }4 V (if (< numt 42)
# P4 @8 u5 A' P+ {6 I (progn5 H) U& g$ u0 [
(setq p56 (list x2 (+ y2 r0)))% N& @; Q) P# L0 S& l- D; H, U
(command "line" p56 p5 "")2 @7 R( p4 o0 \4 r) V: b- y
(setq L33 (entlast))2 | [ v: i3 f! }
(command "zoom" "w" p77 p88)
3 `7 e& e! a- y7 E (command "mirror" L2 L33 "" p2 p12 "")
. |. N* M2 ~0 y0 n) S (setq adj1 (- angi (/ pi 2)))
1 Q* g0 ^' D5 g% I; m. C& ^ (setq adj2 (- (/ pi 2)(* pang 4)))2 }, ?! L6 o5 R) O3 J! \
(setq p17 (polar p2 (+ angi adj1) r0))0 q4 c& K( p- ?5 d) g
(setq p16 (polar p2 adj2 r0))
" l2 o6 C" \6 u! M (command "arc" p16 "c" p2 p17)
# ?7 c+ {& f3 N# ^7 O' h+ n3 R ) ;end progn
p/ H" g" s8 K3 G" G/ W/ J# q (progn5 R% E" A6 v, \; N, k7 W
(command "zoom" "w" p77 p88) K* @7 _( ?2 {* P& |( [* U
(command "mirror" L2 "" p2 p12 "")5 D1 m. H1 k. [0 v
(setq pL1 (entlast))
/ d6 l, k9 ?: h$ v/ V (setq adj1 (- angi (/ pi 2)))
. G) R7 H& b- p (setq adj2 (- (/ pi 2)(* pang 4)))
2 W. {9 X/ `6 T* n1 i, ~5 t" D (setq p17 (polar p2 (+ angi adj1) r0))
# n$ y3 [0 w& d3 K (setq p16 (polar p2 adj2 r0))
+ r0 [* t, n+ e. M9 T, M; [ (if (> numt 101)/ _$ p7 U3 k6 p4 @1 X% C- Q, v
(command "arc" p17 "c" p2 p16)( o/ `- ~9 G# A! g9 t3 p
(command "arc" p16 "c" p2 p17))
4 a- |8 g% F0 Y4 E) z& [# i$ { (setq arc4 (entlast))6 L. t, P' r0 n
(setq p171 (polar p17 0.7854 (/ 0.4 diap)))
5 ^# z5 G6 N! [- ^0 z3 c6 ~ (setq p172 (polar p17 3.9 (/ 0.4 diap)))% p7 P3 ?! l& z
(if (> numt 101)
: e6 M) A% l4 a5 U) K/ S! l+ w (setq p18 (polar p2 (+ angi adj1 ang0) r0))
' b3 q9 v2 H2 c" @ (setq p18 (polar p2 (+ adj2 ang0) r0)))
5 X9 D9 l5 w6 N$ t2 B4 m. l (setq p181 (polar p18 2.3 (/ 0.4 diap))); I1 |/ U& |6 V& {# m8 i! {
(setq p182 (polar p18 5.5 (/ 0.4 diap)))
4 A0 f- e4 M/ V) ^# B (command "zoom" "w" p171 p172): G- N5 J3 l, u9 P5 t: h
(if (> numt 101)
$ V8 l! H3 T x {* p$ ?( |& i (command "extend" pL1 "" p16 "") ) U6 h# Y1 \4 M$ G' f0 H+ D" g- W
(command "extend" pL1 "" p17 ""))# ~* K$ c5 _1 g0 w- A" E
(setq ang0 (/ (* ang0 180) pi))
2 Q" S2 m2 `( p2 H0 x (command "rotate" arc4 "" p2 ang0)3 A: {5 n9 f* p& s/ g
(command "zoom" "w" p181 p182)
% s% i; R% L ~6 F2 k6 u! ^/ A (command "extend" L2 "" p18 "") x/ V4 Z6 B7 L/ n; n3 z
(command "zoom" "w" pz1 pz2)
# J( m/ Z! R0 {# w, {! n, h (command "trim" arc4 "" p5 "")
7 d' D' i2 H6 ]$ z. c (command "erase" pl1 "")
1 {' M* U1 M# W& l2 ~7 M (command "mirror" L2 "" p2 p12 "")& ?- W) w4 y: S0 ^2 H2 t; d
) ;end progn' z; W8 d" b, p# E. N5 r
) ;end if0 E( P7 |7 y$ M8 }
) ;end progn8 `1 A, g/ ]+ K7 P) G
(progn : g# ]. F) ^ u5 Y# E/ x3 O
(setq ang12 (- (/ pi 2) (angle p2 p12))) ; D4 A8 e4 U- j, o; T& ~& a
(setq ang57 (atan (/ r1 h)))
) H; _# v4 E9 N. @, J2 j' O (setq ang58 (- ang0 (* ang12 2) (* ang57 2)))
3 x0 H- w) \* S9 m- i (setq ang577 (+ (/ pi 2) ang57))6 b$ ~$ {0 ?. _
(setq ang588 (+ ang577 ang58))3 `, P$ W2 \) Y6 j6 s. l: F
(setq p57 (polar p2 ang577 (+ r1 r0))) H' n) E$ C) [6 H
(setq p577 (polar p2 ang577 r0))5 Z3 ]4 }- u! J( C3 M
(setq p588 (polar p2 ang588 r0))
# J6 s# C. s3 a7 d (setq p56 (list x2 (+ y2 h)))4 B3 {3 T5 z' h% R1 r. x# I
(command "arc" p577 "c" p57 p56)
" V/ t2 I0 C2 } (setq arc1 (entlast))
5 r: V, h- o- j0 |! l# S$ L" D& b (command "arc" p577 "c" p2 p588)/ y. X% H: v# v7 c; ^
(setq arc2 (entlast))+ I) f0 ?0 n' I1 I: Y
(command "line" p56 p5 ""). s2 k0 ^$ P) `; B0 I# B
(setq L33 (entlast)), Z1 Y5 T/ K6 Z' G( ^. V1 B' G
(command "zoom" "w" p77 p88)) i! [" h- O0 ?# l
(command "mirror" arc1 arc2 L2 L33 "" p2 p12 "")" g# f0 V$ q/ D- d1 B6 K2 v: G
(command "erase" arc2 "")7 u6 p! g. H8 D5 ]2 w/ e& w6 a
) ;end progn
/ Y9 d, D# A5 ~4 P. l( y ) ;end if
6 W( T3 |6 J0 o# W0 L6 o; 5 V% p N; h- H$ R2 Y' m. I+ m
(setq beta (angle p2 p3)); d, M% a& e) y
(setq ang2 (- (* angi 2) beta))# [- P& [4 O: A4 S, m: e O
(setq p15 (polar p2 ang2 orad))
' Y" A3 e5 I1 e* [# @: P (command "arc" p15 "c" p2 p3)& d6 o6 p% c% j' d; Q
(while (setq le (entnext le))
0 u2 L8 ^* a7 ^2 [7 P (ssadd le s)
% N; M) q* K- q( W. c )! x' o/ q( ]1 r0 t* z
(command "array" s "" "p" p2 numt "" "")
0 s% L/ N% w: }7 n8 L. f (setq q1 (nth 0 p2)). ]% m; ?# i$ i8 V4 w# Q4 q
(setq q2 (nth 1 p2))
4 T' x, a' t8 v. G/ ] (setq q5 (+ q1 pitr 2))1 X5 T4 E+ K8 o! L6 R
(setq q6 (- q2 pitr 2))
4 ]* I: t2 w" ? (setq q3 (- q1 pitr 2))
& u+ e! a+ T7 _+ m3 s. y I (setq q4 (+ q2 pitr 2))
) Q( y8 D5 J9 y6 r. ` (setq q1 (list q5 q6))
2 l) ^1 V9 { ]# f. E6 N" a6 H. `! u (setq q2 (list q3 q4))/ I/ r; L8 O- p9 o
(command "zoom" "w" q1 q2)# _9 [4 i g/ d1 V5 G) x: ^
)
- i ~% \. f" m; D )
. v1 N- Y1 {0 F% s u2 b (setvar "pickbox" 5)& O6 {, s) d# T: t9 s& N+ Z+ [! y
(setvar "aperture" 5)8 ?, k+ \. @9 l" _: P0 `$ Q6 p
(setvar "osmode" 37)# w `8 x6 e7 ~/ `3 h: J1 ^
& n; R, C: i ~0 C' P! Q* D
(princ "Finish gear ")
7 A( e( ]8 D# I9 Q (princ numt)) i+ ~+ E% R% B$ r
(princ "T")( P. U/ z% J. n) r f [: ]
(princ) p# C8 H8 {( W9 ]6 [ j" C! m# B
). |* u/ S+ Y8 m: H: E
3 P! p7 k) l6 z4 o8 ] q5 v/ A |