phuynh Posted April 30, 2020 Share Posted April 30, 2020 (edited) Need help to set "rScale" variable between 0 and 1 How can I limit user to enter real number that greater 0 but less than or equal 1 ? Quote (setq rScale (getreal (strcat "\nEnter scale ratio: "))) Thanks! Edited April 30, 2020 by phuynh Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted April 30, 2020 Share Posted April 30, 2020 One way. (setq time t) (while time (setq x (getreal "\nEnter value between 0.0 and 1.0: ")) (if (and (> x 0.0) (< x 1.0)) (setq time nil) ) ) Quote Link to comment Share on other sites More sharing options...
phuynh Posted April 30, 2020 Author Share Posted April 30, 2020 Thank you for reply, It 's work great! Thanks, Quote Link to comment Share on other sites More sharing options...
Jonathan Handojo Posted April 30, 2020 Share Posted April 30, 2020 Here's another... Not tested as it's typed away from CAD. (while (null (< 0.0 (setq rScale (getreal "\nSpecify value: ")) 1.0)) (princ "\nValue is not between 0 and 1") ) 1 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 30, 2020 Share Posted April 30, 2020 I always like to give the user a way to exit without forcing an error with Esc, e.g.: (while (and (setq x (getreal "\nSpecify a number between 0 and 1: ")) (not (<= 0.0 x 1.0)) ) (princ "\nNumber must be between 0 and 1.") ) (if x ;; do stuff ) 1 Quote Link to comment Share on other sites More sharing options...
phuynh Posted April 30, 2020 Author Share Posted April 30, 2020 Jonathan, You code also work great! Thanks! Quote Link to comment Share on other sites More sharing options...
phuynh Posted April 30, 2020 Author Share Posted April 30, 2020 Lee Mac, I am big fan of you! and I learn lot from you and community. I work on lisp code that set up axonometry (dimetric) view point in 3d space. it is work but it sloppy, can you help? Quote Link to comment Share on other sites More sharing options...
lido Posted May 1, 2020 Share Posted May 1, 2020 Try this ;;Get a real number x lying the closed interval [a b] ;; (_getreal 0 1 0.5 "\nSpecify a number between 0 and 1 <0.5>: ") ;; (_getreal 0 1 nil "\nSpecify a number between 0 and 1: ") (defun _getreal (a b default mesg / x) ;; (if (not default) (initget 1)) ;;Optional (setq x (vl-catch-all-apply (function getreal) (list mesg))) (cond ( (and default (not (numberp x))) default) ;;<Enter>, <Space>, <Esc> ( (and default (numberp x) (or (< x a) (> x b))) (_getreal a b default mesg)) ( (and (not default) (or (not (numberp x)) (and (numberp x) (or (< x a) (> x b)))) ) (_getreal a b nil mesg) ) (T x) ) ) ;;_getreal Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.