Flange with bolt circle LISP

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

Reply to
Dr Fleau
Loading thread data ...

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

Reply to
taiken

will your lisp make offset reducers or just concentric?

Reply to
longshot

Only concentric at this time.

Reply to
taiken

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.