Hi guys-
So I have a lisp routine I'm making and I having problems with the getkword/initget function. I want my users to be able to just click Enter to select the default option. I haven't set a bit to leave the option open and I used [ ] < > to set the default value and when I hit enter I get null as my result. Dose anyone know what I'm doing wrong? Please help.
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
The return will be nil if the user just hits enter. You must program for the occasion following a similar syntax to that given below.
(setq tempAgl (getint "\Specify rotation angle increments. <5>: "))
(if (= tempAgl nil)
(setq tempAgl 5)
)
You can extend that for enhanced operation, for example to save any prior value entered and offer that as the default on subsequent use, rather than always offering the same default. There are a couple of ways to do that, in this case with integer values as in the other reply, if you want an initial default of 5:
(setq IntVal
(cond
( (getint ; returns nil on Enter
(strcat
"\nEnter integer value: <"
(if IntVal (itoa IntVal) "5"); offer default [prior value if any]
">: "
); strcat
); getint
); end User-types-integer condition
(IntVal); User hit Enter, and there's a prior value [returns nil if not]
(5); User hit Enter without a prior value [use initial default]
); cond
); setq
Or set the initial default first:
(if (not IntVal) (setq IntVal 5))
(setq IntVal
(cond
((getint (strcat "\nEnter integer value: <" (itoa IntVal) ">: "))); nil on Enter
(IntVal); User hit Enter [keep current value, whether initial default or prior User value]
); cond
); setq
Neither of those uses (initget)/(getkword), but you might have a use for (initget) in that situation, for example to prevent the User from typing 0 or a negative number. The (getkword) function is more often of value when there are multiple options to choose from rather than a single default value to accept or not, and/or when the value is a text string, for example a Layer name. You'll find a lot of examples in this Forum -- just put (getkword) in the Search window.
So I just figured out that I can apply this technique to the getkword function, and it solved a huge problem I was having. again thanks. 🙂
Can't find what you're looking for? Ask the community or share your knowledge.