Author Topic: THREADS  (Read 1477 times)

0 Members and 1 Guest are viewing this topic.

John Hancock

  • Guest
THREADS
« on: August 16, 2007, 02:04:09 PM »
I found this lisp program for drawing threads on the Cadalyst web site.  It's a great routine but I have to reload it each time I use it.  If I make a mistake while in a drawing session I have to reload. 
Could one of you guys tell me what is the problem.

Code: [Select]
; TIP855: THREADS.LSP (c)1993, Paul Davisson

; This routine draws any unified screw thread profile
; which includes the following; coarse thread series
; (unc/unrc), fine thread series (unf/unrf), extra fine
; thread series (unef/unref), and selected combinations
; (uns/unrs).  The program prompts for the style
; of thread (you need only enter whether it is a
; "un" or "unr" series of thread, the default is "un".),
; the pitch diameter, number of threads per inch,
; the approximate length of thread desired, and the
; insertion point on the drawing.  Note the 
; approximate length is used because the thread is
; constructed in a manner that the length is derived
; using increments of thread pitch.  The user can trim the
; thread to the length desired.

;                               Paul Davisson   
;                               Nelson Irrigation Corp.
;                               Walla Walla, Wa. 99362


(setq ANS
   (getstring "unr or un thread series?    UNR or <UN>:   ")

      PIT
                (getreal "enter pitch diameter:   ")

      TI
                (getreal "enter threads per inch:   ")

      TL
   (getreal "enter approximate length of thread desired:  ")

      SP
                (getpoint "select insertion point")
)


(cond ((= ANS "UN")(setq Q 0.0))
      ((= ANS "UNR")(setq Q 1.0))
      ((= ANS "unr")(setq Q 1.0))
      ((= ANS "un")(setq Q 0.0))
      ((= ANS  )(setq Q 0.0))
)


(setq P     (/ 1.0 TI)   
               ; derives thread pitch
   

      TLL   (fix (/ TL P))     
               ; takes desired approximate thread length and     
               ; associates it with the number of threads 
               ; per inch and makes it an intiger
   


      H     (/(* 0.125 P (cos (/ PI 6.0)))
              (* 0.25 (sin (/ PI 6.0))))
               ; literal peak to peak thread height
   

      MAJ   (+ PIT (* 0.375 2.0 H))
               ; major diameter
   
      MIN   (- MAJ (* 2.0 0.625 H))
               ; minor diameter for "un" series
   
      MINR   (- MIN (* H 0.125))
               ; minor diameter for "unr" series

      HMJ   (/ MAJ 2.0)
               ; major radius

      HMN   (/ MIN 2.0)
               ; minor radius for "un" series
   
      HMNR  (/ MINR 2.0)
               ; minor radius for "unr" series

      DIFY  (/ (* (- HMJ HMN) (sin (/ PI 6.0)))
                             (cos (/ PI 6.0)))
               ; major minor difference in y dir for
               ; "un" series
   

      PA    (* 0.0625 P)
               ; one half width of thread crest
   
      A     (list (+ HMJ (car SP))(cadr SP))
      B     (list (car A)(-(cadr A) PA))
      C     (list (+ HMN (car SP))(-(cadr B) DIFY))
      D     (list (car C)(-(cadr A)(* 0.5 P)))
      E     (list (car D)(-(cadr D)(distance C D)))
      F     (list (car A)(-(cadr E) DIFY))
      G     (list (car F)(-(cadr F) PA))
      AA    (list (-(car SP) HMN)(cadr A))
      BB    (list (car AA)(- (cadr SP) (distance C D)))
      CC    (list (-(car SP) HMJ)(-(cadr BB) DIFY))
      DD    (list (car CC)(-(cadr CC) PA))
      EE    (list (car DD)(-(cadr DD) PA))
      FF    (list (car AA)(-(cadr EE) DIFY))
      GG    (list (car FF)(-(cadr FF) (distance C D)))
      I     (list (+ (car SP) HMNR)(- (cadr C)
                  (* 0.108 P (cos (/ PI 6.0)))))
      J     (list (car I)(cadr D))
      K     (list (car I)(- (cadr I)(* 2.0 (distance I J))))
      L     (list (- (car SP) HMNR)(- (cadr SP)
                  (distance I J)))
      M     (list (- (car SP) HMNR)(cadr SP))
      N     (list (car M)(- (cadr FF) (* 0.108 P
                  (cos (/ PI 6.0)))))
      O     (list (car M)(-(cadr N) (distance I J)))
)


(if (= Q 1.0) (command "pline" M "W" 0.0 ""
            L "A" BB "L" CC DD A B C "A" I "L" J O
                  N "A" FF "L" EE DD ""

         "array" (ssget "l") "" "r" TLL 1 (- P)

         "pline" J K "A" E "L" F G ""

         "array" (ssget "l") "" "r" TLL 1 (- P)

         "line" A M ""

         "array" (ssget "l") "" "r" 2 1 (- (* TLL P) )
                ) 
                 ; routine for "unr" series
     


          (command "pline" AA "w" 0.0 ""
                    BB CC EE FF GG D C B A DD ""
           
          "array" (ssget "l") "" "r" TLL 1 (- P)
 
          "pline" D E F G ""

          "array" (ssget "l") "" "r" TLL 1 (- P)

          "line" A AA ""

          "array" (ssget "l") "" "r" 2 1 (- (* TLL P) ))
)             
                 ; routine for "un" series 

(command  "line" (list (car SP) (+ (* PIT 0.1) (cadr SP)))
                 (list (car SP) (- (cadr SP) (+ (* TLL P)
                       (* PIT 0.1)))) "" )
                 ; routine for centerline
« Last Edit: August 16, 2007, 04:28:59 PM by Maverick® »

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: THREADS
« Reply #1 on: August 16, 2007, 02:12:44 PM »
Type APPLOAD in cad and then browse to where you have the file and then it will be there anytime you want it.
Be your Best


Michael Farrell
http://primeservicesglobal.com/

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: THREADS
« Reply #2 on: August 16, 2007, 03:08:10 PM »
The routine is designed ( I'm not sure why) without a command entry.

You could try somenthing like this ...
Code: [Select]
(DEFUN c:threads (/   A   AA  ANS B   BB  C   CC  D   DD  DIFY    E   EE  F   FF  G   GG
                  H   HMJ HMN HMNR    I   J   K   L   M   MAJ MINd    MINR    N   O   P
                  PA  PIT Q   SP  TI  TL  TLL
                 )
    ;;< paste the complete routine as posted below here ..>>


    (PRINC)
)
Then , once loaded it will run each time you enter THREADS at the command line
The variables have been made local to the routine as well.

NOTE
There is a variable named MIN used in the routine. It should be changed to MINd so as not to be confused with the built-in MIN function

/// kwb
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

John Hancock

  • Guest
Re: THREADS
« Reply #3 on: August 16, 2007, 04:00:56 PM »
Kerry,
Thanks much!  It works great now!

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: THREADS
« Reply #4 on: August 16, 2007, 04:03:16 PM »
You're welcome. :-)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.