Hi all,
I'm a little puzzled. I would like to eliminate a mouse click in my program. I use getstring to allow the user to either enter in an integer or a distance used for labeling in a drawing, but I could eliminate the need for the user to then click an option that completes the label if I only knew how to determine if the entry is an integer (such as 5 or 15) or a distance (such as 24" or 36").
I could swear I did this before but I don't remember how. Maybe something like "isdist" but again, I don't remember exactly how I did it.
Any help is greatly appreciated. Thank you in advance.
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
@mid-awe wrote:Hi all,
I'm a little puzzled. I would like to eliminate a mouse click in my program. I use getstring to allow the user to either enter in an integer or a distance used for labeling in a drawing, but I could eliminate the need for the user to then click an option that completes the label if I only knew how to determine if the entry is an integer (such as 5 or 15) or a distance (such as 24" or 36").
I could swear I did this before but I don't remember how. Maybe something like "isdist" but again, I don't remember exactly how I did it.
Any help is greatly appreciated. Thank you in advance.
Maybe.
(defun _correctVal ( / val ) (setq val (getstring "\nEnter Value: ")) (if (or (eq val "") (not (eq (type (read val)) 'INT)) ) (progn (princ "Null Input Try again") (_correctVal)) (print (if (wcmatch val "*\"") (list "Distance" val) (list "Integer" val))) ) (princ) )
@mid-awe wrote:.... I would like to eliminate a mouse click in my program. I use getstring to allow the user to either enter in an integer or a distance used for labeling in a drawing, but I could eliminate the need for the user to then click an option that completes the label if I only knew how to determine if the entry is an integer (such as 5 or 15) or a distance (such as 24" or 36").
....
You can turn the string into an integer, and the integer back into a string, and if they're the same string, the Text represents an integer.
(defun TextInt (txt) (= txt (itoa (atoi txt))))
Command: (setq x (getstring))
[type in:] 24"
"24\""
Command: (TextInt x)
nil
Command: (setq x (getstring))
[type in:] 5
"5"
Command: (TextInt x)
T
Or directly, without the variable:
Command: (TextInt "15")
T
Command: (TextInt "3'-4 1/2")
nil
Command: (TextInt "13.25")
nil
Command: (TextInt "13579")
T
Command: (TextInt "this is a test")
nil
Thank you, that'll do nicely
I believe originally I used an initget bit or something, but this is a great solution that I never considered and it is simple enough for my taste. Thanks again.
@mid-awe wrote:Thank you, that'll do nicely....
You're welcome. And I thought of another way to do it:
(defun TextInt (txt) (not (wcmatch txt "*@*,*.*")))
It just checks whether there are no alphabetic or non-alphanumeric characters in the string, returning T only if all characters are numeric.
For a while there i thought you want to prevent the user from supplying the wrong value. where Integers and unit inch is the only valid value.
(defun _correctVal ( / val ) (setq val (getstring "\nEnter Value: ")) (if (or (eq val "") (not (eq (type (read val)) 'INT)) ) (progn (princ "Null Input Try again") (_correctVal)) (setq val (if (wcmatch val "*\"") (list "Distance" val) (list "Integer" val))) ) ) (defun c:test () (setq ValueToUSe (_correctVal)) (if (eq (car ValueToUSe) "Integer") (princ "\nDo this for Integer") (princ "\nDo this for Distance") ) (princ) )
If you dont have any use for the inch input (") why not stick with getint?
One more suggestion:
ATOI of a string that contains other than numbers will return 0 (which is true).
However DISTOF works well especially in architectural mode.
Don't bother with ATOF.
?
Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.
@scot-65 wrote:One more suggestion:
ATOI of a string that contains other than numbers will return 0 (which is true).
....
Not quite true, actually.... When applied to a string that starts with other than numbers, (atoi) always returns 0. But a string that starts with any numerical character(s), even if it contains other than numbers later on, will return an integer of just the initial number(s), ignoring the rest.
Command: (atoi "abc123")
0
Command: (atoi "123abc")
123
I'm using this for many application but the one that triggered my question was on an "insert" block with label for plant purchase sizes are either in inches for boxed or gallons. If 24", for example, is typed for the size then I can deduce that it is a boxed order or if an integer is entered then I know it is in gallons.
@mid-awe wrote:I'm using this for many application but the one that triggered my question was on an "insert" block with label for plant purchase sizes are either in inches for boxed or gallons. If 24", for example, is typed for the size then I can deduce that it is a boxed order or if an integer is entered then I know it is in gallons.
Comment or Question?