(defun C:gear ()
5 ^+ D+ z/ g( f (setq numt nil
3 A% t" R" b* n9 A: t9 | diap nil
% [" o0 G" q4 \ prsa nil! L9 H7 v. S0 \7 x+ ~
pnts nil
- Q# F/ X+ B% G5 C test nil' c0 b: _* b) F* S y
pwd nil
, E. m6 W; q4 I i3 h$ u/ c )3 \6 |; m9 D0 a
, A; o) O5 k; B1 r (setq numt (getint "Number of teeth:<24>"))
3 }3 I, b. U8 ? (if (= numt nil)5 A; _4 q q2 N" L
(setq numt 24)5 G: s6 e8 g) ?* n6 o' Y# T
)
5 x. C( e+ C1 h: S% y& m! n! Z2 ^ (setq diap (getreal "Modulus of gear:<0.5> "))3 P2 h$ u6 \# J# x6 I- I
(if (= diap nil)4 S6 k& [3 x, u2 ?; {, h+ ?
(setq diap (/ 1 0.5))
9 w: {* @# H% u+ }+ i0 s/ d' n (setq diap (/ 1 diap))/ L/ D% u/ k# X1 O0 g1 p& T# v( X
)2 z8 N8 L" @( a' j- A, f* k
(setq prsa (getreal "Pressure angle:<20.0> "))
5 F) J. @/ A+ y( q C8 d% P (if (= prsa nil)
/ e% m v ], ^3 s (setq prsa 20.0)! p" C) R* d( j" K3 x6 [
) { j/ t9 p. A6 k1 ~. h
(setq pnts (getint "number of points on curve:<40> ")); L; L. _# {* ?* v; e
(if (= pnts nil)
+ q0 l0 M! b3 _! H7 T0 H (setq pnts 40)
0 ]" I2 z: `5 \ )( }7 d$ r" ~, w; ]) w0 A0 e
. C; e- o# X0 f9 A
; (setq pwd (getreal "Please input password:"))
6 V8 G s4 w9 h% {5 p ~6 C; (if (/= pwd 8833)
& \# P% s9 {$ j S) x5 \: N; (setq numt 0), ?, p4 Q! C! K; o* M9 o4 q
; )
( R, d8 t9 s) G: e. l/ r# h8 L; (if (= pwd nil)0 {1 R7 g8 |% z+ |7 M; R3 Y Y
; (setq numt 0)- ?6 |5 {7 E& h# T
; )
# M& `+ L1 d- q4 u. s! u;
5 h, t1 X* y' q6 i# D) ^% h (command "osnap" "non")* A" z) E" l7 }! \1 Z) {
(setvar "cmdecho" 0)
' K6 ]& z* c: ]5 ?' I4 _% Y3 Q8 n (setq oldvar (getvar "pickbox")): M! t% J3 N$ w6 n# U
(setvar "pickbox" 0), {- G$ O0 [7 e9 V4 r
(setvar "aperture" 1): S* q" O: j! }6 W: k6 {
(command "osmode" "0" )
& D1 w0 s- y: T* _) Q T;) d5 ]3 t. P7 X/ m9 l9 W, ^
(setq prsa (/ (* prsa pi) 180.0))
$ k8 n) A: d% G) D (setq pitd (/ numt diap))
' T% E$ w" |/ J9 ~1 h; Z (setq outd (/ (+ numt 2) diap))
7 }7 O- B! U) j (setq basr (/ (* pitd (cos prsa)) 2)) S. Y/ H: \3 M5 W3 Q3 ]+ a
(setq orad (/ outd 2.0)): Y& g5 `/ k& O& ~
(setq z (- (expt orad 2.0) (expt basr 2.0)))$ ~- v( K/ e* r
(setq x (sqrt z))* ?$ K; y/ A, M+ @! W7 s3 D+ V
(setq paodd (atan (/ x basr)))9 O$ C0 x& |" A: `, _2 M
(setq incr (/ paodd pnts))
& [- v& O* D! _# [: z+ m (setq p 0.0)
! \# n: H" S1 ? (setq pitr (/ pitd 2.0)) A' [6 F( N7 y+ u
(setq pang (/ 360. (* numt 4.0)))
9 z) _9 L4 u+ v% _, H; B (setq pang (/ (* pang pi) 180.0))6 n" n5 T9 ~# d3 b8 m0 R$ v Y9 u0 v
(graphscr)
5 P1 ^% F! H# |5 R" ^ (setq p2 (getpoint "center of gear:"))% \: W4 l% x# v* M# Y
(setq y2 (cadr p2))
% ^- w/ t$ K4 D) X* a: z. l; A. L1 Z (setq x2 (car p2))
4 Y$ [) a4 w& j8 `. l" Y' {& A (setq r0 (/ (/ (- numt 2.5) diap) 2))
. J) H/ `; c( G: s (setq r1 (/ 0.2 diap))' A- G' t- m' N/ {
(setq h (sqrt (- (* (+ r1 r0) (+ r1 r0)) (* r1 r1))))
' [* k1 F9 P S8 `$ e% Z# I& H (setq ang0 (/ (* pi 2) numt))+ F" H# R9 R% R7 a9 ] P8 n7 J9 G
. [0 x* ?, [: u( U) R
(setq y5 (+ y2 basr))9 N5 [4 q0 H/ W; @7 b
(setq p5 (list x2 y5))% M, u* K- c# O2 s5 D5 ]
(setq y55 (+ y2 r0))
4 G2 q+ M# r6 V& D4 _ (setq p55 (list x2 y55))4 E; h9 b# Y, I
(setq p88 (list (+ x2 2) (+ y5 2)))
) i1 V0 Z8 A0 \" B: T2 W/ k (setq a3 (/ (* pi 5) 4))" \& u! F4 h: }9 ?! Y" { {
(setq a4 (/ pi 4))" U% t% N* |1 n5 }3 o
(setq pz3 (polar p2 a3 (* orad 1.5)))& U9 P6 z# f1 `) P1 U: k/ K( Y
(setq pz4 (polar p2 a4 (* orad 1.5)))
, ?0 O, \5 n m% g8 v0 V (command "zoom" "w" pz3 pz4)
! P" w. k. E2 J9 b* q; L9 w- n7 M;; q, \+ e* R2 H
(setq clay (getvar "CLAYER"))
7 b' N; ^4 D- T* \2 W P6 E/ L7 Q7 c0 Q (setq sblip (getvar "BLIPMODE"))6 ~0 i" b7 E0 j D/ E6 o
(setq ts (tblsearch "LAYER" "CEN"))$ q4 p$ L. f5 W+ F1 D, u- s, w/ | _
(if (null ts)
$ a2 |# V* P9 _, g0 n& N (progn8 L) Y: Q3 Y. @2 F
(prompt "\nCreating new layer - CEN. ")
: ^8 v7 }8 F2 P! r) y4 ? (setvar "BLIPMODE" 0) P2 Y8 I$ k" a/ [2 Y
(command "LAYER" "M" "CEN" "LT" "CENTER" "CEN" "C" "RED" "CEN" "")
. R' }6 W: y* ]5 A) O8 n )
1 k/ H3 O* k3 D5 M (progn
$ P$ c* z# U; {- R) A& T" L (if (> (cdr (assoc 70 ts)) 0) (command "LAYER" "T" "CEN" "ON" "CEN" "U" "CEN" ""))
* V6 `" @) @$ j9 y (command "LAYER" "S" "cen" "")
2 ], a7 H' K1 w! L- h" o9 A )! M7 `5 H& T/ ~4 z6 h
)7 ^2 n! O# i3 e
(command "circle" p2 pitr)) b& L, v% I' Z2 }# _% F
(setvar "BLIPMODE" sblip)
. `! j4 B5 l2 G% u: b _ (command "LAYER" "S" clay ""); |; T& j+ M# ] z% R/ W# | J5 Q
;
# X1 \. K4 F# b) @( ^8 X (setq a1 (- (/ pi 2 ) 0.1))) W0 @' }( N; R$ Q5 T4 B. y5 f
(setq a2 (+ (/ pi 2) 0.1)). s5 Q0 F; f! q: k. ^7 U$ J
(setq pz1 (polar p2 a1 basr))' Q- a6 H" n8 E( g5 p% ]
(setq pz2 (polar p2 a2 orad))1 i2 _ N0 \( z& L0 ^& }& `+ A
(command "zoom" "w" pz1 pz2). m/ b* `7 h9 r7 y* j5 K
(setq s (ssadd))
/ J& y4 m$ _' ^& G (setq le (entlast))! s+ g0 b( w+ t7 l
(setq test 0)
9 L" c7 q4 o4 {" [& v: f" e5 n% X3 j2 m3 p, f( D
(command "pline" p5)
# T% r( j, ?, j$ Z+ |& j (setq p (+ incr p ))
% b/ D9 A3 K8 i% D (while (> pnts 0)3 X% B3 ]. J8 Y \2 u
(setq e1 (sin p))3 b7 Y1 ~) F7 y" i! F- h0 |$ \: I
(setq e2 (cos p))
& Q H* T" }: a (setq e (/ e1 e2))' K" g u: ~/ ]/ ^
(setq j (- e p))0 S6 F( D+ o# U3 ^
(setq x1 (* (/ (sin j) (cos p)) basr))
0 N6 M/ L% w W, x7 {; _ (setq y1 (* (/ (cos j) (cos p)) basr))5 D- S3 r( ~9 k% ~' f
(setq x3 (+ x2 x1))
! O' [ e) h- {7 x9 o* c (setq y3 (+ y2 y1))+ g7 H! s& N) b$ B4 T! m8 F
(setq p3 (list x3 y3))
7 P+ x' f( N1 d, O! Z (command p3)7 e1 K4 X& |+ g$ T& [( f
(setq p (+ incr p))
9 ?5 Z! h2 {, m* q0 I8 U (setq pnts (- pnts 1))
& I4 u# { X) q$ k2 O( u (if (/= test 1)( I. Y% h; F+ I# V: a
(progn
: f$ h3 [) s6 H) A/ u( m* D (setq hyp (sqrt (+ (expt x1 2) (expt y1 2))))% W: Q, q1 L' w
(if (> hyp pitr)
6 W/ C* j3 i \& n0 j: Y( d; _5 J (progn( d) g" U7 t/ P) l
(setq pint p3)
9 _4 x7 [5 h3 W8 Y6 c( y! A$ Q$ G* \ (setq test 1)
5 ]2 d. N' V6 T3 V4 e: D+ R$ j ). I# b5 L# W7 W1 H# q9 C- B3 Q
)
3 a1 R; q/ v. t% ]5 c& A( p );endif3 L" o. F- W, B) o* p& I3 U4 ]
);endif
. G( D: c' d9 i+ N$ X )
3 ?$ E% _9 X% ~; B% P4 ^% \" ], J (command "")
7 \1 d. h/ a; {) g) x3 Z (setq L2 (ssget "L"))+ p$ a) @: P- }6 J
(initget "Y y N n")
2 T5 m% ^9 M0 J' Q (setq ans (getkword "\n Finish the gear ?:<Y> "))* h' ~( ^ s6 G1 W# C: u
(if (/= ans "N")+ O+ P6 b3 [; h* U \1 v
(progn
. \& T, h1 z; j% c& g/ N7 E2 y (command "zoom" "w" pz1 pz2)
9 c9 m9 _' v7 w' C (setq p11 (osnap pint "inter"))
1 _/ d0 c" S& e$ w (setq ang (angle p2 p11))' h% f5 P( H+ M2 E
(setq angi (- ang pang))- C$ v s; y& J
(setq p12 (polar p2 angi 1.0))+ P2 ~9 A/ o! z6 f7 T5 R2 e# }
;
& i C9 B% Q5 X! P# b! j (if (< (* 0.94 numt (/ 1 diap)) (* h 2.0005))
+ O" ~: L0 ]' b0 l& G2 v (progn1 `/ i$ V% n- z+ v( g$ h s
(if (< numt 42)
6 w- b0 x( f0 T7 {+ G (progn4 T/ a7 B$ l5 o" }! U' w1 s" Z
(setq p56 (list x2 (+ y2 r0)))
' Q z' {$ }- T5 `- ?; H0 w (command "line" p56 p5 "")
1 j, c; h: A5 U6 v: H/ o! b (setq L33 (entlast))
4 d$ J ^* G: j8 n& Y! r (command "zoom" "w" p77 p88)0 e* L1 x7 L; z, X) f8 @' E
(command "mirror" L2 L33 "" p2 p12 "")2 L% _) a; ` S
(setq adj1 (- angi (/ pi 2)))- |" k, k# E8 |" }( }& W
(setq adj2 (- (/ pi 2)(* pang 4)))
& Z5 C% N; v7 x. o7 q* s (setq p17 (polar p2 (+ angi adj1) r0))) S" J9 Q2 q: E+ S4 l7 [
(setq p16 (polar p2 adj2 r0))3 S9 I% n2 v0 i
(command "arc" p16 "c" p2 p17)7 p1 L" d+ I+ [3 ~
) ;end progn
7 s" L4 w( }6 n (progn1 h$ r- t9 ?2 u5 {& u4 v0 A! V/ a
(command "zoom" "w" p77 p88)
3 |" m+ a) G+ f! u3 J+ O. @ (command "mirror" L2 "" p2 p12 "")
: V3 i( B0 Q% m (setq pL1 (entlast))
* l7 U! H" c; r( | (setq adj1 (- angi (/ pi 2)))+ W; H, Q2 ?5 J- p
(setq adj2 (- (/ pi 2)(* pang 4)))
7 r2 |: a" W- C( S/ k5 y x# ] (setq p17 (polar p2 (+ angi adj1) r0))
* w, x: P2 F+ @9 K& c, F (setq p16 (polar p2 adj2 r0))' o* v5 K$ F/ _1 u
(if (> numt 101)8 u; t* }1 B( H: l+ Y" ?" ]
(command "arc" p17 "c" p2 p16)& t2 `* f: z$ `
(command "arc" p16 "c" p2 p17))
: ?# u8 n* ?, A& W (setq arc4 (entlast))0 e# u, g- l: d( ^
(setq p171 (polar p17 0.7854 (/ 0.4 diap)))
" l' O4 ?, ]! F7 t2 E2 x (setq p172 (polar p17 3.9 (/ 0.4 diap)))
, o5 J' D5 E+ Y4 ^ (if (> numt 101)
8 q( Z5 p O0 a% q1 K$ f (setq p18 (polar p2 (+ angi adj1 ang0) r0))7 r+ M6 s5 _+ M6 y: x( c6 c! z9 b
(setq p18 (polar p2 (+ adj2 ang0) r0)))
& u2 |7 N, @* Q! S$ n (setq p181 (polar p18 2.3 (/ 0.4 diap)))
0 C4 Q+ F( D2 z$ l (setq p182 (polar p18 5.5 (/ 0.4 diap)))- H* M: Q9 F: Y+ e
(command "zoom" "w" p171 p172)
8 i) p2 s, L( j* Q% ]' C- n9 k7 w (if (> numt 101), J" G# w1 F3 Q
(command "extend" pL1 "" p16 "")
. M3 |9 }9 i! S) l8 X0 B. \ (command "extend" pL1 "" p17 ""))/ E; D* ]# V0 F- ]
(setq ang0 (/ (* ang0 180) pi))
' P1 X( u9 D% y- E @4 M (command "rotate" arc4 "" p2 ang0)
% p- S! \& w& w# U( U8 @* \ (command "zoom" "w" p181 p182)6 S# K; k0 r/ C, k! W2 Y
(command "extend" L2 "" p18 "")
3 [% p4 z( |9 f0 N0 N) g( g (command "zoom" "w" pz1 pz2)% U# }+ Q% C* ~
(command "trim" arc4 "" p5 "")$ Z' ?+ J2 b1 i0 i# {' g# }, ^% v# ^
(command "erase" pl1 "")
! t) {( B3 V3 Z& z3 W( Y. l* h (command "mirror" L2 "" p2 p12 "")" p3 k: u: x# D. v1 Q& Q7 @1 i
) ;end progn) b/ P& ?0 R7 v2 T# b# _! A6 R' f
) ;end if
+ \# [' ~* d2 w1 |( |7 p$ C; A ) ;end progn5 R# ~" g9 }+ N4 D6 v
(progn - b& S+ M' P" o* ] ?( u! J
(setq ang12 (- (/ pi 2) (angle p2 p12))) 2 s; k! `5 u" h% g
(setq ang57 (atan (/ r1 h)))3 e1 U: b% N# o" e& Y- W; l9 |- N
(setq ang58 (- ang0 (* ang12 2) (* ang57 2)))1 ]. G8 ?2 C& L4 v% h
(setq ang577 (+ (/ pi 2) ang57))
3 S2 G. \5 D* Y: w9 B, @ (setq ang588 (+ ang577 ang58)); A. K$ K4 s- N; i _
(setq p57 (polar p2 ang577 (+ r1 r0)))
/ g( i" A7 {% l- u0 B (setq p577 (polar p2 ang577 r0)); x- L* F! S- D6 D
(setq p588 (polar p2 ang588 r0))
7 ]6 K3 t) Y1 ]8 ` (setq p56 (list x2 (+ y2 h)))* b" Y! I+ s. B2 g1 |9 }
(command "arc" p577 "c" p57 p56)% i. y/ w( p O! ^# s
(setq arc1 (entlast))
( c" R% f# e, X* N4 N' I7 v# t8 N (command "arc" p577 "c" p2 p588)
: F. ] v% ]' F+ r* y (setq arc2 (entlast))
% i" l4 h9 d7 K @' e2 I& K6 B" Y' P (command "line" p56 p5 "")
- Y5 e0 n6 l( ~; }* c (setq L33 (entlast))
, ~9 _) S6 h$ ~6 O( ]" ] (command "zoom" "w" p77 p88)% X+ l/ E( V3 @- [7 O6 z
(command "mirror" arc1 arc2 L2 L33 "" p2 p12 "")
3 @( ^6 I/ r1 ^" ?8 w (command "erase" arc2 "")/ K7 S2 S+ k) e$ j2 q6 g
) ;end progn
$ }0 Y/ T. l4 Q! t9 P, o ) ;end if2 z3 n& v$ n( {+ b' f" T
;
0 F R2 M% o, j2 `. n) G$ o# @9 U* E (setq beta (angle p2 p3))" y5 i! j r/ F2 |
(setq ang2 (- (* angi 2) beta))
$ V0 c& F- g/ Z6 p/ }$ R* W (setq p15 (polar p2 ang2 orad))
8 G( Y% D: i @& |. M" g$ \ (command "arc" p15 "c" p2 p3). J# t) ~% V* i! W
(while (setq le (entnext le))9 r+ G+ @& C1 h _
(ssadd le s)
/ a0 r, ~9 x2 @: a )
6 E+ B- Y9 ]$ K2 A (command "array" s "" "p" p2 numt "" "")
9 `9 y) x! Q4 t2 D2 [$ H (setq q1 (nth 0 p2))
- O& @7 f# M+ P% W (setq q2 (nth 1 p2)) y6 q/ t: T( T4 G4 z8 U
(setq q5 (+ q1 pitr 2))% [, G: E# m: W, X; M9 d- x/ y
(setq q6 (- q2 pitr 2))+ j, x# h, p5 h, }( f
(setq q3 (- q1 pitr 2))7 l" I8 y# |0 B9 P* {
(setq q4 (+ q2 pitr 2))
, d; n2 d* |3 K8 K. O) C (setq q1 (list q5 q6))" v: a4 @- K3 A+ F/ [4 n
(setq q2 (list q3 q4))
/ Y- t l$ a. ? E (command "zoom" "w" q1 q2)
2 e! n$ E7 l; R. A) ?& ?0 p2 J1 ] )6 a) `2 B7 f" t
)
5 a9 r6 b7 c+ v/ I) `7 V" G V (setvar "pickbox" 5)- R$ \; m* w) y8 u' h: L
(setvar "aperture" 5)" F* H9 o( |8 M* K. Q9 @" U
(setvar "osmode" 37)
+ k. d- l; y! g
" x, P2 }7 \/ U9 N: d, w (princ "Finish gear ")
: w$ R6 i& `. g& i (princ numt)
1 _+ O5 o/ W# O* q O7 y6 d (princ "T")' i4 ?3 t$ M$ H' K+ S7 L
(princ)9 \; _& y9 z* l
)
$ ?0 ]6 |. ^2 L) K: n* J$ w5 u v: |/ Q: b
|