<P>;-------------------------------------------------------------------<BR>; THREAD.LSP Creates 3D solid (ACIS) threads. 01/9/1999<BR>;<BR>; Corrected<BR>;<BR>; written by: Robbert Teggelove<BR>;<BR>;-------------------------------------------------------------------<BR>;<BR>; This is a way to make 3D solid external threads in<BR>; AutoCAD R13 and R14.<BR>; You can make threads according to:<BR>; - ISO 228 (equal to DIN 228 and NEN 176)<BR>; - Gas thread straight inside thread only, ISO 7-1 (equal to DIN 2999 and NEN 3258)<BR>; - Metric inside and outside thread, NEN 81 and NEN 1870, geometrically 100% correct<BR>;<BR>; There is no error trapping or anything like that.<BR>;<BR>; The program works by creating a single thread<BR>; and then arraying it out to the proper length. The threads are<BR>; drawn a little longer and then sliced off to the correct length.<BR>; This program only draws the thread, you're on your own drawing<BR>; the rest of the screw or internal thread.<BR>;<BR>; Note, the threads created by this can make for some rather big files,<BR>; so make sure your system is up to it. Also, it might take a while<BR>; to union all of the single threads together so be patient.<BR>;<BR>;-------------------------------------------------------------------</P>
<P><BR>(defun myerror (s)</P>
<P> (if (/= s "function cancelled") (princ (strcat "<A href="file://nError/"><U><FONT color=#0000ff>\\nError</FONT></U></A>: " s)))<BR> (setvar "cmdecho" ocmd)<BR> (setvar "osmode" osm)<BR> (setq *error* olderr)<BR> (princ)<BR>)</P>
<P>(defun c:ISO228 (/ nom pitch length threadangle cpt inout minordiafactor nom1 nom2 size size1 n s olderr)</P>
<P> ;;;;(setq olderr *error*<BR> ;;;; *error* myerror)<BR> (setq osm (getvar "osmode"))<BR> (setq ocmd (getvar "cmdecho"))</P>
<P> (setvar "cmdecho" 1)</P>
<P> (setq minordiafactor 1.6666666667)<BR> ;(Princ "<A href="file://nThread/"><U><FONT color=#0000ff>\\nThread</FONT></U></A> according to DIN ISO 228, NEN 176")<BR> ;(initget 1 "I E")<BR> ;(setq inout (getkword "<A href="file://nInternal/"><U><FONT color=#0000ff>\\nInternal</FONT></U></A> or External thread (I/E): "))<BR> (setq inout "I")<BR> (initget "1/16 1/8 1/4 3/8 1/2 5/8 3/4 7/8 1 1-1/8 1-1/4 1-1/2 1-3/4 2 2-1/4 2-1/2 2-3/4 3 3-1/2 4 4-1/2 5 5-1/2 6")<BR> (setq size1 (getkword "<A href="file://n/"><U><FONT color=#0000ff>\\n</FONT></U></A>公称尺寸, 1/16' to 6' (如: 1/8 or 1-1/4): "))<BR> (if(= size1 "1/16")(setq nom1 1.5875))<BR> (if(= size1 "1/8")(setq nom1 3.175))<BR> (if(= size1 "1/4")(setq nom1 6.35))<BR> (if(= size1 "3/8")(setq nom1 9.525))<BR> (if(= size1 "1/2")(setq nom1 12.7))<BR> (if(= size1 "5/8")(setq nom1 15.875))<BR> (if(= size1 "3/4")(setq nom1 19.05))<BR> (if(= size1 "7/8")(setq nom1 22.225))<BR> (if(= size1 "1")(setq nom1 25.4))<BR> (if(= size1 "1-1/8")(setq nom1 28.575))<BR> (if(= size1 "1-1/4")(setq nom1 31.75))<BR> (if(= size1 "1-1/2")(setq nom1 38.1))<BR> (if(= size1 "1-3/4")(setq nom1 44.45))<BR> (if(= size1 "2")(setq nom1 50.8))<BR> (if(= size1 "2-1/4")(setq nom1 57.15))<BR> (if(= size1 "2-1/2")(setq nom1 63.5))<BR> (if(= size1 "2-3/4")(setq nom1 69.85))<BR> (if(= size1 "3")(setq nom1 76.2))<BR> (if(= size1 "3-1/2")(setq nom1 88.9))<BR> (if(= size1 "4")(setq nom1 101.6))<BR> (if(= size1 "4-1/2")(setq nom1 114.3))<BR> (if(= size1 "5")(setq nom1 127))<BR> (if(= size1 "5-1/2")(setq nom1 139.7))<BR> (if(= size1 "6")(setq nom1 152.4))<BR> ;(setq size "1") ; demo version only 1<BR> ;(if (= size "1")(if (= inout "E") (setq nom1 33.069) (setq nom1 33.568)))<BR> (setq n (getdist "<A href="file://n/"><U><FONT color=#0000ff>\\n</FONT></U></A>牙数:"))<BR> (setq pitch (/ 25.4 n))<BR> (initget 1) ; no enter<BR> (setq cpt (getpoint "起始点: "))<BR> (initget 3) ; no enter, not zero<BR> (setq length (getdist "<A href="file://n/"><U><FONT color=#0000ff>\\n</FONT></U></A>螺纹总长(Y方向): "))</P>
<P> (setq h (* 0.96049 pitch)) ; h according to ISO 228<BR> (setq nom (+ nom1 (/ h 3))) ; biggest outside diameter<BR> (setq nom2 (- nom (* h minordiafactor))) ; inside diameter<BR> (setq threadangle (+ 27.5 0)) ; threadangle</P>
<P> (setvar "osmode" 0)<BR> (setvar "cmdecho" 0)</P>
<P> (drawthread nom nom1 nom2 pitch length threadangle cpt)</P>
<P> (princ "<A href="file://nDone/"><U><FONT color=#0000ff>\\nDone</FONT></U></A>")<BR> (setvar "osmode" osm)<BR> (setvar "cmdecho" ocmd)<BR> (setq *error* olderr)<BR> (princ)<BR>)</P>
<P><BR>; Next routine makes metric thread according to NEN 1870</P>
<P>(defun c:Metric (/ nom pitch length threadangle cpt inout minordiafactor nom1 nom2 ocmd osm 4H 5H 6H h6 g6 tol)</P>
<P> ;-------------------------------------------------------------------<BR> ; Gets the nominal size, tpi, and total length<BR> ; then calculates a bunch of geometry points.<BR> ; All running osnaps are turned off as well.<BR> ;-------------------------------------------------------------------</P>
<P> (setq 4H (list 0.0015 0.002 0.002 0.0025 0.003 0.0035 0.004 0.005 0.006 0.007 0.008 0.009 0.010)) <BR> (setq 5H (list 0.002 0.0025 0.003 0.004 0.0045 0.0055 0.0065 0.0075 0.009 0.010 0.0115 0.0125 0.0135)) <BR> (setq 6H (list 0.003 0.004 0.0045 0.0055 0.0065 0.008 0.0095 0.011 0.0125 0.0145 0.016 0.018 0.020)) <BR> (setq h6 (list -0.003 -0.004 -0.0045 -0.0055 -0.0065 -0.008 -0.0095 -0.011 -0.0125 -0.0145 -0.016 -0.018 -0.020)) <BR> (setq g6 (list -0.005 -0.008 -0.0095 -0.0115 -0.0135 -0.017 -0.0195 -0.023 -0.0265 -0.0295 -0.033 -0.036 -0.0515)) </P>
<P> (setq osm (getvar "osmode"))<BR> (setq ocmd (getvar "cmdecho"))<BR> (setq minordiafactor 1.5)<BR> ;(initget 1 "I E")<BR> ;(setq inout (getkword "<A href="file://nInternal/"><U><FONT color=#0000ff>\\nInternal</FONT></U></A> or External thread (I/E): "))<BR> (setq inout "I")<BR> (initget 7) ; no enter, not zero, not negative<BR> (setq nom1 (getdist "<A href="file://n/"><U><FONT color=#0000ff>\\n</FONT></U></A>公称外径: "))<BR> ;(setq nom1 10) ; demo version only M10<BR> (initget 7) ; no enter, not zero, not negative<BR> (setq pitch (getreal "<A href="file://n/"><U><FONT color=#0000ff>\\n</FONT></U></A>螺距: "))<BR> ;(setq pitch 1.25) ; demo version only 1.25<BR> (initget 1) ; no enter<BR> (setq cpt (getpoint "起始点: "))<BR> (initget 3) ; no enter, not zero, not negative<BR> (setq length (getdist "<A href="file://n/"><U><FONT color=#0000ff>\\n</FONT></U></A>螺纹总长(Y方向): "))</P>
<P>; add tolerance to nominal diameter</P>
<P> (if (<= nom1 3) (setq n 0) ; position in tolerance field depending on nominal diameter<BR> (if (<= nom1 6) (setq n 1)<BR> (if (<= nom1 10) (setq n 2)<BR> (if (<= nom1 18) (setq n 3)<BR> (if (<= nom1 30) (setq n 4)<BR> (if (<= nom1 50) (setq n 5)<BR> (if (<= nom1 80) (setq n 6)<BR> (if (<= nom1 120) (setq n 7)<BR> (if (<= nom1 180) (setq n 8)<BR> (if (<= nom1 250) (setq n 9)<BR> (if (<= nom1 315) (setq n 10)<BR> (if (<= nom1 400) (setq n 11)<BR> (if (<= nom1 500) (setq n 12)<BR> )))))))))))))</P>
<P> (if (= inout "I")<BR> (if (< pitch 0.25) (setq nom1 (+ nom1 (nth n 4H))) ; tolerance field to use depending on pitch<BR> (if (< pitch 0.35) (setq nom1 (+ nom1 (nth n 5H)))<BR> (if (>= pitch 0.35) (setq nom1 (+ nom1 (nth n 6H)))<BR> )))<BR> )<BR> (if (= inout "E")<BR> (if (< pitch 0.35) (setq nom1 (+ nom1 (nth n h6)))<BR> (if (>= pitch 0.35) (setq nom1 (+ nom1 (nth n g6)))<BR> ))<BR> )</P>
<P> (setq h (* 0.866025 pitch)) ; h=0.866025<BR> (setq nom (+ nom1 (/ h 4))) ; h/8<BR> (setq nom2 (- nom (* h minordiafactor))) ; inside diameter<BR> (setq threadangle (+ 30 0)) ; 30?threadangle</P>
<P> (setvar "osmode" 0)<BR> (setvar "cmdecho" 0)</P>
<P> (drawthread nom nom1 nom2 pitch length threadangle cpt)</P>
<P> (princ "<A href="file://nDone/"><U><FONT color=#0000ff>\\nDone</FONT></U></A>")<BR> (setvar "cmdecho" ocmd)<BR> (setvar "osmode" osm)<BR> (princ)<BR>)</P>
<P><BR>; Next routine makes all threads</P>
<P>(defun c:mythread (/ nom pitch length threadangle cpt inout minordiafactor nom1 ocmd osm)</P>
<P> ;-------------------------------------------------------------------<BR> ; Gets the nominal size, tpi, and total length<BR> ; then calculates a bunch of geometry points.<BR> ; All running osnaps are turned off as well.<BR> ;-------------------------------------------------------------------</P>
<P> (setq osm (getvar "osmode"))<BR> (setq ocmd (getvar "cmdecho"))<BR> (initget 7) ; no enter, not zero, not negative<BR> (setq nom1 (getdist "<A href="file://n/"><U><FONT color=#0000ff>\\n</FONT></U></A>有效外径: "))<BR> ;(setq nom1 22) ; demo version only 22<BR> (initget 7) ; no enter, not zero, not negative<BR> (setq nom (getdist "<A href="file://n/"><U><FONT color=#0000ff>\\n</FONT></U></A>公称外径: "))<BR> ;(setq nom 22.5) ; demo version only 22.5<BR> (initget 7) ; no enter, not zero, not negative<BR> (setq nom2 (getdist "<A href="file://n/"><U><FONT color=#0000ff>\\n</FONT></U></A>有效底径: "))<BR> (initget 7) ; no enter, not zero, not negative<BR> (setq pitch (getreal "<A href="file://n/"><U><FONT color=#0000ff>\\n</FONT></U></A>螺距: "))<BR> (initget 7) ; no enter, not zero, not negative<BR> (setq threadangle (getreal "<A href="file://n/"><U><FONT color=#0000ff>\\n</FONT></U></A>螺纹角度: "))<BR> (initget 1) ; no enter<BR> (setq cpt (getpoint "起始点: "))<BR> (initget 3) ; no enter, not zero, not negative<BR> (setq length (getdist "<A href="file://n/"><U><FONT color=#0000ff>\\n</FONT></U></A>螺纹总长(Y方向): "))</P>
<P> (setq h (* 0.866025 pitch)) ; h=0.866025</P>
<P> (setvar "osmode" 0)<BR> (setvar "cmdecho" 0)</P>
<P> (drawthread nom nom1 nom2 pitch length threadangle cpt)</P>
<P> (princ "<A href="file://nDone/"><U><FONT color=#0000ff>\\nDone</FONT></U></A>")<BR> (setvar "cmdecho" ocmd)<BR> (setvar "osmode" osm)<BR> (princ)<BR>)</P>
<P><BR>(defun drawthread (nom nom1 nom2 pitch length threadangle cpt / total pt1 pt1z pt2 pt3 ang pt1a<BR>pt1az pt3a pt1b pt1bz pt3b pt4 pt4 pt6 pt7 pt8 pt9 pt10 pt11 pt12 ss conewantedstart conewantedend)</P>
<P> ;-------------------------------------------------------------------<BR> ; Gets the nominal size, tpi, and total length<BR> ; then calculates a bunch of geometry points.<BR> ; All running osnaps and cmdecho are turned off as well.<BR> ;-------------------------------------------------------------------<BR> ;(command "undo" "begin") ; start undo steps</P>
<P> (setq total (+ (fix (/ (abs length) pitch)) 3)<BR> pt1 (list (- (car cpt) (/ nom 2.0)) (cadr cpt) (caddr cpt))<BR> pt1z (list (- (car cpt) (/ nom 2.0)) (cadr cpt) (+ (caddr pt1) 1.0))<BR> pt2 (polar pt1 (/ (* threadangle pi) 180.0) 1)<BR> pt3 (list (+ (car pt1) nom) (+ (cadr pt1) (/ pitch 2.0)) (caddr cpt))<BR> ang (angle pt1 pt3)<BR> pt1a (polar pt1 (+ ang (/ pi 2.0)) pitch)<BR> pt1az (list (car pt1a) (cadr pt1a) (+ (caddr pt1a) 1.0))<BR> pt3a (polar pt1a ang nom)<BR> pt1b (polar pt1 (- ang (/ pi 2.0)) pitch)<BR> pt1bz (list (car pt1b) (cadr pt1b) (+ (caddr pt1b) 1.0))<BR> pt3b (polar pt1b ang nom)<BR> pt4 (polar pt3 (/ (* (- 180 threadangle) pi) 180.0) 1)<BR> pt5 (inters pt1 pt2 pt3 pt4 nil)<BR> pt6 (list (car pt5) (cadr cpt) (caddr cpt))<BR> pt7 (polar pt1 (/ (* (- 360 threadangle) pi) 180.0) 1)<BR> pt8 (polar pt3 (/ (* (+ 180 threadangle) pi) 180.0) 1)<BR> pt9 (inters pt1 pt7 pt3 pt8 nil)<BR> pt10 (list (car pt9) (cadr pt3) (caddr pt3))<BR> pt11 (polar cpt (/ pi 2.0) pitch)<BR> pt12 (polar pt11 (/ pi 2.0) (abs length))<BR> )</P>
<P> ;-------------------------------------------------------------------<BR> ; Draws two cones which are inverted and offset 1/2 the pitch.<BR> ; The cones are each sliced at the angle of the crest line<BR> ; and then unioned together<BR> ;-------------------------------------------------------------------</P>
<P>; (initget 0 "Y N")<BR>; (setq conewantedstart (getkword "<A href="file://nDo/"><U><FONT color=#0000ff>\\nDo</FONT></U></A> you want a 90?top angle at the start? (Y/N) <Y>: <BR>(SETQ CONEWANTEDSTART "N")<BR>;"))<BR>; (initget 0 "Y N")<BR>; (setq conewantedend (getkword "<A href="file://nDo/"><U><FONT color=#0000ff>\\nDo</FONT></U></A> you want a 90?top angle at the end? (Y/N) <Y>: "))<BR>(SETQ CONEWANTEDEND "Y")<BR> (command "zoom" "w" (list (car pt1a) (+ (cadr pt1a) (abs length)) (caddr pt1a)) pt3b)</P>
<P> (princ "<A href="file://n/"><U><FONT color=#0000ff>\\n</FONT></U></A>绘制螺纹....需要一段时间")<BR> (command "pline" pt1 pt5 pt6 "c")<BR> (command "revolve" "l" "" pt5 pt6 "")<BR> (command "slice" "l" "" pt1 pt3 pt1z pt5)<BR> (command "slice" "l" "" pt1a pt3a pt1az pt3)<BR> (setq ss (ssadd (entlast)))<BR> (command "pline" pt3 pt9 pt10 "c")<BR> (command "revolve" "l" "" pt9 pt10 "")<BR> (command "slice" "l" "" pt1 pt3 pt1z pt9)<BR> (command "slice" "l" "" pt1b pt3b pt1bz pt3)<BR> (setq ss (ssadd (entlast) ss))<BR> (command "union" ss "")</P>
<P> ;-------------------------------------------------------------------<BR> ; This above solid is sliced in half and then mirrored. This<BR> ; creates the "helix" in the thread. The height of the single<BR> ; thread is actually equal to twice the pitch, but the<BR> ; excess is either absorbed or cut off in the last step<BR> ;-------------------------------------------------------------------</P>
<P> (command "slice" ss "" "xy" cpt "b")<BR> (setq ss (ssadd (entlast) ss))<BR> (command "mirror" "l" "<A href='mailto:" pt1 "@10<0'><U><FONT color=#0000ff>" pt1 "@10<0</FONT></U></A>" "y")<BR> (command "union" ss "")</P>
<P> ;-------------------------------------------------------------------<BR> ; The thread is arrayed and then unioned together (this part can<BR> ; take a while). The resulting solid is cut to the specified length.<BR> ;-------------------------------------------------------------------</P>
<P> (setq e (entlast))<BR> (command "array" ss "" "r" total 1 pitch)<BR> (repeat (1- total)<BR> (setq e (entnext e)<BR> ss (ssadd e ss)<BR> )<BR> )<BR> (command "union" ss "")</P>
<P>; if wanted make a 45?cone at the start and union with thread</P>
<P> (if (/= conewantedstart "N")<BR> (progn (setq e (entlast))<BR> (command "cone" (list (car cpt) (+ (cadr cpt) pitch) (caddr cpt)) "d" nom1 "a" (list (car cpt) (+ (+ (cadr cpt) (/ nom1 2)) pitch) (caddr cpt)))<BR> (command "union" "l" e "")<BR> )<BR> )</P>
<P> (command "slice" "l" "" "zx" pt11 pt12)<BR> (command "slice" "l" "" "zx" pt12 pt11)<BR> (command "move" "l" "" cpt (list (car cpt) (- (cadr cpt) pitch) (caddr cpt))) </P>
<P>; make a minor diameter cylinder and union with thread</P>
<P> (setq e (entlast))<BR> (command "cylinder" cpt "d" nom2 "c" (list (car cpt) (+ (cadr cpt) (abs length)) (caddr cpt)))<BR> (command "union" "l" e "")<BR> (setq ss (entlast))</P>
<P>; make a hollow cylinder, with or without end cone, and subtract from thread</P>
<P> (command "cylinder" cpt "d" nom1 "c" (list (car cpt) (+ (cadr cpt) (abs length)) (caddr cpt))) ; minor dia<BR> (setq e (entlast))</P>
<P> ; if wanted make a 45?cone at the end</P>
<P> (if (/= conewantedend "N")<BR> (progn (command "move" "l" "" cpt (list (car cpt) (- (cadr cpt) (/ (- nom1 nom2) 2)) (caddr cpt))) ; move minor dia down<BR> (command "cone" cpt "d" nom1 "a" (list (car cpt) (+ (cadr cpt) (/ nom1 2)) (caddr cpt))) ; put cone on minor dia<BR> (command "move" "l" "" cpt (list (car cpt) (- (+ (cadr cpt) (abs length)) (/ (- nom1 nom2) 2)) (caddr cpt)))<BR> (command "union" "l" e "") ; union cone and minor dia<BR> (setq e (entlast))<BR> )<BR> )</P>
<P> ; subtract minor dia from bigger cylinder</P>
<P> (command "cylinder" cpt "d" (* nom1 1.5) "c" (list (car cpt) (+ (cadr cpt) (abs length)) (caddr cpt)))<BR> (command "subtract" "l" "" e "")<BR> (setq e (entlast))</P>
<P> ; subtract hollow cylinder from thread</P>
<P> (command "subtract" ss "" e "")</P>
<P> ; if thread negative length then mirror</P>
<P> (setq e (entlast))<BR> (if (< length 0) (mirror3d e "zx" cpt "y"))</P>
<P> (command "zoom" "p")</P>
<P> (command "undo" "end") ; end undo steps<BR>)</P>
<P><BR>;;;---------------------------------------------------------------------------------------------------------------------;</P>
<P>(arxload "geom3d" nil)<BR>(princ "<A href="file://n//tISO228"><U><FONT color=#0000ff>\\n\\tISO228</FONT></U></A>, Metric and Mythread loaded. ")<BR>;(princ "<A href="file://n//tThis"><U><FONT color=#0000ff>\\n\\tThis</FONT></U></A> copy is licensed to: DEMO VERSION ")<BR>(princ)</P>
<P></P><BR>