Sticky initget? Or getkword recognizing only the first initget call?

Sticky initget? Or getkword recognizing only the first initget call?

Anonymous
Not applicable
2,325 Views
11 Replies
Message 1 of 12

Sticky initget? Or getkword recognizing only the first initget call?

Anonymous
Not applicable

Can anyone explain why the following is happening?

 

Command: (initget "Alpha Beta Gamma")
nil

Command: (getkword "\nChoose Alpha/Beta/Gamma: ")

Choose Alpha/Beta/Gamma: a
"Alpha"

Command: (initget "Apples Berries Cocoa")
nil

Command: (getkword "\nChoose Apples/Berries/Cocoa: ")

Choose Apples/Berries/Cocoa: a
"Alpha"

Command: (getkword "\nChoose Apples/Berries/Cocoa: ")

Choose Apples/Berries/Cocoa: b
"Beta"

Command: (getkword "\nChoose Apples/Berries/Cocoa: ")

Choose Apples/Berries/Cocoa: c

Invalid option keyword.

Choose Apples/Berries/Cocoa: g
"Gamma"

 

Many thanks in advance,

David Field

0 Likes
Accepted solutions (2)
2,326 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable

I copy/pasted code from another initget-related post and it worked like I expected, so I thought maybe it had something to do with using three keywords, for some reason. Grasping at straws here...

So I tried it again in a new drawing, with just two keywords - same behavior.

 

Command:
Command:

Command:
Command: (initget "Yes No")
nil

Command: (setq ans (getkword "Yes or No? "))
Yes or No? y
"Yes"

Command: (setq ans (getkword "Yes or No? "))
Yes or No? n
"No"

Command: (setq ans (getkword "Yes or No? "))
Yes or No? y
"Yes"

Command: (setq ans (getkword "Yes or No? "))
Yes or No? you

Invalid option keyword.
Yes or No? noah

Invalid option keyword.
Yes or No? n
"No"

Command: (setq newans (getkword "You or Noah? "))
You or Noah? y
"Yes"

Command: (setq newans (getkword "You or Noah? "))
You or Noah? n
"No"

Command: (setq newans (getkword "You or Noah? "))
You or Noah? you

Invalid option keyword.
You or Noah? noah

Invalid option keyword.
You or Noah? y
"Yes"

Command: (initget "You Noah")
nil

Command: (setq newans (getkword "You or Noah? "))
You or Noah? y
"Yes"

Command: (setq newans (getkword "You or Noah? "))
You or Noah? noah

Invalid option keyword.
You or Noah? you

Invalid option keyword.
You or Noah? no
"No"

Command: (setq newans (getkword "You or Noah? "))
You or Noah? yes
"Yes"

 

0 Likes
Message 3 of 12

kerry_w_brown
Advisor
Advisor

 

Hi David

 

The initget bit values and keywords apply only to the next user-input function call.

 

You seem to be missing a couple of initget(...) statements

 

Regards,

 


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes
Message 4 of 12

Anonymous
Not applicable
No, I don't think I am. Line 6 in the first example, I called (initget "Apples Berries Cocoa"), and in line 35 in the 2nd example, I called (initget "You Noah") after messing around with entering invalid keywords several times.
0 Likes
Message 5 of 12

kerry_w_brown
Advisor
Advisor

 

Sorry, I can't reproduce your issue.

 

Which build are you working with ?

 


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes
Message 6 of 12

CADaSchtroumpf
Advisor
Advisor
Accepted solution

I can reproduce this phenomenon if I execute line by line, from the command line, it's strange. . .
However in an encapsulated code, the problem does not reproduce.
Example:

 

