(defun C:gear ()
: `% u0 q' K# W (setq numt nil
* }0 E* v% E: J5 e# N diap nil
$ t6 X: F7 @- A. D prsa nil. O# K, K3 G# c/ m1 ^% h; n) X# Z; d' C
pnts nil1 l( R- ^7 L7 }, d9 H, P
test nil& C5 z* }& {+ n* ^9 m$ r& |/ g5 r
pwd nil, y ^" M F, G9 |: M- }9 O
)
8 O% y |; A" p: g$ n4 N* I
% J6 }9 A' w: Z" {/ O- F1 U9 n4 w (setq numt (getint "Number of teeth:<24>"))
# X0 o4 }0 W- ^ (if (= numt nil)) y5 x ^+ M$ D7 ]) l/ r3 @8 s# s
(setq numt 24)
6 R! {2 T5 u+ Y )# ]- ^$ Y y# w. n$ X: {
(setq diap (getreal "Modulus of gear:<0.5> "))5 X: a# `: f3 j
(if (= diap nil)$ _, x" g7 ]: v/ r
(setq diap (/ 1 0.5))% ~! z; R/ T) n2 F9 ]
(setq diap (/ 1 diap))
7 R. T+ C1 ^0 X3 I" n2 r )
" b. y4 I* l7 t3 n0 f& ~ (setq prsa (getreal "Pressure angle:<20.0> "))8 a5 f0 M7 J1 |" `
(if (= prsa nil)
3 b3 ~ ?& j9 M5 i4 S' \* Z (setq prsa 20.0)
0 \* v( J3 z R' p; g )% j( ^$ }. A, D, {; P) E4 s& d
(setq pnts (getint "number of points on curve:<40> "))/ S% O% U% c- Z9 N1 r. s
(if (= pnts nil)
' `- U0 @. h9 P6 q% T( w( } (setq pnts 40)
* E- z; [: K, O8 V0 J( @* b ) @/ k: C2 V+ x0 j8 P
; y& w9 o, u" g9 O; (setq pwd (getreal "Please input password:"))
1 m/ Y- _9 ^% y3 v( O; (if (/= pwd 8833)
! @' P* p9 F; U! k* n4 E8 H2 M( P; (setq numt 0)
- [! d$ o; d6 N& K; )
" H b9 J/ v; v; i. f4 W7 D8 W4 P" P- w; (if (= pwd nil)# G, F- Z/ v2 I; i3 d6 b3 _
; (setq numt 0)
# y: x+ E- d/ v, ~; )% g' u" {7 Z$ T0 q
;1 O% x# _) W& y6 T8 Y
(command "osnap" "non")% @& ^0 s3 x$ ~. T2 ^9 x& p- G. y
(setvar "cmdecho" 0)3 y- t, v8 q/ |3 _ ?3 S
(setq oldvar (getvar "pickbox"))
5 o& Y1 K+ B8 s8 `. E0 c9 ? (setvar "pickbox" 0); \1 b# N" x% Q+ s8 j
(setvar "aperture" 1)
1 d% }; b/ r1 V' ]. h (command "osmode" "0" )
3 U. H5 u9 h2 \/ t' };
, L: |8 k, K3 s N4 p! Y' W1 i# o (setq prsa (/ (* prsa pi) 180.0))
g' g; w2 ~ u# u* Z0 Q( F7 F7 _ (setq pitd (/ numt diap)): y+ a4 P3 @/ g4 |. S# I
(setq outd (/ (+ numt 2) diap))
% T" |; [7 h1 ?' ^ (setq basr (/ (* pitd (cos prsa)) 2))
( i" G) g7 k/ S3 T, B, f% m (setq orad (/ outd 2.0))3 l3 C1 D& j/ E' T, r
(setq z (- (expt orad 2.0) (expt basr 2.0)))
0 w( G2 t0 X, Q8 G! o/ I (setq x (sqrt z))! O: ^5 i: v/ ]- P; ^) ^
(setq paodd (atan (/ x basr)))2 z7 L- `; X2 ^; A- q
(setq incr (/ paodd pnts))
' g0 z V( d" o5 A (setq p 0.0)
! S6 G+ L# e5 V (setq pitr (/ pitd 2.0))7 `0 S8 A& z0 d
(setq pang (/ 360. (* numt 4.0)))
6 \9 x$ G; p u+ } (setq pang (/ (* pang pi) 180.0))2 C% L. H( T% a2 A/ n! ^1 G
(graphscr)
& q; g3 P, o0 {. ?5 A9 ` Y (setq p2 (getpoint "center of gear:"))# ~4 P7 S) P/ \
(setq y2 (cadr p2))
5 l7 ~, Z2 E4 B& @ J6 m: D% H* A7 I r (setq x2 (car p2)): l$ P+ b2 ?" v" z5 d5 }
(setq r0 (/ (/ (- numt 2.5) diap) 2))
' |* ]1 y1 X' c, p* p+ G9 c (setq r1 (/ 0.2 diap))8 P" S; u# S$ D7 k
(setq h (sqrt (- (* (+ r1 r0) (+ r1 r0)) (* r1 r1)))) ^1 b$ E: P) j: e- ~+ y
(setq ang0 (/ (* pi 2) numt))5 l% Q* A; M% h& }9 t4 V
% Z/ u* n; k; a! I6 b4 h (setq y5 (+ y2 basr))
5 r2 T( ~9 |6 D! w6 ~5 O i (setq p5 (list x2 y5)): L7 J1 P ]& r7 q
(setq y55 (+ y2 r0))/ u7 ?2 T x: y6 L4 C
(setq p55 (list x2 y55))
; s. r9 ?6 P2 V' g% S* P (setq p88 (list (+ x2 2) (+ y5 2)))$ g' d1 L3 i1 o6 _/ Y K( T" w; x* L
(setq a3 (/ (* pi 5) 4))* @& `9 b* s5 f; B- \ l; G
(setq a4 (/ pi 4))
9 E' T( h1 h/ | u: ? (setq pz3 (polar p2 a3 (* orad 1.5)))3 e) C- j/ e- N) B2 W p
(setq pz4 (polar p2 a4 (* orad 1.5)))
$ P$ `0 c6 b7 E (command "zoom" "w" pz3 pz4)9 R' \) @* @8 d5 Z" x' Q
;
5 b6 M ^3 a0 k* {+ m$ C (setq clay (getvar "CLAYER"))
7 q8 C1 ?* w+ Y$ {* y (setq sblip (getvar "BLIPMODE"))* ^$ ^* c. H: j; P5 }
(setq ts (tblsearch "LAYER" "CEN"))
+ u) [: F& o: u9 V' F (if (null ts)
. N) S3 G' `! T) F. `( m (progn) T# }3 q0 K( |3 d% r- L( _% X3 Y
(prompt "\nCreating new layer - CEN. ")
7 i( Y/ N% M9 a: S3 r5 H6 @3 x (setvar "BLIPMODE" 0)' z7 x0 m: m8 X1 u/ M* H& T
(command "LAYER" "M" "CEN" "LT" "CENTER" "CEN" "C" "RED" "CEN" "") # d! U2 \. _1 C) t: @9 T( D; C9 O
)
) `; l- d" Q1 y* K Z2 `% j (progn( s8 B+ z3 @* }: T! m
(if (> (cdr (assoc 70 ts)) 0) (command "LAYER" "T" "CEN" "ON" "CEN" "U" "CEN" ""))4 j* B7 Y0 i r4 B' x
(command "LAYER" "S" "cen" "") R7 Y+ e- f6 n( E1 B, t5 `
)* Z R$ C7 p/ y" u
)
4 K" F7 M- J" f9 ], V* q: L (command "circle" p2 pitr)6 P/ _' i6 F: i
(setvar "BLIPMODE" sblip)% t: K7 x: X( ?
(command "LAYER" "S" clay "")
2 |) @& J6 A6 N# L;( O, m) }; z3 E) Z
(setq a1 (- (/ pi 2 ) 0.1))
) C1 `; ^6 K% m, } (setq a2 (+ (/ pi 2) 0.1))
/ H4 L$ G: |% ^+ u* t, E/ t7 Q (setq pz1 (polar p2 a1 basr)); s- X& N j! |5 u- R5 s
(setq pz2 (polar p2 a2 orad))
, Z0 Z! {) R$ T# E5 u (command "zoom" "w" pz1 pz2)
3 b7 d) c, r; L1 U (setq s (ssadd))8 w) {; W, O, Y" [+ h: z
(setq le (entlast))8 L+ D! m! s3 }0 o* g
(setq test 0)
2 b _, r# e! r1 q9 `% S- z) f! l6 U
4 r% @$ o& i$ S" B5 v (command "pline" p5)
1 v U& I( L9 J! s+ H (setq p (+ incr p ))! K: y6 a9 `0 U) M- T
(while (> pnts 0)* a! w7 ^6 w& R J; b
(setq e1 (sin p))
/ d' C$ X: g& J- F$ X# t (setq e2 (cos p))
) t! [& R0 t) h3 Z8 p# Y3 a0 m: E; a (setq e (/ e1 e2))
5 X( R4 u$ S- ~8 X6 b: ~ (setq j (- e p))
) @& K$ w' X( N' Q; F& f* Y (setq x1 (* (/ (sin j) (cos p)) basr))9 D. ^( y8 P2 i6 Q' J# ?
(setq y1 (* (/ (cos j) (cos p)) basr))
) g8 R7 p( |8 I* a H+ F2 V/ z (setq x3 (+ x2 x1))
, ` b3 b& T2 i* Y* { (setq y3 (+ y2 y1))9 B( f0 E5 z% a3 ~" J, G- ]
(setq p3 (list x3 y3)) R- E9 `6 X9 O) C: _1 P9 Q4 l2 i
(command p3)3 ^( S4 j$ ~. }& k+ X! S" w
(setq p (+ incr p)). J* q8 V1 g5 Q% u9 A; d; s
(setq pnts (- pnts 1))
3 V0 }' {* P& L( a) z2 R (if (/= test 1)
: V) o0 ]* C. D- q (progn
+ A. ^( {, ^' |+ L& o3 F- N (setq hyp (sqrt (+ (expt x1 2) (expt y1 2))))
8 G+ V% b$ c3 p% X (if (> hyp pitr)
6 j* e; L+ X7 E (progn
9 g5 K7 ?1 s/ J7 z2 w( W+ A5 P6 ^ (setq pint p3)2 ?; b5 U; X7 a& s4 {
(setq test 1)" L2 t0 o# w0 m4 D. M
)
4 G5 s. g+ f Q4 d3 f% h" n )
4 {. X0 l7 ?3 t! z0 G );endif2 W8 @) C/ y" w5 b( e, ]1 `
);endif! f' ~. o$ H0 G" m- f
)
( a7 q; E/ L. G' _ (command "") G" H2 G' |) ~/ L: P3 T
(setq L2 (ssget "L"))8 O, H2 w+ l$ j, }
(initget "Y y N n"), A2 z6 i5 w9 D' h0 i
(setq ans (getkword "\n Finish the gear ?:<Y> "))# X3 K# w; o& H' C, w
(if (/= ans "N")) [' I. [8 A( U: {+ X
(progn) q% X; a- O! D7 }" t
(command "zoom" "w" pz1 pz2)7 W: `4 ]$ @- l; D# J0 o1 O
(setq p11 (osnap pint "inter"))" m# H# [% A# \7 o( a
(setq ang (angle p2 p11))
2 j+ [- U2 v v4 M4 p9 B2 F9 P (setq angi (- ang pang))
% j, Z: r6 B0 A (setq p12 (polar p2 angi 1.0)) M+ a0 R' L D
;
# q7 {4 h3 Z/ Z' T; E- I, ^9 U4 @7 C (if (< (* 0.94 numt (/ 1 diap)) (* h 2.0005))
; m: ^8 l/ d# U* q (progn/ L' H8 |' |' i' ^" O# a2 y# u
(if (< numt 42)
$ @- A9 S1 ^5 H1 B4 S0 R (progn" j; M1 k& A# \6 K/ ?: W" ~4 {+ D6 V
(setq p56 (list x2 (+ y2 r0)))
) l0 P% _ K2 o* p3 E (command "line" p56 p5 "")# v& n* T' q" {5 e. Z; N @
(setq L33 (entlast))9 S9 {5 \# H4 ?3 u
(command "zoom" "w" p77 p88)* u6 ~! B4 U8 o. `8 A3 v
(command "mirror" L2 L33 "" p2 p12 "")% H1 s# h5 X2 D# H! x2 v: c
(setq adj1 (- angi (/ pi 2)))
+ g! Q0 ]% p* }* | (setq adj2 (- (/ pi 2)(* pang 4)))
8 o& k+ @" ^! l) d& Q (setq p17 (polar p2 (+ angi adj1) r0))2 W3 ^$ J( }+ `& Q* U8 {
(setq p16 (polar p2 adj2 r0))
/ a0 Y `! ^' f5 G (command "arc" p16 "c" p2 p17)# ~6 r, Q( r; v2 a+ `) ^
) ;end progn: l( G" j, [* \$ s0 ~# O
(progn
) t \) D( X8 x/ {: k) P$ } (command "zoom" "w" p77 p88)
* L/ O5 R) g% `$ @! v0 @( c& [ (command "mirror" L2 "" p2 p12 "")
4 n' F% R/ T: w, f (setq pL1 (entlast)) - l. \/ b, ^ C2 p5 P3 z
(setq adj1 (- angi (/ pi 2)))
& D! g: o+ V _ (setq adj2 (- (/ pi 2)(* pang 4)))
2 t) @) ?5 I! g& p# S7 w4 M' R (setq p17 (polar p2 (+ angi adj1) r0))
( p" r! a, a( }3 t o3 L+ }/ a( k (setq p16 (polar p2 adj2 r0))0 Z* t& f" u& l- s( p
(if (> numt 101)
+ t* R$ h6 y! g' x( Z; c( e (command "arc" p17 "c" p2 p16)
; y; P% N4 \1 W3 O (command "arc" p16 "c" p2 p17))
* M$ P( E' {9 }# z, x8 z, k/ D: u (setq arc4 (entlast))" v* \) `( s2 b6 ~: Q% y1 V7 C
(setq p171 (polar p17 0.7854 (/ 0.4 diap)))
/ N- n2 q. M w7 D, v (setq p172 (polar p17 3.9 (/ 0.4 diap)))
5 I8 F, A- h3 r7 x; f* D (if (> numt 101): W. X% K0 T- O+ F a
(setq p18 (polar p2 (+ angi adj1 ang0) r0))
/ c9 [$ O7 w* h+ s3 m- @ (setq p18 (polar p2 (+ adj2 ang0) r0)))& \) q& D9 J0 w7 A' Y" t
(setq p181 (polar p18 2.3 (/ 0.4 diap)))
4 y" l& M% s% |$ a4 x! ^5 `" H; h (setq p182 (polar p18 5.5 (/ 0.4 diap)))5 o( C4 ^. A* N' ]9 J
(command "zoom" "w" p171 p172)( G7 {: T! x+ i l1 @
(if (> numt 101)
9 q3 t6 e2 C2 @: s$ f (command "extend" pL1 "" p16 "") % M) b7 e" e( P9 H
(command "extend" pL1 "" p17 ""))
: p9 f: V. x) i8 h# Y (setq ang0 (/ (* ang0 180) pi))' ]" }8 I: H5 e
(command "rotate" arc4 "" p2 ang0)8 G/ S; q8 w4 ]
(command "zoom" "w" p181 p182)+ ? C- I e; l
(command "extend" L2 "" p18 "")
! r' ?3 i7 x# D% p; y (command "zoom" "w" pz1 pz2)
* x% O5 g1 E/ ` (command "trim" arc4 "" p5 "")5 G- m5 l* y* C# L! C6 `
(command "erase" pl1 "")$ Y) e0 l% h% M' T
(command "mirror" L2 "" p2 p12 "")
) I5 Q& N" A/ @; c" v ) ;end progn+ L7 c# d3 _$ ]4 m+ w" B
) ;end if
( z/ S* `: f; B3 } ) ;end progn- `: e0 Y% R; r2 z+ F- f* f
(progn
" x" s0 Q4 _7 D0 q* w3 M- G2 [ (setq ang12 (- (/ pi 2) (angle p2 p12)))
' V" g9 u+ ^. ~+ @2 W: x, I5 K (setq ang57 (atan (/ r1 h)))
4 o7 M m: p+ R (setq ang58 (- ang0 (* ang12 2) (* ang57 2)))
; `8 Z) h q5 B \2 p+ | (setq ang577 (+ (/ pi 2) ang57))0 f" \6 G$ q4 V# H9 |" O; h
(setq ang588 (+ ang577 ang58))9 A9 B9 }$ @5 P
(setq p57 (polar p2 ang577 (+ r1 r0)))
/ k( H0 c! x5 @ (setq p577 (polar p2 ang577 r0)) n7 D8 @) V6 O; O3 N) [4 @
(setq p588 (polar p2 ang588 r0))
: I" q4 e! F! K5 r5 t. g2 ^. E4 U (setq p56 (list x2 (+ y2 h)))
* M: p: L! ]/ K1 H$ [+ [ (command "arc" p577 "c" p57 p56)5 t7 D. D6 f4 y0 O
(setq arc1 (entlast))
6 ], @: C, _% J$ E7 G6 @2 D8 b; @5 o& B( y (command "arc" p577 "c" p2 p588)
- E( } L! V3 Y) z" _, h; l (setq arc2 (entlast))1 z2 _* E4 {+ L5 ~; A6 b! _
(command "line" p56 p5 "")4 ^/ Q: m/ l% j# L4 O# P
(setq L33 (entlast)); x" a. a8 D$ \% {' G
(command "zoom" "w" p77 p88)
. m- o7 [" N/ `0 A1 { (command "mirror" arc1 arc2 L2 L33 "" p2 p12 "")
. m" U9 ^0 @& k* Y (command "erase" arc2 "")5 y) b, }; V8 k/ K
) ;end progn ) x, |9 T: A" [ g/ {
) ;end if
0 [& j( J8 V' K5 A& \ V$ b;
2 f. q: L* \4 ] p (setq beta (angle p2 p3))
2 c, {0 z% a L: p+ Z8 e5 V (setq ang2 (- (* angi 2) beta))
0 \# F4 B; y; l& ? (setq p15 (polar p2 ang2 orad))6 K2 t8 e1 l) R' \( x
(command "arc" p15 "c" p2 p3)
0 E7 a9 c. R5 A- | (while (setq le (entnext le))1 }1 D) r. g9 `8 X% U
(ssadd le s)7 ?# n- P% ~; Z
); G4 l% W( T" E: E
(command "array" s "" "p" p2 numt "" "")
. e" ?, U9 z: [9 N/ S (setq q1 (nth 0 p2))
/ M# s+ X8 @# \5 y( U/ z$ U (setq q2 (nth 1 p2))
! p/ _# _! W, g' {& ^3 { (setq q5 (+ q1 pitr 2))" W5 X8 ~# ?8 h' k# r4 o" \
(setq q6 (- q2 pitr 2))2 H2 B/ B9 j1 h; [9 s! I' J
(setq q3 (- q1 pitr 2))( ~& F( ^1 n& J7 m: |4 i, u
(setq q4 (+ q2 pitr 2))3 @" W ^; `! m# ^' y4 ~! X
(setq q1 (list q5 q6))
/ w: K8 `* O5 R2 D6 E4 \" m$ C+ q (setq q2 (list q3 q4))
8 H$ d1 l% f3 Z l+ y (command "zoom" "w" q1 q2). \$ J" I7 U0 i
)7 I0 V/ O, b6 Q8 ?
)
$ j& U5 s$ p- ~% Z, y& n7 H5 a1 V; L (setvar "pickbox" 5)
0 @0 c/ J! ^2 k) x (setvar "aperture" 5)
, X6 B, X, Q: Q: ^* E, L (setvar "osmode" 37)' d( K7 {$ V6 ?: J# p, J
3 a; c: M$ `( `% }9 r8 m0 m
(princ "Finish gear ")4 S7 i2 m z8 e$ a6 o+ e
(princ numt), L o* H. m5 A" i$ @8 b
(princ "T")$ q& t$ b0 W+ G! V8 s5 h* g) ~
(princ)
3 d5 J% c { y- h )
5 f7 o- u. s3 V- r9 K. ^) O- r. l( j/ ~# D p* X7 b/ @" |6 G# i
|