View Full Version : Help with a conditional statement
tflaherty
2005-05-11, 08:33 PM
I'm trying to write my own routine to draw circular stairs, since I can't find one out there.
Here's what I've got so far:
(defun circular (/ cp isr ws osr)
(setq cp (getpoint "\nSelect point for center of stair radius: "))
(setq isr (getdist "\nSpecify inside radius of stairs (min 3'-6\"): "))
(cond (>= irs 42)
(setq ws (getdist "\nWidth of stairs: "))
(setq osr (+ isr ws))
(command "circle" cp isr)
(command "circle" cp osr)
(command "line" cp (strcat "@" (+ (rtos isr) 12) "<0") "")
(princ))
What I'm unsure of is how to handle the conditional statement after the user specifies the inside radius. I want it to verify the user's input is 3'-6" or greater, if so it goes on to the next input prompt etc. If it doesn't I want it to return a prompt saying "Invalid input, try again" or something like that.
I'm not sure if I'm going about this the right way.
Also, is there a way to use the "last" option with offset like you can with the line command.
Thanks for all your help.
The one thing I see wrong with your conditional is the variable name. You specify the name to be "isr" in your "setq" statement but use "irs" in your conditional.
You could use the "while" conditional to repeat the request for the inside radius until it is equal to or larger than your required distance.
(setq isr (getdist "\nSpecify inside radius of stairs (min 3'-6\"): "))
(while (< isr 42)
(alert "Inside radius must be a minimum of 3'-6\"")
(setq isr (getdist "\nSpecify inside radius of stairs (min 3'-6\"): "))
)
tyshofner
2005-05-11, 08:51 PM
You could just use an IF statement rather than a COND. It would be something like this:
(defun circular (/ cp isr ws osr)
(setq cp (getpoint "\nSelect point for center of stair radius: "))
(setq isr (getdist "\nSpecify inside radius of stairs (min 3'-6\"): "))
(if (>= isr 42)
(progn
(setq ws (getdist "\nWidth of stairs: "))
(setq osr (+ isr ws))
(command "circle" cp isr)
(command "circle" cp osr)
(command "line" cp (strcat "@" (+ (rtos isr) 12) "<0") "")
)
(prompt "\nInvalid input, please try again.")
)
(princ)
)
Ty :mrgreen:
RobertB
2005-05-11, 08:51 PM
I'm trying to write my own routine to draw circular stairs, since I can't find one out there.
...
What I'm unsure of is how to handle the conditional statement after the user specifies the inside radius. I want it to verify the user's input is 3'-6" or greater, if so it goes on to the next input prompt etc. If it doesn't I want it to return a prompt saying "Invalid input, try again" or something like that.
I'm not sure if I'm going about this the right way.
Also, is there a way to use the "last" option with offset like you can with the line command.
Thanks for all your help.
(defun circular (/ cp isr ws osr)
(setq cp (getpoint "\nSelect point for center of stair radius: "))
(setq isr (getdist "\nSpecify inside radius of stairs (min 3'-6\"): "))
(cond ((>= irs 42)
(setq ws (getdist "\nWidth of stairs: "))
(setq osr (+ isr ws))
(command "circle" cp isr)
(command "circle" cp osr)
(command "line" cp (strcat "@" (+ (rtos isr) 12) "<0") "")
)
(T (prompt "\nSlap!"))
)
(princ))
(command "._Offset" 1.0 (cons (entlast) (list (getvar "LastPoint"))) '(0.0 0.0 0.0) "")
scwegner
2005-05-11, 08:54 PM
(defun circular (/ cp ws osr marker)
(setq cp (getpoint "\nSelect point for center of stair radius: "))
(while
(not marker)
(setq isr (getdist "\nSpecify inside radius of stairs (min 3'-6\"): "))
(cond
(
(>= irs 42); test if true
(setq ws (getdist "\nWidth of stairs: "))
(setq osr (+ isr ws))
(command "circle" cp isr)
(command "circle" cp osr)
(command "line" cp (strcat "@" (+ (rtos isr) 12) "<0") "")
(setq marker 1)
);first condition set
(t ;force true
(princ "\nRadius must be greater than 3' 6\"")
);second condition set
);close cond
);close while
(princ)
)
The cond statement needed another set of parens to group the test with the things you want done if true and another close parens to finish of the cons. You also didn't have any other options -just what you wanted to happen if the person entered a usable number.
The blue while additions make it loop until an acceptable number is entered. While runs until the first argument is true, so in this case, until the first cons statement is true and sets a value for the marker variable.
To make isr available the next time around,
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.