((lambda ( / l omega)
	(setq l '("Alpha Beta Gamma" "Apples Berries Cocoa" "Alan Bob Ghost" "Sumerians Egyptians Romans Mayans"))
	(setq omega (mapcar '(lambda (x) (initget x) (princ (getkword (strcat "\nChoose[" (vl-string-translate " " "/" x) "]: ")))) l))
	(print omega)
	(prin1)
))

The variable contains omega although the list of choices.

Message 7 of 12

Anonymous
Not applicable

acadver = "20.0s (LMS Tech)"

Civil 3D 2015 service pack 3

 

Here's a simplified, color coded, line numbered command line sequence:

 

1   Command: (initget "Yes No")
2   nil

3   Command: (getkword "Yes or No? ")
4   Yes or No? y
5   "Yes"

6   Command: (initget "You Me")
7   nil

8   Command: (getkword "You or Me? ")
9   You or Me? you

10  Invalid option keyword.
11  You or Me? me

12  Invalid option keyword.
13  You or Me? no
14  "No"

15  Command: (getkword "You or Me? ")
16  You or Me? y
17  "Yes"

 

Maybe it's time to learn to use lambda...

0 Likes
Message 8 of 12

ВeekeeCZ
Consultant
Consultant
Accepted solution

@Anonymous wrote:

acadver = "20.0s (LMS Tech)"

Civil 3D 2015 service pack 3

 

Here's a simplified, color coded, line numbered command line sequence:

 

 

...

Maybe it's time to learn to use lambda...


It is failing where this is used in a code? Never to me!


If you use this is regular way... it never fails. Btw you should use a standardized format - then it's clickable.

 

btw Can you reproduce this if you wrap these with (progn)? 

(progn (initget "You Noah") (princ (getkword "\nYou or Noah? [You/Me]: ")))

I can't.

 

 

Spoiler
(defun c:test ()

  (initget 1 "Yes No")
  (princ (getkword "\nYes or No? [Yes/No]: "))

  (initget "You Me")
  (princ (getkword "\nYou or Me? [You/Me]: "))

  (initget "You Noah")
  (princ (getkword "\nYou or Noah? [You/Me]: "))

  (initget "Apples Berries Cocoa")
  (princ (getkword "\nChoose [Apples/Berries/Cocoa]: "))

  (initget "Alpha Beta Gamma")
  (princ (getkword "\nChoose [Alpha/Beta/Gamma]: "))

  (princ)
)
Spoiler
Command: TEST

Yes or No? [Yes/No]: y
Yes
You or Me? [You/Me]: y
You
You or Noah? [You/Me]: y
You
Choose [Apples/Berries/Cocoa]: a
Apples
Choose [Alpha/Beta/Gamma]: a
Alpha

Command:
Command:
TEST

Yes or No? [Yes/No]: y
Yes
You or Me? [You/Me]: m
Me
You or Noah? [You/Me]: m

Invalid option keyword.

You or Noah? [You/Me]: n
Noah
Choose [Apples/Berries/Cocoa]: c
Cocoa
Choose [Alpha/Beta/Gamma]: g
Gamma

Command:
Command:
TEST

Yes or No? [Yes/No]: n
No
You or Me? [You/Me]: me
Me
You or Noah? [You/Me]: you
You
Choose [Apples/Berries/Cocoa]: cocoa
Cocoa
Choose [Alpha/Beta/Gamma]: b
Beta

Command:

No need for lambda on regular basis. As @CADaSchtroumpf said:

 

I can reproduce this phenomenon if I execute line by line, from the command line, it's strange. . .
However in an encapsulated code, the problem does not reproduce.

 

0 Likes
Message 9 of 12

Anonymous
Not applicable

No, I'm in the habit of pasting each line of code to the command line as I write to make sure it works on its own. This is the first time I've run into a function that doesn't work that way.

 

You're right though, it works fine wrapped in a progn. From what you say it should also work fine when I run the finished routine, but I'll make a note of using progn just in case.

 

Still confused by the fact this doesn't work if entered line by line at the command line, but okay, I can accept it just doesn't.

 

Thanks all!

0 Likes
Message 10 of 12

Anonymous
Not applicable

By the way, what did you mean by a standardized format?

0 Likes
Message 11 of 12

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

By the way, what did you mean by a standardized format?


(getkword "\nChoose [Alpha/Beta/Gamma]: ")
;
; or if there is a default option:
; (getkword "\nChoose [Alpha/Beta/Gamma] <Beta>: ")
0 Likes
Message 12 of 12

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

No, I'm in the habit of pasting each line of code to the command line as I write to make sure it works on its own....


Frankly... if there is a rule, that certain command works just for the following function... it's suspicious to me - not automatical expecting that it works in command line as well. This applies for (initget) or (initcommandversion)... Just caution -- but it should work 🙂 Maybe when a delay is too long, it does not.

0 Likes