TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Water Bear on February 26, 2004, 11:26:31 AM
-
I made some changes, added a loop at the end but it won't work..can you tell me why?
(defun duct_calc
(/ friction volume velocity diam width depth area_sqft)
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;; Local Functions
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;
;; returns the square side dimension equivelant of rnd duct
(defun rnd_to_sqr (dia ; dia of round duct
a ; side A of square duct
/ loop fuzz b)
(if (= (type a) 'int) ; make sure A is a REAL
(setq a (* a 1.0))
)
(setq b a ; B is target
fuzz 0.001
loop t
)
;; Returns Side B of square duct
(while loop
(setq dia2
(* 1.3
(exp (/ (log (/ (expt (* a b) 5) (expt (+ a b) 2))) 8))
)
)
(if (equal dia2 dia fuzz)
(setq loop nil) ; done
(setq b (* b (/ dia dia2)))
)
)
(princ)
b
) ; end defun
;; given the area in square feet returns the diameter
(defun area2dia (sf_area / square)
(setq square (sqrt (* sf_area 144.0)))
(* 1.3
(exp
(/ (log (/ (expt (* square square) 5.0)
(expt (+ square square) 2.0)
)
)
8.0
)
)
)
) ; end defun
;; given diameter returns the side dimension
(defun dia2sq (dia)
;;(* dia 0.914774703)
;;(*(sqrt area_sqft)12)
(setq depth (* (sqrt area_sqft) 12)) ; CAB
(rnd_to_sqr dia depth) ; CAB
)
;; given the diameter returns the area in sq ft
(defun dia2area (dia)
;;(/ (* 0.7854 (expt dia 2.0)) 144.0)
(/ (* pi (expt (/ dia 2.0) 2.0)) 144.0) ; CAB
)
;;given a square duct, make it round<=====added this
(defun make_round (w d)
(* 1.3
(exp
(/ (log (/ (expt (* w d) 5.0)
(expt (+ w d) 2.0)
)
)
8.0
)
)
)
)
;; given the diameter returns the area in sq ft
(defun veloc2press (vel)
(expt (/ vel 4005.00) 2)
)
;; calc friction
(defun find_fric ()
(/ (* 0.109136 (expt volume 1.9)) (expt diam 5.02))
)
;;print results
(defun show_me ()
(textscr)
(mapcar '(lambda (x)
(prompt (strcat "\n"
(car x)
(if (cdr x)
(rtos (cdr x) 2 2)
"X"
)
)
)
)
(list (cons "Diameter " diam)
(cons "Width " width)
(cons "Depth " depth)
(cons "Volume " volume)
(cons "Velocity " velocity)
(cons "Friction " friction)
)
)
)
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;================================================================
;;; Start of Routine
;;;================================================================
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;; Get User Input
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
(prompt "\nEnter known values. Press Enter if not known. ")
(setq diam (getreal "\nEnter duct diameter: "))
(if (null diam) ; skip if diameter entered
(setq width (getreal "\nEnter duct width: ")
depth (getreal "\nEnter duct depth: ")
)
)
(setq volume (getreal "\nEnter total CFM'S: ")
loop t
)
(if (null (and (or diam (and width depth)) volume))
(setq friction (getreal "\nEnter FRICTION value: "))
)
(if (null (and (or diam (and width depth)) volume))
(setq velocity (getreal "\nEnter Velocity in FPM: "))
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;; Process User Input
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
(cond
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
((and friction diam)
(setq volume (exp
(/ (log (/ (* friction (expt diam 5.02)) 0.109136))
1.9
)
)
area_sqft (dia2area diam)
width (dia2sq diam)
velocity (/ volume area_sqft)
)
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
((and friction volume)
(setq diam (exp
(/ (log (/ (* 0.109136 (expt volume 1.9)) friction))
5.02
)
)
area_sqft (dia2area diam)
width (dia2sq diam)
velocity (/ volume area_sqft)
)
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
((and diam volume)
(setq area_sqft (dia2area diam)
width (dia2sq diam)
velocity (/ volume area_sqft)
friction (find_fric)
)
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
((and diam velocity)
(setq area_sqft (dia2area diam)
width (dia2sq diam)
volume (* area_sqft velocity)
friction (find_fric)
)
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
((and width depth friction)
(setq diam (make_round width depth)
volume (exp
(/ (log (/ (* friction (expt diam 5.02)) 0.109136))
1.9
)
)
velocity (/ volume (dia2area diam))
)
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
((and width depth volume)
(setq diam (make_round width depth)
velocity (/ volume (dia2area diam))
friction (find_fric)
)
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
((and width depth velocity)
(setq diam (make_round width depth)
volume (* (dia2area diam) velocity)
friction (find_fric)
)
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
((and volume velocity)
(setq area_sqft (/ (/ volume velocity) 0.914774703)
diam (area2dia area_sqft)
width (dia2sq diam)
friction (find_fric)
)
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
(t
(cond
((or volume velocity)
(prompt
"\nYou must enter diameter or Width x Depth ..."
)
)
(t
(prompt "\nYou must indicate CFMs or FPM..")
)
)
)
) ; end cond stmt
(show_me)
(princ)
;friction ; return flag, nil if failed
;;=-=-=-=-=-=-=-=-==-=-=-==-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=
(while loop
(setq width (getreal "\nEnter new duct width: ") ;WB
depth (getreal "\nEnter new duct depth: ")
)
(if (or width depth)
(cond
((= width t)
(setq depth (rnd_to_sqr diam width)
diam (make_round width depth)
velocity (/ volume (dia2area diam))
friction (find_fric)
)
(show_me)
)
((= depth t)
(setq width (rnd_to_sqr diam depth)
diam (make_round width depth)
velocity (/ volume (dia2area diam))
friction (find_fric)
)
(show_me)
)
)
)
(setq loop nil)
) ;end while
) ; end defun
(defun c:test (/ friction)
(while (setq friction (duct_calc)))
(print friction)
(princ)
)
-
Without post the entire code again, here's the bottom of it.
(prompt
"\nYou must enter diameter or Width x Depth ..."
)
)
(t
(prompt "\nYou must indicate CFMs or FPM..")
)
)
)
) ; end cond stmt
(show_me)
;; added this ---------------------------------
(setq ask (getint "\nRun this again? (1=Yes <No>): "))
(if ask (duct_calc))
;; added this ---------------------------------
(princ)
;; remove from here down ----------------------
;friction ; return flag, nil if failed
;;=-=-=-=-=-=-=-=-==-=-=-==-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;;; (while (setq width (getreal "\nEnter new duct width: ")) ;WB
;;; (setq depth (getreal "\nEnter new duct depth: ")
;;; )
;;; (if (or width depth)
;;; (cond
;;; ((= width t)
;;; (setq depth (rnd_to_sqr diam width)
;;; diam (make_round width depth)
;;; velocity (/ volume (dia2area diam))
;;; friction (find_fric)
;;; )
;;; (show_me)
;;; )
;;; ((= depth t)
;;; (setq width (rnd_to_sqr diam depth)
;;; diam (make_round width depth)
;;; velocity (/ volume (dia2area diam))
;;; friction (find_fric)
;;; )
;;; (show_me)
;;; )
;;; )
;;; )
;;; ; (setq loop nil)
;;; ) ;end while
) ; end defun
-
Also you might want to add the names of all those nested defun's to the local variable list.
-
Thanks for the help Mark. But what I am trying to accomplish is that when I input the known variables it calcs the rest, then based on that, I want to loop thru only width and depth (using the diam, volume, velocity and friction that was gathered) that way I only have to enter eitherwidth or depth not both
(setq A(rnd_to_sqr diam B))
if I enter A (since I already know diam), this will calc the other side--then, if I can't use that size, I'll try another..
-
(defun duct_calc
(/ friction volume velocity diam width depth area_sqft loop)
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;; Local Functions
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;
;; returns the square side dimension equivelant of rnd duct
(defun rnd_to_sqr (dia ; dia of round duct
a ; side A of square duct
/ loop fuzz b)
(if (= (type a) 'int) ; make sure A is a REAL
(setq a (* a 1.0))
)
(setq b a ; B is target
fuzz 0.001
loop t
)
;; Returns Side B of square duct
(while loop
(setq dia2
(* 1.3
(exp (/ (log (/ (expt (* a b) 5) (expt (+ a b) 2))) 8))
)
)
(if (equal dia2 dia fuzz)
(setq loop nil) ; done
(setq b (* b (/ dia dia2)))
)
)
(princ)
b
) ; end defun
;; given the area in square feet returns the diameter
(defun area2dia (sf_area / square)
(setq square (sqrt (* sf_area 144.0)))
(* 1.3
(exp
(/ (log (/ (expt (* square square) 5.0)
(expt (+ square square) 2.0)
)
)
8.0
)
)
)
) ; end defun
;; given diameter returns the side dimension
(defun dia2sq (dia)
;;(* dia 0.914774703)
;;(*(sqrt area_sqft)12)
(setq depth (* (sqrt area_sqft) 12)) ; CAB
(rnd_to_sqr dia depth) ; CAB
)
;; given the diameter returns the area in sq ft
(defun dia2area (dia)
;;(/ (* 0.7854 (expt dia 2.0)) 144.0)
(/ (* pi (expt (/ dia 2.0) 2.0)) 144.0) ; CAB
)
;;given a square duct, make it round<=====added this
(defun make_round (w d)
(* 1.3
(exp
(/ (log (/ (expt (* w d) 5.0)
(expt (+ w d) 2.0)
)
)
8.0
)
)
)
)
;; given the diameter returns the area in sq ft
(defun veloc2press (vel)
(expt (/ vel 4005.00) 2)
)
;; calc friction
(defun find_fric ()
(/ (* 0.109136 (expt volume 1.9)) (expt diam 5.02))
)
;;print results
(defun show_me ()
(textscr)
(mapcar '(lambda (x)
(prompt (strcat "\n"
(car x)
(if (cdr x)
(rtos (cdr x) 2 2)
"X"
)
)
)
)
(list (cons "Diameter " diam)
(cons "Width " width)
(cons "Depth " depth)
(cons "Volume " volume)
(cons "Velocity " velocity)
(cons "Friction " friction)
)
)
)
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;================================================================
;;; Start of Routine
;;;================================================================
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;; Get User Input
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
(prompt "\nEnter known values. Press Enter if not known. ")
(setq diam (getreal "\nEnter duct diameter: "))
(if (null diam) ; skip if diameter entered
(setq width (getreal "\nEnter duct width: ")
depth (getreal "\nEnter duct depth: ")
)
)
(setq volume (getreal "\nEnter total CFM'S: ")
loop t
)
(if (null (and (or diam (and width depth)) volume))
(setq friction (getreal "\nEnter FRICTION value: "))
)
(if (null (and (or diam (and width depth)) volume))
(setq velocity (getreal "\nEnter Velocity in FPM: "))
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;; Process User Input
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
(cond
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
((and friction diam)
(setq volume (exp
(/ (log (/ (* friction (expt diam 5.02)) 0.109136))
1.9
)
)
area_sqft (dia2area diam)
width (dia2sq diam)
velocity (/ volume area_sqft)
)
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
((and friction volume)
(setq diam (exp
(/ (log (/ (* 0.109136 (expt volume 1.9)) friction))
5.02
)
)
area_sqft (dia2area diam)
width (dia2sq diam)
velocity (/ volume area_sqft)
)
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
((and diam volume)
(setq area_sqft (dia2area diam)
width (dia2sq diam)
velocity (/ volume area_sqft)
friction (find_fric)
)
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
((and diam velocity)
(setq area_sqft (dia2area diam)
width (dia2sq diam)
volume (* area_sqft velocity)
friction (find_fric)
)
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
((and width depth friction)
(setq diam (make_round width depth)
volume (exp
(/ (log (/ (* friction (expt diam 5.02)) 0.109136))
1.9
)
)
velocity (/ volume (dia2area diam))
)
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
((and width depth volume)
(setq diam (make_round width depth)
velocity (/ volume (dia2area diam))
friction (find_fric)
)
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
((and width depth velocity)
(setq diam (make_round width depth)
volume (* (dia2area diam) velocity)
friction (find_fric)
)
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
((and volume velocity)
(setq area_sqft (/ (/ volume velocity) 0.914774703)
diam (area2dia area_sqft)
width (dia2sq diam)
friction (find_fric)
)
)
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
(t
(cond
((or volume velocity)
(prompt
"\nYou must enter diameter or Width x Depth ..."
)
)
(t
(prompt "\nYou must indicate CFMs or FPM..")
)
)
)
) ; end cond stmt
(show_me)
(setq loop 1)
(princ)
;friction ; return flag, nil if failed
;;=-=-=-=-=-=-=-=-==-=-=-==-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=
(while loop
(cond ((setq width (getreal "\nEnter new duct width: "))
(setq depth (rnd_to_sqr diam width)
diam (make_round width depth)
velocity (/ volume (dia2area diam))
friction (find_fric)
)
(show_me)
)
((setq depth (getreal "\nEnter new duct depth: "))
(setq width (rnd_to_sqr diam depth)
diam (make_round width depth)
velocity (/ volume (dia2area diam))
friction (find_fric)
)
(show_me)
)
(T (setq loop nil))
)
) ;end while
)
-
Sensational!!! I was close..but no cigar...:D