(defun C:gear ()
5 ?! o2 e! ~2 h (setq numt nil
+ I5 b V( [: U3 M" Z* e diap nil " N0 d6 \+ |, Q
prsa nil3 c" f: @, ~3 g1 C
pnts nil! q8 p- G- f0 s5 E
test nil
! N: D& P" o3 [' I. ~% f+ _4 z4 X# J pwd nil1 g' G, D3 H! \0 A. J2 P
)
: Z2 k9 t" r: m: _5 ]) C+ _ : T) m( G" \+ x
(setq numt (getint "Number of teeth:<24>"))
# ]+ S3 o: P4 |4 e) N7 z" e (if (= numt nil)
a- i2 \1 I; g+ S0 o; Y: r6 E (setq numt 24)2 G5 z& `" N; c7 t3 H. z4 I8 i
)) ?; z- C/ d+ {9 J9 }/ ^- a/ d
(setq diap (getreal "Modulus of gear:<0.5> "))
. k& `& `" s$ A (if (= diap nil)
: B: }' Q q. v5 I- V (setq diap (/ 1 0.5))
) k* M: v9 P8 m2 u& E (setq diap (/ 1 diap))0 a: ~0 G+ p1 X% e4 b
)
9 j+ ?3 q! f$ V. H# u; |3 d (setq prsa (getreal "Pressure angle:<20.0> "))+ y+ i9 X5 O `4 l/ [/ b8 p6 M
(if (= prsa nil) B+ u3 L# w! g& |! t7 w8 p* k
(setq prsa 20.0)
- F# a: `' z* d )
- R: I& }0 C6 P8 \! d (setq pnts (getint "number of points on curve:<40> "))
2 \& j3 _- M0 c! c3 F. m5 v# |: j; M (if (= pnts nil) C% B* @4 o" ?7 ^* k1 z1 {
(setq pnts 40)
9 K* `! U0 m5 L! t! h7 t- a )2 C; B% ?" h. D5 M- [! {
; Z* l% _" S6 D ` ~ n; (setq pwd (getreal "Please input password:"))
% M6 B; G3 r( }8 W3 ]; (if (/= pwd 8833)
/ ~0 o* I8 c2 S5 S2 }; (setq numt 0)# @9 y( `! H& H4 J/ x: d
; )
' d; c0 E- F1 A6 ~; (if (= pwd nil)7 o* t8 L0 G0 m, Z) x, \; S
; (setq numt 0), \* }$ a/ E: A ?- L9 `/ I. X5 }
; )
6 Q" N2 R) P- R4 A0 e1 }/ |;3 ~6 W# U, S' E/ P; L* ^
(command "osnap" "non")$ V9 l: [" ~4 F
(setvar "cmdecho" 0)) d$ n0 ?( l5 M' V$ S8 H
(setq oldvar (getvar "pickbox"))( ]! K) W- V d% B" ?& m
(setvar "pickbox" 0)3 B1 u% W7 x) y8 L
(setvar "aperture" 1)7 U% x( H$ P' Z
(command "osmode" "0" )
1 ?) z) e+ c w;# c c/ T! x4 m
(setq prsa (/ (* prsa pi) 180.0))
- Y2 J( ~8 H6 H& h( } (setq pitd (/ numt diap))3 E" T5 t+ y$ M) h v, N
(setq outd (/ (+ numt 2) diap))
9 e6 h6 ]* @- G0 g2 z8 F' Q, Q (setq basr (/ (* pitd (cos prsa)) 2))
' K& N8 v8 q3 y0 w' N$ e1 W4 J (setq orad (/ outd 2.0))2 T" Z8 Y/ q' ^4 Q4 n
(setq z (- (expt orad 2.0) (expt basr 2.0)))1 v7 Q+ x4 t# @9 B' \
(setq x (sqrt z))( |6 v: @' r2 U
(setq paodd (atan (/ x basr)))
4 k2 Q& _( O, I5 Z (setq incr (/ paodd pnts))
; V% O4 u+ j# _6 K+ D- R (setq p 0.0)) L! M, v/ }' }+ B. e8 y
(setq pitr (/ pitd 2.0))' S2 L7 ~9 ~0 M" y1 I, ?5 X% x
(setq pang (/ 360. (* numt 4.0)))" V' w1 S, ^; f' f
(setq pang (/ (* pang pi) 180.0))
u5 L/ }/ L' f$ E; B8 p. l (graphscr)( {9 J* l; z: A. x2 _
(setq p2 (getpoint "center of gear:"))( W/ B1 Q! I) i y" I
(setq y2 (cadr p2))
3 m* D7 @1 x( A+ t9 Z (setq x2 (car p2))2 v0 ~/ c7 i0 [! n
(setq r0 (/ (/ (- numt 2.5) diap) 2))% p* \( ~9 r6 }% p2 c/ d# M$ L
(setq r1 (/ 0.2 diap))$ X+ f5 }% O5 l& o/ e
(setq h (sqrt (- (* (+ r1 r0) (+ r1 r0)) (* r1 r1))))
' Q* o, A& F: ^( y4 N (setq ang0 (/ (* pi 2) numt))
7 v5 t% v0 N; d- {4 ~6 A5 V
) ]* G ]6 P C! R) v: q (setq y5 (+ y2 basr))! U G' s5 O6 a
(setq p5 (list x2 y5))
6 f/ d! Q5 O$ ~& o+ J& L, } (setq y55 (+ y2 r0))
7 S2 S. M: w$ i) K0 o; z1 Q I8 f- x (setq p55 (list x2 y55))7 h6 ]: m- c* z5 D: L1 i
(setq p88 (list (+ x2 2) (+ y5 2))) H, l+ [ q. {0 ]" s
(setq a3 (/ (* pi 5) 4))5 o0 u9 M0 q& G K/ D4 A
(setq a4 (/ pi 4))* Z! G1 C6 t9 d2 w8 D9 o
(setq pz3 (polar p2 a3 (* orad 1.5))), z+ ]3 ?0 Q& V9 N
(setq pz4 (polar p2 a4 (* orad 1.5)))/ L4 J$ C+ D6 W, k3 H
(command "zoom" "w" pz3 pz4)8 k- G7 z6 R+ p4 v
;% H( w& [) a7 }
(setq clay (getvar "CLAYER")): Y2 v. ~) L" D$ n0 u
(setq sblip (getvar "BLIPMODE"))
* `+ [- R, o6 J4 H0 l (setq ts (tblsearch "LAYER" "CEN"))) g9 j: L9 r1 r! ~
(if (null ts)
& ? s! z X, a2 I. A3 ^ (progn% W% A0 U% O& X* ~! J
(prompt "\nCreating new layer - CEN. ") . b# t; W; T4 l- Q; p
(setvar "BLIPMODE" 0)
; L' o# L* ^1 Q) d( P+ ]; b8 e (command "LAYER" "M" "CEN" "LT" "CENTER" "CEN" "C" "RED" "CEN" "")
! V8 u1 A% ?# q* B6 F: M [. L )5 s. ^9 [" M9 y4 u p1 T8 j0 G E
(progn: o2 t, Z5 H9 y0 V# n6 L
(if (> (cdr (assoc 70 ts)) 0) (command "LAYER" "T" "CEN" "ON" "CEN" "U" "CEN" ""))
+ Q& z% U2 q. m3 |9 K- s2 k (command "LAYER" "S" "cen" "")
% l7 Y/ y2 c5 J: M: A2 J; s: B )
7 t( X6 a6 R/ ] )' ?5 c) q1 M+ z3 w2 i; I& t6 x
(command "circle" p2 pitr)
" R& W' m( v, v (setvar "BLIPMODE" sblip) `9 I. Z) Z6 u( f/ c
(command "LAYER" "S" clay "")
3 C& O- r" I5 W3 @3 \( ?0 h* H( _;- s; `& Q( r0 ?+ V
(setq a1 (- (/ pi 2 ) 0.1))
" T" q6 u/ Q" q! ? (setq a2 (+ (/ pi 2) 0.1))8 }* U# `9 a. {! T- i( G/ ?
(setq pz1 (polar p2 a1 basr))6 _$ Z' [2 t- e C3 W: k
(setq pz2 (polar p2 a2 orad))
U$ t1 P; x6 ~ (command "zoom" "w" pz1 pz2)
* T) Z+ H* d; P$ }3 T6 ~9 m& E (setq s (ssadd))$ p& H9 h/ B" g0 e* ^% ~: i4 U
(setq le (entlast))3 T: K1 @" B H
(setq test 0)
Z5 |4 I8 Y1 ^
( n; a' Q+ q# C! a5 O+ ` (command "pline" p5)! v3 B" ]9 J9 |
(setq p (+ incr p ))# x8 ^. g4 n8 z' Y+ i) }; P( ~
(while (> pnts 0)* T# h; G' W; c5 a2 a* P
(setq e1 (sin p))& R1 A; d, \0 o& m. U5 P) t
(setq e2 (cos p))* @' ?4 T' F- U: {2 u5 t+ K
(setq e (/ e1 e2))
7 j+ P1 S1 v( G6 c. J (setq j (- e p))
9 z! | C- }" Z9 I: r# Z (setq x1 (* (/ (sin j) (cos p)) basr))1 l, ~+ M6 d3 T L; R( W: n
(setq y1 (* (/ (cos j) (cos p)) basr))
5 h) m3 b! Y" A3 R/ J# f' V (setq x3 (+ x2 x1))( I+ P4 D% ]' \
(setq y3 (+ y2 y1))- b& ], ~8 q/ a% F2 H
(setq p3 (list x3 y3))/ b9 f$ S. x: P# m
(command p3)+ a h2 ?* X; R z6 w0 B
(setq p (+ incr p))
6 K$ B6 }9 _& l W, @ (setq pnts (- pnts 1))
& r i, J8 q7 D5 j) j, N. X) x v( i- s (if (/= test 1)/ `, q( C. ?. Y% Q/ [& q
(progn' g" c( I3 ]' k* w
(setq hyp (sqrt (+ (expt x1 2) (expt y1 2))))! n6 J! z" p+ n0 r2 o
(if (> hyp pitr)1 V4 P5 |! f N1 X- p
(progn
6 x4 G) {3 i% e n (setq pint p3)4 O) S( [9 J/ n6 B7 Z5 d
(setq test 1)3 C# M* W* i6 h0 v: w0 M
)
" C7 i% g+ [. Q' J. H) S: K: R: d )
/ S+ Q; L9 t( `; X- N+ J );endif
! p9 T) q0 ~5 [4 y- `! k3 p, p );endif8 s2 S# B& J7 q' m9 _- a
)
5 p' f5 l( @6 L6 ^/ O1 \5 j9 [& d (command "")' {% G7 t% Q, t& K2 B8 `4 M
(setq L2 (ssget "L")). q/ Z& S- z: d3 y1 r i6 X: ~$ y
(initget "Y y N n")
6 v0 t8 ?+ J& a; p* Y& K8 v ` (setq ans (getkword "\n Finish the gear ?:<Y> "))/ M* L( {3 W, B& n1 u
(if (/= ans "N")& [* o$ e8 G. c; M! s2 F3 ^, G! q; f7 a
(progn8 s4 [) C; _! P$ W
(command "zoom" "w" pz1 pz2)
* l$ o& D* d {" `! v3 p8 I (setq p11 (osnap pint "inter"))7 u. [" M Z( }2 Q, F3 V ?7 m
(setq ang (angle p2 p11))
; b1 m' t3 H- z' m, Y! ^+ M( { (setq angi (- ang pang))
) q0 z5 e. V! H9 o (setq p12 (polar p2 angi 1.0))
$ W+ M& T6 |. u" p;4 S( n" y/ T: W+ U% G) M" H
(if (< (* 0.94 numt (/ 1 diap)) (* h 2.0005))% H# J& w5 m; r
(progn
% ]6 C7 \0 I+ x9 j: ~) ? (if (< numt 42)
$ w8 X f4 r" R! S0 d (progn1 I% s3 Z$ r: @, I* X3 `8 e0 ?7 u
(setq p56 (list x2 (+ y2 r0)))
9 Q' F! n. Y+ Q. H5 s/ C (command "line" p56 p5 "")* H2 X% k& \ c$ z: ]) g6 q
(setq L33 (entlast))
+ @% {1 w- r+ w' p% }0 W (command "zoom" "w" p77 p88)
; A8 t) V M* Y4 ]; {5 u* ]$ ~ (command "mirror" L2 L33 "" p2 p12 "")- V2 o6 X7 w. g" Q; E
(setq adj1 (- angi (/ pi 2)))
& Y8 n2 }4 ?3 [4 x1 B" [6 x (setq adj2 (- (/ pi 2)(* pang 4)))8 E, g2 X) d+ l" \! q
(setq p17 (polar p2 (+ angi adj1) r0))
8 x6 h3 M' K) ~( ^; r$ X4 M (setq p16 (polar p2 adj2 r0))9 x; ~/ w2 v& s
(command "arc" p16 "c" p2 p17)
2 j6 R; q s; L$ z4 d8 u ) ;end progn
# t, X" r1 [- u (progn5 u) ]& F4 M6 r9 g: Y4 L
(command "zoom" "w" p77 p88)2 `% D. A8 P& V! f" L
(command "mirror" L2 "" p2 p12 "")
& L ` h7 u3 o- N8 t (setq pL1 (entlast))
# ?/ Q3 Z' B# ]& T e (setq adj1 (- angi (/ pi 2)))
! W1 e" s( u( w% y' t+ Z (setq adj2 (- (/ pi 2)(* pang 4)))+ [4 s& t9 D0 s, ^: d C+ D1 j
(setq p17 (polar p2 (+ angi adj1) r0))' H4 ~' h6 m3 o, @
(setq p16 (polar p2 adj2 r0))# {/ J' ^7 p6 w, J6 |
(if (> numt 101)4 O, e8 b, ]( R) q
(command "arc" p17 "c" p2 p16)6 v# O' I, Z- q! w' L- j
(command "arc" p16 "c" p2 p17))
# | W' P) \6 y/ o' e# O (setq arc4 (entlast))
3 B2 @3 m4 r o. I0 U$ |: t0 y5 c* d (setq p171 (polar p17 0.7854 (/ 0.4 diap)))0 ]- t- n9 m: c* Q/ a: i
(setq p172 (polar p17 3.9 (/ 0.4 diap)))( s9 v% d+ c0 {
(if (> numt 101)
2 s* n4 Z" s3 N3 @- r3 T8 } (setq p18 (polar p2 (+ angi adj1 ang0) r0))
5 X7 Q2 @/ H Z (setq p18 (polar p2 (+ adj2 ang0) r0)))& Q2 w8 g3 o0 G# h* Z8 q$ S, m
(setq p181 (polar p18 2.3 (/ 0.4 diap)))6 J( q/ O1 [% O
(setq p182 (polar p18 5.5 (/ 0.4 diap))); _6 P) B" I$ l
(command "zoom" "w" p171 p172)+ I6 F) s' E+ l! K7 S9 n9 V5 N
(if (> numt 101)
) j/ U8 |. {+ X1 J (command "extend" pL1 "" p16 "") 3 [0 [' B! ` B' e; e6 c/ d% w- n
(command "extend" pL1 "" p17 "")), F# `+ V6 r" q, L6 V
(setq ang0 (/ (* ang0 180) pi))
% t: Q1 j8 P, I* m# R/ I& j! o! I- i/ c4 i* Y (command "rotate" arc4 "" p2 ang0)- H7 a# v. \# Q T" q. g) @
(command "zoom" "w" p181 p182)6 o* d: m, s5 g& D
(command "extend" L2 "" p18 "")9 p5 F" q& l* S, u2 Y
(command "zoom" "w" pz1 pz2)2 t, C7 \, t/ G( ?& B6 ]
(command "trim" arc4 "" p5 "")
6 T) y. \! r1 I (command "erase" pl1 "")! q4 r- H! Y* x* r
(command "mirror" L2 "" p2 p12 "")6 R& L' `. h6 p, m
) ;end progn
- D% F& p, \, M! Z8 G3 ~, b ) ;end if8 Q9 W2 B+ m7 _9 I* L
) ;end progn
$ m6 @6 ]$ _( A3 w$ X& U (progn
. H- j/ {: v, B% o% y (setq ang12 (- (/ pi 2) (angle p2 p12)))
) O9 _4 Y$ \- D: f+ r. ]! ^ (setq ang57 (atan (/ r1 h)))" m# t) G- D- O- b% q
(setq ang58 (- ang0 (* ang12 2) (* ang57 2)))
N* ^! U6 G1 L) i0 `$ f; v (setq ang577 (+ (/ pi 2) ang57))% F! H7 x0 T$ e
(setq ang588 (+ ang577 ang58))4 ]; n& G/ M. O M& E
(setq p57 (polar p2 ang577 (+ r1 r0)))9 K+ }9 m" }( M3 `
(setq p577 (polar p2 ang577 r0))& o2 j- \4 P4 m: S1 x: K, Q
(setq p588 (polar p2 ang588 r0)) 5 J0 X/ S7 ~0 i% R( U6 g5 n6 ?& a
(setq p56 (list x2 (+ y2 h)))
+ M2 L9 C) G: i0 [( D* g+ [; {2 m (command "arc" p577 "c" p57 p56)
u: z/ i7 j T1 _ (setq arc1 (entlast))/ A+ i8 n8 G6 u) L( e: d, m# o
(command "arc" p577 "c" p2 p588)
. k- a2 O9 i1 Z9 Z+ p1 B! U (setq arc2 (entlast))+ p! Y6 k( O7 ^! d# n- R2 @' O
(command "line" p56 p5 "")% w* f- b4 a0 V3 {( U2 [
(setq L33 (entlast))
. Q: f, u+ M0 r) U( q2 t (command "zoom" "w" p77 p88)
6 }* S4 b c. E- Y+ W% w (command "mirror" arc1 arc2 L2 L33 "" p2 p12 "")+ x" x) e; P7 X+ s% n" f( {# {- N
(command "erase" arc2 ""); U6 l3 `5 h E1 P6 Q
) ;end progn
r. ~. I" w6 A$ Q+ @( u, j ) ;end if" }$ h- g5 C' ~$ ~
; - E7 ~" A- H% \8 @) M/ A, F& t
(setq beta (angle p2 p3))/ Q; b# E' Y- Q
(setq ang2 (- (* angi 2) beta)): u: t- P) t: D, w0 v
(setq p15 (polar p2 ang2 orad))
: d' {( C& Y, e {0 p (command "arc" p15 "c" p2 p3)
z2 E- ?# j8 l2 [% k (while (setq le (entnext le))* f+ G8 e' m+ F& ^- o1 e/ o
(ssadd le s)
, C" z. V9 J% a: B0 \ )
" N, L$ ?7 w1 C* d3 |' A (command "array" s "" "p" p2 numt "" "")& R8 v: m- ]- ?. u
(setq q1 (nth 0 p2))
5 j' z" T* Q& @6 u, e1 I+ ~+ U (setq q2 (nth 1 p2))' Z( G* i% k" n2 ?1 L7 f
(setq q5 (+ q1 pitr 2))
- F& H7 g, v3 L6 i' ` (setq q6 (- q2 pitr 2)). [ B& L. t; p/ ]
(setq q3 (- q1 pitr 2))# {; r2 R7 }. d2 ~8 r% d( x* ^3 D
(setq q4 (+ q2 pitr 2))
6 m4 J9 Q$ X$ Z/ R4 a8 U; b1 D (setq q1 (list q5 q6))
6 N3 r9 k, g% L$ s, G (setq q2 (list q3 q4))
% ~0 ?) a( {0 m( U6 s8 I2 G; {% F (command "zoom" "w" q1 q2)4 p. `* L; X- E$ B& s% w1 M, Z
)% {, e) l) [+ ]( @
)
$ G7 B( ?0 T7 f Z8 i% g (setvar "pickbox" 5): Z8 }7 t2 l4 s& l+ g0 O7 i9 i
(setvar "aperture" 5)0 n, A$ b; j: _! J" _
(setvar "osmode" 37)
! S1 Q8 [, f: d% ?4 \ ( Y" M& }3 r' @4 {, ?5 _/ M
(princ "Finish gear ")3 R; V# m8 a. D5 S) t. {
(princ numt)
! ?; o* E4 @6 R: ?+ b' Y1 P (princ "T")
' _. p+ y: x1 | (princ)
5 O" x+ x) N) f0 R9 d. [0 U) Y& x$ m )
/ Q! m# C+ `" V1 d7 X0 |
5 H7 p/ z9 x# C- U1 S) y |