Flange with bolt circle LISP

Discussion in 'AutoCAD' started by Dr Fleau, Apr 18, 2007.

  1. Dr Fleau

    Dr Fleau Guest

    Hi ya,

    I just feel like sharing a little thing I did a while ago. I love it,
    anyway. Hope you do too. It draws a circular flange with outerØ, innerØ,
    bolt circle and holes in a snap.

    Feel free to give it away at Christmas. It's a great stocking stuffer.

    ;;; Flange.lsp
    ;;; Draws a flange with bolt circle
    (DEFUN c:flange(/ out in bc num trou cen cen1 cir1 cir2 cir3)
    (SETQ out (GETREAL "Give OUTER diameter : ")
    in (GETREAL "Give INNER diameter :")
    bc (GETREAL "Give bolt circle diameter : ")
    num (GETINT "How many holes : ")
    trou (GETREAL "Hole diameter : ")
    cen (GETPOINT "Insertion point : ")
    ) ;_ end of setq
    (IF (NOT (AND (TBLSEARCH "layer" "Axis")
    (TBLSEARCH "layer" "Contour")
    ) ;_ END and
    ) ;_ END not
    (PROGN
    (COMMAND "layer" "m" "Axis" "c" "Red" "" "l" "center" "" "") ;_ END
    COMMAND
    (COMMAND "layer" "m" "Contour" "c" "Magenta" "" "l" "continuous" ""
    "") ;_ END COMMAND
    ) ;_ END progn
    )
    (SETVAR "OSMODE" 0)
    (setvar "CLAYER" "Contour")
    (COMMAND "_.circle" cen "D" out)
    (COMMAND "_.circle" cen "D" in)
    (SETQ cen1 (POLAR cen (/ PI 2) (/ bc 2)))
    (COMMAND "_.circle" cen1 "D" trou)
    (setq cir1 (entlast))
    (setvar "CLAYER" "AXIS")
    (command "_.line" (polar cen1 (/ pi 2) (/ trou 2)) (polar cen1 (/ pi -2)
    (/ trou 2)) "")
    (setq cir2 (entlast))
    (command "_.line" (polar cen1 pi (/ trou 2)) (polar cen1 0.0 (/ trou 2))
    "")
    (setq cir3 (entlast))
    (setvar "OSMODE" 0)
    (command "_.regen")
    (COMMAND "_.array" cir1 cir2 cir3 "" "P" cen num 360 "y")
    (setvar "CLAYER" "Contour")
    (SETVAR "OSMODE" 183)
    (PRINC)
    ) ;_ end of defun


    Dr Fléau
     
    Dr Fleau, Apr 18, 2007
    #1
  2. Dr Fleau

    taiken Guest

    On 4/18/07 I read from Dr Fleau:
    Dr Fleau or anyone else interested --here is a routine I wrote a year or so
    ago that creates a 3d weld neck flange as a solid model. It requires a text
    file also included here. When copying the text file note that it is space
    delimited and must have one space ending each line. You must edit the lisp
    to send the routine to the proper place to find the file on your system.

    By the way a very nice routine you have written

    First the lisp:


    ;;A program to draw a 3D wn flange
    ;; The program has no error checking so results will be unpredictable if
    negative numbers are used
    ;; I recommend using this program in a new drawing and copying the flange
    where it is needed
    ;;Written by Tim Aiken-- tested on 2000 and 2004 --may be distributed freely
    as long as this heading remains


    ;; Create the function to read the data file

    (defun rdata ( / ups a dps c ctr)

    ;; Get the pipe size from the user

    (setq ups (getreal "Enter the pipe size Enter 0.5 or 0.75 for 1/2 or 3/4
    pipe: "))

    ;; Open the data file read only ;; Change the path to the data file on your
    system

    (setq a (open "c:/windows/desktop/Tim's folder/acad/150_flg_data.txt" "r"))

    ;; Initialize a variable to contain the pipe size returned from each loop of
    the while statement

    (setq dps 0)

    ;; Loop through the data file one line at a time

    (while (/= ups dps)

    ;; Read each line of the data file until the first string (first entry) of
    the file is equal to the pipe size

    (setq *b (read-line a))

    ;; Get the first string of the line but first...

    ;; initialize a counter and a container for a concatenated string

    (setq ctr 1 str "" c "")

    ;; As long as the character c is not a space...

    (while (/= c " ")

    ;; In case the pipe size has 2 digits...
    (progn
    (setq c (substr *b ctr 1))
    (setq str (strcat str c))
    (setq ctr (1+ ctr))
    );progn


    );while

    ;; Convert the substring to an integer

    (setq dps (atof str))


    ;; end while

    )

    ;; Close the open file

    (close a)

    ;; *b is the line of interest, using substr loop through the line *b to pull
    out the substrings

    ;;set up the counter to increment the substr function to walk through the
    line of text

    (setq *sctr 1)

    ;; initialize a variable to hold the data string as it is revealed by the
    substr routine

    (setq datastr "")

    ;; initialize a variable to track the number of spaces found

    (setq *ns 0)

    ;; initialize a variable to hold the length of *b

    (setq *blength (strlen *b))



    ;; if *a is a space then the complete piece of data is contained in datastr.
    If *a is not a space concatenate *a
    ;;to the data string and increment the counter. Repeat evaluation for every
    character in *b

    (repeat *blength

    ;;initialize a variable to hold the substring

    (setq *a (substr *b *sctr 1))

    (if (= *a " ")

    (progn
    (setq *ns (1+ *ns))
    (cond
    ((= *ns 1) (setq pid (atof datastr)) (setq *sctr (1+ *sctr)) (setq datastr
    ""))
    ((= *ns 2) (setq odia (atof datastr)) (setq *sctr (1+ *sctr)) (setq
    datastr ""))
    ((= *ns 3) (setq tflg (atof datastr)) (setq *sctr (1+ *sctr)) (setq
    datastr ""))
    ((= *ns 4) (setq bhdia (atof datastr)) (setq *sctr (1+ *sctr)) (setq
    datastr ""))
    ((= *ns 5) (setq nb (atoi datastr)) (setq *sctr (1+ *sctr)) (setq datastr
    ""))
    ((= *ns 6) (setq lth (atof datastr)) (setq *sctr (1+ *sctr)) (setq datastr
    ""))
    ((= *ns 7) (setq bhcdia (atof datastr)) (setq *sctr (1+ *sctr)) (setq
    datastr ""))

    );cond
    );prog

    (progn
    (setq datastr (strcat datastr *a))
    (setq *sctr (1+ *sctr))
    );prog

    );if

    );repeat

    ;; Exit cleanly

    (princ)

    ;; end defun

    )

    ;;process the data

    (defun procinfo ()

    ;;compute radius of bolt hole circle

    (setq x (/ bhcdia 2))

    ;;global variable to define a point which will be the center of the bolt
    hole array

    (setq *bh (list 0 x))

    ;;draw the bolt hole

    (COMMAND "circle" *bh "d" bhdia)

    ;;get name of bolt hole entity

    (setq *k (entlast))

    ;;create a ss of the bolt hole

    (setq *l (ssadd *k))

    ;;array the bolt holes

    (COMMAND "array" *l "" "p" "0,0" nb "" "")

    ;;global to define a selection set of all entities (ie the newly arrayed
    bolt holes)

    (setq *xxx (ssget "_X"))

    ;;set isolines to 10 for ease of viewing

    (setvar "isolines" 10)

    ;;extrude the bolt holes to the height of the flange thickness

    (COMMAND "extrude" *xxx "" tflg "")

    ;;reset global to define a selection set of all entities(solid bolt holes)
    for subtraction later

    (setq *xxx (ssget "_X"))


    ;;draw the outside of the flange

    (COMMAND "circle" "0,0" "d" odia)

    ;;get name of the outside circle to extrude later

    (setq *xx (entlast))

    ;;draw the pipe ID circle

    (COMMAND "circle" "0,0" "d" pid)

    ;;global to get the name of the pipe circle for later extrusion

    (setq *a (entlast))

    ;;create ss for later extrusion

    (setq *t (ssadd *a))

    ;;extrude the outside flange circle

    (COMMAND "extrude" *xx "" tflg "")

    ;;get name of the outside flange extrusion

    (setq *i (entlast))

    ;;create a ss of the outside flange extrusion

    (setq *j (ssadd *i))

    ;;subtract the bolt holes from the flange

    (COMMAND "subtract" *j "" *xxx "")
    ;; get name of the new subtracted entity

    (setq *r (entlast))

    ;;create ss of the subtracted extrusions

    (setq *s (ssadd *r))

    ;; make a list representing the center point for the tapered extrusion

    (setq *c (list 0 0 tflg))

    ;;make the diameter of the circle for the tapered extrusion 1.5" larger than
    the pipe circle

    (setq *d (- bhcdia 1.25))

    ;;draw the circle for the tapered extrusion

    (COMMAND "circle" *c "d" *d)

    ;;get name of circle which will later be tapered

    (setq *h (entlast))

    ;;create a ss for this circle

    (setq *e (ssadd *h))

    ;;statements to get the extrusion angle

    ;;set the extrusion height 0.25" less than tflg

    (setq *f (- lth (+ tflg 0.25)))
    (setq *m (+ 0.25 (/ pid 2)))
    (setq *n (/ *d 2))
    (setq *g (atan (/ (- *n *m) *f)))

    ;;atan returns angle in radians so convert to degrees
    (setq *o (/ (* *g 360) 6.28))

    ;; extrude the tapered portion

    (COMMAND "extrude" *e "" *f *o)

    ;;get the name of the extruded tapered circle

    (setq *p (entlast))

    ;; create a ss for the tapered extrusion for joining(UNION) by adding the
    tapered solid to the subtracted flange ss

    (setq *q (ssadd *p *s))

    ;; union the solids

    (COMMAND "union" *q "")

    ;;reuse old global "*a" to get name for new solid after union command

    (setq *a (entlast))

    ;;create a ss of the unioned solids for subtraction

    (setq *b (ssadd *a))

    ;;extrude the pipe circle to lth

    (COMMAND "extrude" *t "" lth "")

    ;;get the name of this extrusion

    (setq *u (entlast))

    ;; create a ss for subtraction

    (setq *v (ssadd *u))

    ;;subtract the pipe extrusion from the flange and tapered ss

    (COMMAND "subtract" *b "" *v "")

    ;; get the name of the subtracted solids (reuse old global

    (setq *f (entlast))

    ;; create a ss from this solid

    (setq *w (ssadd *f))

    ;; create the small triangle that will revolve to become the bevel but
    first...

    ;; create a point to start the construction of the triangle

    (setq *n (list *m (- lth 0.25)))

    ;; ... and now the triangle

    (COMMAND "_-view" "_front")

    (COMMAND "pline" *n "@0.25<180" "@0,0.25" "c" )

    ;; get the name of the triangle

    (setq *aa (entlast))

    ;; create a ss of the triangle

    (setq *bb (ssadd *aa))

    ;;now revolve the triangle about the y axis

    (COMMAND "revolve" *bb "" "y" "")

    ;;get the name of the revolved triange reuse *bb

    (setq *bb (entlast))

    ;;create a ss of the revolved triangle reuse *aa

    (setq *aa (ssadd *bb *w))

    ;; union the two solids

    (COMMAND "union" *w "")

    ;;get the name of the completed flange reuse *aa

    (setq *aa (entlast))

    ;; create a ss of the flange reuse *bb

    (setq *bb (ssadd *aa))

    ;; reset the view to top to rotate the flange 22.5 degrees

    (COMMAND "_-view" "top")

    ;;rotate the flange depending on the # of bolt holes

    (setq *cc (/ 180 nb))

    (COMMAND "rotate" *bb "" "0,0" *cc )

    ;; exit smooth

    (princ)

    ;;end procinfo

    )


    ;; create main container function to bring it all together

    (defun c:fl ( / odia tflg bhdia nb lth bhcdia pid) ;; fl runs the
    program
    (rdata)
    (procinfo)

    ;;end the program

    )


    And now the text file:


    0 pipe size/ odia/ tflg/ bhdia/ nb/ lth/ bhcdia/ pod --- last data must
    follow with a space
    0.5 3.5 0.4375 0.625 4 1.875 2.375 0.840
    0.75 3.875 0.5 0.625 4 2.0625 2.75 1.050
    1 4.25 0.5625 0.625 4 2.1875 3.125 1.315
    1.25 4.625 0.625 0.625 4 2.25 3.5 1.660
    1.5 5 0.6875 0.625 4 2.4375 3.875 1.9
    2 6 0.75 0.75 4 2.5 4.75 2.375
    2.5 7 0.875 0.75 4 2.75 5.5 2.875
    3 7.5 0.9375 0.75 4 2.75 6 3.5
    4 9 0.9375 0.75 8 3 7.5 4.5
    5 10 0.9375 0.75 8 3.5 8.5 5.563
    6 11 1 0.875 8 3.5 9.5 6.625
    8 13.5 1.125 0.875 8 4 11.75 8.625
    10 16 1.1875 1 12 4 14.25 10.75
    12 19 1.25 1 12 4.5 17 12.75


    Text file ends with space after 12.75
    Name the file "150_flg_data.txt" ( maximize window before you copy text)
    If you require flanges larger than 12" you'll need to add data to the text
    file
    I also have routines for 3d elbows, reducers, tees, and slip on flanges --
    all generate solid models of exact proportions.
     
    taiken, Apr 19, 2007
    #2
    Hitendra likes this.
  3. Dr Fleau

    longshot Guest

    will your lisp make offset reducers or just concentric?
     
    longshot, Apr 19, 2007
    #3
  4. Dr Fleau

    taiken Guest

    Longshot wrote:
    Only concentric at this time.
     
    taiken, Apr 19, 2007
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.