getkword not honoring keywords

getkword not honoring keywords

Anonymous
Not applicable
2,228 Views
5 Replies
Message 1 of 6

getkword not honoring keywords

Anonymous
Not applicable

Hi,

 

I'm trying to learn how to use the getkword function, and I can't figure out why it does not seem to allow me to select the keywords I set up with initget.

According to the getkword page on the Autodesk help pages, it should behave like this:

 

(initget 1 "Yes No")
nil

(setq x (getkword "Are you sure? (Yes or No) "))
Are you sure? (Yes or No) yes
"Yes"

 What I am getting is this:

 

(initget 1 "Yes No")

nil

 

(setq x (getkword "Are you sure (Yes or No) "))

Are you sure (Yes or No) Yes

 

Invalid option keyword.

Are you sure (Yes or No) No

 

Invalid option keyword.

 

I can't find any help on this.  Any ideas why this is happening?

0 Likes
Accepted solutions (1)
2,229 Views
5 Replies
Replies (5)
Message 2 of 6

stevor
Collaborator
Collaborator

Getkword will work, many examples found by a search,

Or someone will explain it all here, in a minute.

My crew was a quicker version, so I used the grread method,

which returns a logical T or nil, for true of false.

This is a long version of it:

 

 ; input yes no AusCadd.com, SCG
 (defun I_YN (QSTR YNFLG / TF NF IT IG IK) ;
  (princ (strcat QSTR (if YNFLG " N or < Y > " " Y or < N > ")))
  (while (and (setq IT (car (setq IG (grread T)))) (/= 6 IT )
              (setq IK (cadr IG)) ; key maybe
              (not (and (= 2 IT) (or    ; key board
                (setq NF (or (= 110 IK) (= 78 IK) ) )
                (setq TF (or (= 121 IK) (= 89 IK) ) )
                (= 13 IK)   (= 32 IK) ) )  )
               (not (= IT 11)) ) ) ; end while  ; mou R
   (setq YNFLG (cond  (NF nil)  (TF t)  (t YNFLG) ) )
   (princ (if YNFLG " Y " " N "))  YNFLG )
 ; (setq Flag (I_YN " @ i_yn subr0 " nil))

S
0 Likes
Message 3 of 6

john.uhden
Mentor
Mentor

(initget <whatever>) always returns nil, so don't worry about that.  If it really bothers you, or is part of a lengthy (and ...) then you can use (not (initget ...)).

The rest of the behavior you supplied does not make sense.  It appears you were testing the exact example from the help on getkword.

It "should" work exactly as advertised.

 

Were there other lines of code between the (initget) and the (getkword) that you omitted to post?

John F. Uhden

0 Likes
Message 4 of 6

vladimir_michl
Advisor
Advisor

This should work fine. Please check if the space in initget is really a plain space, not some special character (like hard-space).

 

Vladimir Michl, www.cadstudio.cz  www.cadforum.cz

 

0 Likes
Message 5 of 6

DannyNL
Advisor
Advisor

To be honest, I'm experiencing the same issues as well. Didn't notice it before, but if you have different multiple initget statements only the first will be honored and persistent. I have not found a solution yet.

 

See example below.

 

Command: (initget "Yes No")
nil

Command: (getkword "\nOption [Yes/No]: ")

Option [Yes/No]: y
"Yes"

Command: (initget "Stop Go")
nil

Command: (getkword "\nOption [Stop/Go]: ")

Option [Stop/Go]: s

Invalid option keyword.

Option [Stop/Go]: Stop

Invalid option keyword.

Option [Stop/Go]: Go

Invalid option keyword.

Option [Stop/Go]: y
"Yes"
0 Likes
Message 6 of 6

DannyNL
Advisor
Advisor
Accepted solution

I've found an older post describing exactly this problem. Although it shouldn't happen, it appears it is a commandline problem only. When using in a routine the keywords will be honored from the last initget.

 

For the older post >>> Click Here <<<

 

I've checked with a small routine and then it works fine and as expected.

 

(defun c:Test ()
   (initget 1 "Yes No")
   (setq T_Answer1 (getkword "\nSelect option [Yes/No]: "))
   (initget 1 "Stop Go")
   (setq T_Answer2 (getkword "\nSelect option [Stop/Go]: "))
   (princ (strcat "\nAnswer1: " T_Answer1 " / Answer2: " T_Answer2))
   (princ)
)