(defun C:gear ()
- R3 R: K, O2 X W5 _, S (setq numt nil6 a- e% @+ X, l% W
diap nil m1 Q: j1 ]$ h `
prsa nil# ]" @; o% }" U5 y. m8 e# @
pnts nil
: ]. M X9 c& }7 v test nil0 Z6 D8 E U& p+ M, H/ H( W
pwd nil
. k% |5 Y+ ]; z# T8 b )
# d" L$ z0 r* X8 D8 O u8 f# D
/ h& z" d! Y1 t; v/ j' `) H5 y (setq numt (getint "Number of teeth:<24>"))
' U, h; ]4 D. T; c t (if (= numt nil)
8 T4 s' J. H+ E; E- | (setq numt 24)
) l! d5 c- B& Y6 n )* t, G) g1 m' N. X1 F/ X, Z
(setq diap (getreal "Modulus of gear:<0.5> ")); w! C9 V/ M1 G
(if (= diap nil)/ R4 P% k# t- H
(setq diap (/ 1 0.5))5 d1 J" `8 m2 G" H# X q3 Y
(setq diap (/ 1 diap))
: `. K" d/ u O P6 j* g j: G/ H! k )
" k+ j, I0 Q1 S& ` (setq prsa (getreal "Pressure angle:<20.0> "))
$ B7 W, x. ?: w (if (= prsa nil)
: y" ~: K8 z/ @- Z; l (setq prsa 20.0)! W& V; ?% Y8 M* A5 m2 R" r
)
( I$ @6 ^) R$ j6 i) Z/ q1 h7 V6 ] (setq pnts (getint "number of points on curve:<40> "))+ ?4 h& A) _8 ]% M
(if (= pnts nil)' j; ]- g" M& p- F! U
(setq pnts 40)
8 H1 G9 G+ X: F x3 V" ~6 e5 @ )
( o0 z0 x" `/ L4 j3 v: U* Y( h
7 b# T* b1 Z! }% Y5 \/ d8 @) T; (setq pwd (getreal "Please input password:"))) j& ^4 U' Y. p; i$ O
; (if (/= pwd 8833)
8 @4 _7 ]! C5 k# K+ Y# j) V9 t; (setq numt 0)' B& r% Z5 f7 [6 j/ {! Z/ R
; )/ f! G9 D- A4 C) ?1 \
; (if (= pwd nil)8 _4 k$ |! r( G0 l
; (setq numt 0)5 l+ B& T: m( {- M! X
; )
8 C( j$ C; I4 n3 n) Y7 p;3 c3 \. q0 C+ m$ s6 W
(command "osnap" "non")( s; u' }5 P7 X8 L7 ~
(setvar "cmdecho" 0)
8 K& z f q# V- V (setq oldvar (getvar "pickbox"))
: `5 e! D$ J, ~# k (setvar "pickbox" 0)
2 C& e1 J4 F' Y, _* N (setvar "aperture" 1)4 Z) r- c$ V7 Z6 j
(command "osmode" "0" )
. m, E2 D. ]4 v2 [. Y, e;0 h' u( K% z! Y. q: D: e
(setq prsa (/ (* prsa pi) 180.0))- y0 Q0 p$ S/ g: h
(setq pitd (/ numt diap))! I+ ~3 R* |7 {
(setq outd (/ (+ numt 2) diap))
4 f3 q' B" D) Y5 A9 \% J; D) f; U (setq basr (/ (* pitd (cos prsa)) 2))
* C2 ^1 j( q& a, z& U; K6 g (setq orad (/ outd 2.0)), A/ L6 v3 Q9 p2 C
(setq z (- (expt orad 2.0) (expt basr 2.0))): t' h3 ^8 b, I4 F
(setq x (sqrt z))
1 F; E/ M) B, T% s) F9 h+ H9 ` (setq paodd (atan (/ x basr)))
5 W! V- a& G7 C* U8 r (setq incr (/ paodd pnts))
) p2 p) a1 s1 [ (setq p 0.0)* R4 N. k5 L. x. G1 [
(setq pitr (/ pitd 2.0))* C1 T8 R: ~& I* T2 [
(setq pang (/ 360. (* numt 4.0)))% f( m5 T+ I+ z! \9 v
(setq pang (/ (* pang pi) 180.0))
0 T# L2 H9 r6 k" f (graphscr)
4 q/ V) K& e d$ E$ | (setq p2 (getpoint "center of gear:"))& i% Z0 p. j1 u. M: _# f
(setq y2 (cadr p2))
* b2 O b: d3 K. z, _ (setq x2 (car p2))
) z% _ t: f: m1 h B5 y" | (setq r0 (/ (/ (- numt 2.5) diap) 2))7 Z9 f4 x) B( t2 w+ H
(setq r1 (/ 0.2 diap))+ E) w7 [$ \& [2 _. I# I
(setq h (sqrt (- (* (+ r1 r0) (+ r1 r0)) (* r1 r1))))
' Y. H; u5 l- V* p( Q! h, C (setq ang0 (/ (* pi 2) numt))
) r# n- s# y5 y6 w/ ^
( s+ {) w+ v( s; { (setq y5 (+ y2 basr))
* R- E; t- t2 ~: y0 Z( f (setq p5 (list x2 y5))* U% _4 z% v, W5 v7 h/ b" ~
(setq y55 (+ y2 r0))) I0 |4 Q, N; T$ H) C
(setq p55 (list x2 y55))" H) p, u! X! C* P" S. [% M8 L/ D& e
(setq p88 (list (+ x2 2) (+ y5 2)))
h$ ]8 v& Z0 e- d (setq a3 (/ (* pi 5) 4))7 D, |# M# i$ c* B% ?
(setq a4 (/ pi 4))$ }) s; J5 l7 {( {1 q
(setq pz3 (polar p2 a3 (* orad 1.5)))
& n' `: f' e n (setq pz4 (polar p2 a4 (* orad 1.5)))
0 A6 j0 Y# G* _7 \8 R7 W (command "zoom" "w" pz3 pz4)6 h2 U6 u- x' ^' \4 ~
;6 w8 x+ r. E9 A0 K
(setq clay (getvar "CLAYER"))
( N. p/ @" ]9 ^; J* C (setq sblip (getvar "BLIPMODE"))
7 \# C, i6 n) f (setq ts (tblsearch "LAYER" "CEN"))- k: j: c0 a# V8 C$ S( N! i- o
(if (null ts)
# u# d6 @0 } i, L (progn
$ M+ O. k7 n' B6 m* X1 M" A" s (prompt "\nCreating new layer - CEN. ") " m6 r( F8 ?9 M( N) m
(setvar "BLIPMODE" 0)3 Y9 ], y: W/ F( u
(command "LAYER" "M" "CEN" "LT" "CENTER" "CEN" "C" "RED" "CEN" "")
$ z( t9 m* R# n5 z: t% w; X" ? )
5 [2 W1 ~% O% q" g x/ L" J (progn% o8 J- L7 v% s5 ^; }
(if (> (cdr (assoc 70 ts)) 0) (command "LAYER" "T" "CEN" "ON" "CEN" "U" "CEN" ""))
8 D0 k' m t4 A3 { T- n9 W5 f (command "LAYER" "S" "cen" "")1 G$ Y+ |) \1 o& \0 D& P. K
)
8 \% e- Y# L) \ ) _4 M% i: |: N1 Y" K' s
(command "circle" p2 pitr)9 E$ T3 Q% m2 ]- H/ X+ l
(setvar "BLIPMODE" sblip)
' I2 R, Y& u# Q- J' l1 G (command "LAYER" "S" clay "")
) a6 @- T2 P5 x;# c) l2 n7 K* x5 r" I) A: n; `" h
(setq a1 (- (/ pi 2 ) 0.1))
$ T7 Q$ s( X0 t/ F8 `' | (setq a2 (+ (/ pi 2) 0.1))2 h6 G7 A; ]. N) O+ t+ Z
(setq pz1 (polar p2 a1 basr))1 Y. @0 K* g1 P* n3 q
(setq pz2 (polar p2 a2 orad))
4 A @0 z3 \' z0 [' G# \4 W (command "zoom" "w" pz1 pz2)$ {. p) @, \7 y" X" {8 Q
(setq s (ssadd)): h+ M3 D; t' n# ]0 C5 ^' M+ N
(setq le (entlast))6 z2 q& O! r9 i* n3 ?- W
(setq test 0)
_; w ?9 z6 k2 w3 M4 }/ v% U# C" z5 C5 ]8 W
(command "pline" p5)
8 n1 j8 |+ g' r% J, R$ @" z2 } (setq p (+ incr p ))5 f c6 c: \+ }
(while (> pnts 0)
: m' h2 U" [0 K: S1 N# o (setq e1 (sin p))
/ E* u4 m5 [% T/ M (setq e2 (cos p))
9 u" _" M' z8 H+ w7 J (setq e (/ e1 e2))
* K" _. b0 k# k% Z4 y! O (setq j (- e p))- G6 Q, T/ v- X9 ~
(setq x1 (* (/ (sin j) (cos p)) basr))- n# m/ A4 n0 ^4 ^- ~( h
(setq y1 (* (/ (cos j) (cos p)) basr))2 N1 ?& `( W. j& q
(setq x3 (+ x2 x1))
( G" ?5 }$ C$ T- K( [ (setq y3 (+ y2 y1))
/ \7 B5 n d, g2 N7 P4 X8 L% [ (setq p3 (list x3 y3))
. V) w0 X! @$ l3 z/ t1 y (command p3)3 C1 R2 l- K' z
(setq p (+ incr p))2 D3 I* M2 y; h' c
(setq pnts (- pnts 1))5 l+ I1 _' U, @
(if (/= test 1)# r8 [; M6 [' }# ~- z
(progn3 n: k4 I# P( e/ [' T
(setq hyp (sqrt (+ (expt x1 2) (expt y1 2))))
; W; Z! z" g; h! c& M: H (if (> hyp pitr). I. e+ U8 k. B3 G
(progn
; V! S3 h: T4 h8 @0 g (setq pint p3). ]' }, V0 U4 a3 l5 M2 c
(setq test 1)8 ^) d; h' R2 B$ o9 o1 B0 j
)7 b4 Z% y1 c! h0 q6 D8 e
)' e1 _' [+ q7 s
);endif. ]! q5 I8 N$ U, g
);endif
8 M& t, V1 P4 g8 L& o- E) Z- h )+ e" A& j6 L3 R+ f2 I/ H3 P
(command "")
% I# e- j5 M- L; C( }" | (setq L2 (ssget "L"))
5 }! G" t( @+ k- {- d (initget "Y y N n")
* s: A" d. N, u! w: U (setq ans (getkword "\n Finish the gear ?:<Y> "))
) U' e; D; O+ W6 m! Y) I4 X) @. u (if (/= ans "N")! O' e9 G$ x) J8 Q5 e, _: [
(progn
/ w6 h7 Z {* l4 v0 l9 ~0 N (command "zoom" "w" pz1 pz2)1 k$ d* |5 s9 u( m; \ S- {) y
(setq p11 (osnap pint "inter"))5 f+ F6 K% P, ]8 J7 W6 L ~9 S$ z1 c
(setq ang (angle p2 p11))
# ^4 ]/ z. T5 ]$ ?% s# Y0 ?! j6 X' M) l (setq angi (- ang pang))
4 Y/ x( n# E- b3 }2 s (setq p12 (polar p2 angi 1.0))" U$ f+ u' { s8 P% B: j5 l0 ~
;6 H$ _. g+ s3 g
(if (< (* 0.94 numt (/ 1 diap)) (* h 2.0005))6 q* H- q6 J. H( w* b# _; u3 F
(progn1 C# B/ ~: _5 G! ?
(if (< numt 42)
0 B5 n# K& `6 T% q' y7 g (progn
7 [, F, M" @# {$ K) C- M (setq p56 (list x2 (+ y2 r0))): D) J; F% p; g& i: n% P
(command "line" p56 p5 "")4 F! A3 }$ {1 i
(setq L33 (entlast))
- k% L2 i7 Y) b3 @ (command "zoom" "w" p77 p88)
' U' B$ U$ w2 r+ R | (command "mirror" L2 L33 "" p2 p12 "")8 z/ G0 o2 o3 Z) A/ X
(setq adj1 (- angi (/ pi 2)))- v$ a( f' M0 @
(setq adj2 (- (/ pi 2)(* pang 4)))
! J- F, J( t0 f K, `6 {, v2 [ (setq p17 (polar p2 (+ angi adj1) r0))2 `, l4 ]: F# n2 } M5 U% g
(setq p16 (polar p2 adj2 r0))$ X$ E+ q3 T" e
(command "arc" p16 "c" p2 p17)
; R4 g8 {, S8 @( Y) b2 Q ) ;end progn$ Q! }/ Z% h; i& e4 Z% _& J
(progn0 o' t" a5 W. V
(command "zoom" "w" p77 p88)
- C" v D& w6 K6 n2 [3 \ (command "mirror" L2 "" p2 p12 "")( j v# e0 K, h
(setq pL1 (entlast)) 3 r9 |& J4 P/ |( Z, S- y. v3 T6 ^
(setq adj1 (- angi (/ pi 2)))) q2 G# k% \" O% {7 W3 Y
(setq adj2 (- (/ pi 2)(* pang 4)))
v- d5 [, g/ m# b) b' m# r& Y (setq p17 (polar p2 (+ angi adj1) r0))
/ w3 ]) S8 ~1 k6 \% b (setq p16 (polar p2 adj2 r0))
/ C7 z1 ]" X* E2 ` (if (> numt 101)+ H( q! h& @. w+ y
(command "arc" p17 "c" p2 p16)
# E+ H7 i1 B' _ (command "arc" p16 "c" p2 p17))
L$ p9 w2 h- c) G) J (setq arc4 (entlast)); ]# j: M1 Y0 X. k2 N) Q, t
(setq p171 (polar p17 0.7854 (/ 0.4 diap)))
0 Y+ l: o9 I+ \ (setq p172 (polar p17 3.9 (/ 0.4 diap)))
5 K: ?7 E9 l9 d, K (if (> numt 101): c/ t0 h' N: h* f! K0 b1 ~, s
(setq p18 (polar p2 (+ angi adj1 ang0) r0))4 q w+ Q- \8 ^0 l2 [
(setq p18 (polar p2 (+ adj2 ang0) r0)))
& ~, _0 ?7 D$ _; F/ G1 ^3 F (setq p181 (polar p18 2.3 (/ 0.4 diap)))9 H3 f/ v, W& f9 c8 B- a: w, y
(setq p182 (polar p18 5.5 (/ 0.4 diap)))$ b5 I# Y; {$ D4 B5 {: T& b6 e' K
(command "zoom" "w" p171 p172)* n5 ~7 u/ ~* s; t7 {3 \9 o
(if (> numt 101); I+ r5 e- U) ^, \7 Y2 G
(command "extend" pL1 "" p16 "")
. g" m. @) H$ N- f (command "extend" pL1 "" p17 ""))
6 p/ J! M# X$ h) f5 y (setq ang0 (/ (* ang0 180) pi)): l9 v1 T0 N( ~ l( J
(command "rotate" arc4 "" p2 ang0)" \, V O+ y3 Q8 b2 B1 i
(command "zoom" "w" p181 p182)
( J4 B# x' V$ W8 R$ l (command "extend" L2 "" p18 "")
' t# o& H3 x! G2 o: n# e (command "zoom" "w" pz1 pz2)# W+ ?. a. B8 T. L! `
(command "trim" arc4 "" p5 "")( f' M9 o4 P0 X8 W2 z i
(command "erase" pl1 "")6 V1 O8 R" j& V% n
(command "mirror" L2 "" p2 p12 "")
- @* t" c+ {3 B: T) o ) ;end progn
' Q! ?2 W2 L! u; ^! y ) ;end if$ V% v* }7 X% l1 J" p
) ;end progn% j' B% U+ n+ q3 |0 ?* g
(progn ; z: b8 a0 m% u; o% \+ e
(setq ang12 (- (/ pi 2) (angle p2 p12))) 0 }6 L ^8 u$ u4 j/ W) t% K
(setq ang57 (atan (/ r1 h)))3 N1 |9 S* ~/ e; f% \
(setq ang58 (- ang0 (* ang12 2) (* ang57 2)))0 V5 S, m1 N+ K$ N
(setq ang577 (+ (/ pi 2) ang57))
: _6 b) T( D* v+ {6 a/ p N4 @ (setq ang588 (+ ang577 ang58)); k6 ^1 |, M/ ]6 S5 \5 h* r7 ~ ~
(setq p57 (polar p2 ang577 (+ r1 r0)))8 T* S/ u( S9 _
(setq p577 (polar p2 ang577 r0))9 v% z0 d M) u" {9 ?
(setq p588 (polar p2 ang588 r0)) ( }. g T6 Q5 \& V
(setq p56 (list x2 (+ y2 h)))1 R/ P9 W `" k) O; g
(command "arc" p577 "c" p57 p56)& E- s& j$ t9 L
(setq arc1 (entlast))) n9 s1 F: V8 p. v2 P# _
(command "arc" p577 "c" p2 p588)% x b% {; S* B2 u- k
(setq arc2 (entlast)) I# o6 A, ^8 n/ U! Z) O% A
(command "line" p56 p5 "")
1 G/ ^5 ~7 C5 [; O. E (setq L33 (entlast))7 P& E; u0 R: B% m" @
(command "zoom" "w" p77 p88)( S/ \" o5 |* U' q
(command "mirror" arc1 arc2 L2 L33 "" p2 p12 "")1 `, r; G+ f x2 }' J7 h. k) {( [4 g
(command "erase" arc2 "")
6 m- a& }/ t! }; M( ? ) ;end progn ! Z9 n/ l! X/ }
) ;end if
7 {1 H* c3 R! E& _; - u; [- q; s# n7 L8 N
(setq beta (angle p2 p3))
" j& _! }2 O5 R) y% ?; ?; o# u (setq ang2 (- (* angi 2) beta))
" {$ @: W4 I, P+ ]3 N+ I/ i" @ (setq p15 (polar p2 ang2 orad))/ P8 W1 F4 E9 p
(command "arc" p15 "c" p2 p3): C7 u* A7 `8 K) r& C! H8 A. O, L
(while (setq le (entnext le)); f, o+ x9 ?6 Q- g, Y
(ssadd le s)1 f3 J3 G2 Q+ p, m" i; Q1 e+ Z
)
, E* n6 s' D! Q (command "array" s "" "p" p2 numt "" "")
0 N% A$ W( M! w+ a (setq q1 (nth 0 p2)) H; B' }' R6 T, U) }
(setq q2 (nth 1 p2))
: Z; _, t$ d7 N- k6 ]# F (setq q5 (+ q1 pitr 2))
( v. J# ^9 h/ l" L8 U (setq q6 (- q2 pitr 2))" N% ]3 q0 `1 y2 E: V( Y
(setq q3 (- q1 pitr 2)) z- R! |2 i% F; f7 d
(setq q4 (+ q2 pitr 2))4 E+ i+ l: ?2 D( j5 w! c
(setq q1 (list q5 q6))
2 H j$ V- ^# a, g7 f! L+ I (setq q2 (list q3 q4))
: v2 {1 k7 k# a" C. i0 w, S (command "zoom" "w" q1 q2)
2 y+ ^; k5 O# s0 g' Z ); C/ i# R- ?8 w4 |% ]& z' Z
)( w9 n; y! f; M
(setvar "pickbox" 5)
, K6 L* p( L0 g9 s (setvar "aperture" 5)+ H: h/ B# ]( M. F. t
(setvar "osmode" 37)
3 z& }, a6 H+ C: y! \) o
$ L7 M3 q% l. g/ Z2 `4 u (princ "Finish gear "). {/ b6 z' V- s& P0 I3 b% n
(princ numt)0 i/ n c$ A! {$ o
(princ "T"): @( x5 T, L% c( O
(princ)
4 j- x! T: q) @1 K! y2 m A: L )5 j% Z) W6 t* g3 n7 }5 ] I
1 p4 r$ p% [: @* B* S9 B2 D |