Author Topic: Question about "initget"  (Read 5483 times)

0 Members and 1 Guest are viewing this topic.

MeasureUp

  • Bull Frog
  • Posts: 465
Question about "initget"
« on: April 18, 2013, 11:59:03 PM »
I have used "initget" a lot without any problems until I am working on a new code.
In the code, I set two groups of keyword by using "initegt" and this is a sample:

Code: [Select]
(initget "A B C")
(setq ABC (getstring "\nSelect a Letter (A/B/C): "))
(if (eq ABC "A")
(prompt "Print letter A.")
); end if

...

(initget "D E F")
(setq DEF (getstring "\nSelect a Letter (D/E/F): "))

If I enter "D", "E" or "F" in the line of "setq DEF...", it returns "Invalid option keyword."
If I enter "A", "B" or "C" it accepts.
Is there anything that I did wrong?
Your helps are much appreciated.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Question about "initget"
« Reply #1 on: April 19, 2013, 12:08:02 AM »
Try this:
Code: [Select]
(initget "D E F")
(setq DEF (getkword "\nSelect a Letter (D/E/F): "))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MeasureUp

  • Bull Frog
  • Posts: 465
Re: Question about "initget"
« Reply #2 on: April 19, 2013, 01:33:27 AM »
Sorry, CAB.
The "get-" function in my code was "getkword" instead of "getstring".
If I enter "D", "E" or "F" in the line of "setq DEF...", it returns "Invalid option keyword."
Is there anything in the code incorrect?

Code: [Select]
(initget "A B C")
(setq ABC (getkword "\nSelect a Letter (A/B/C): "))
(if (eq ABC "A")
(prompt "Print letter A.")
); end if

...

(initget "D E F")
(setq DEF (getkword "\nSelect a Letter (D/E/F): "))

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Question about "initget"
« Reply #3 on: April 19, 2013, 03:55:42 AM »
Sorry, CAB.
The "get-" function in my code was "getkword" instead of "getstring".
If I enter "D", "E" or "F" in the line of "setq DEF...", it returns "Invalid option keyword."
Is there anything in the code incorrect?

Code: [Select]
(initget "A B C")
(setq ABC (getkword "\nSelect a Letter (A/B/C): "))
(if (eq ABC "A")
(prompt "Print letter A.")
); end if

...

(initget "D E F")
(setq DEF (getkword "\nSelect a Letter (D/E/F): "))

Works for me.

BTW. See the square brackets .. try Right-click at the prompt to see an interactive menu with A, B, C as menu items
« Last Edit: April 19, 2013, 04:03:28 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Question about "initget"
« Reply #4 on: April 19, 2013, 02:19:11 PM »
You could also do something like this to "remember" your last selection.

Code: [Select]
(or *global* (setq *global* "A"))
(initget "A B C")
(alert (setq *global* (cond ((getkword (strcat "\n[A/B/C] <" *global* ">: ")))
    (*global*)
      )
       )
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

HasanCAD

  • Swamp Rat
  • Posts: 1423
Re: Question about "initget"
« Reply #5 on: April 20, 2013, 05:50:02 AM »
Prompting with a Default Option
http://www.lee-mac.com/promptwithdefault.html

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Question about "initget"
« Reply #6 on: April 20, 2013, 07:39:29 AM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MeasureUp

  • Bull Frog
  • Posts: 465
Re: Question about "initget"
« Reply #7 on: April 21, 2013, 09:33:05 PM »
Thanks to everyone for the rich info.
However, I couldn't figure out what was wrong in my code.
It forces the user enter "A", "B" or "C" in the line
Code: [Select]
(setq DEF (getkword "\nSelect a Letter (D/E/F): "))
Otherwise it returns "Invalid option keyword."
It looks likely it holds the variable active:
Code: [Select]
(setq ABC (getkword "\nSelect a Letter (A/B/C): "))

BTW, I use AutoCAD Mech v2013.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Question about "initget"
« Reply #8 on: April 22, 2013, 12:33:49 AM »
You must use  a new initget before each getkword.
Did you use this (initget "D E F") just before the getkword ?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MeasureUp

  • Bull Frog
  • Posts: 465
Re: Question about "initget"
« Reply #9 on: April 22, 2013, 02:51:21 AM »
You must use  a new initget before each getkword.
Did you use this (initget "D E F") just before the getkword ?

Yes, I use a new initget as shown on my code in the previous post:
Code: [Select]
...
(initget "D E F")
(setq DEF (getkword "\nSelect a Letter (D/E/F): "))

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Question about "initget"
« Reply #10 on: April 22, 2013, 07:03:55 AM »
To clarify, try the following program:

Code: [Select]
(defun c:doit ( )
    (initget 1 "D E F")
    (getkword "\nChoose a Letter [D/E/F]: ")

    (initget 1 "A B C")
    (getkword "\nAnd Another [A/B/C]: ")
    (princ)
)

MeasureUp

  • Bull Frog
  • Posts: 465
Re: Question about "initget"
« Reply #11 on: April 22, 2013, 06:45:05 PM »
To clarify, try the following program:

Code: [Select]
(defun c:doit ( )
    (initget 1 "D E F")
    (getkword "\nChoose a Letter [D/E/F]: ")

    (initget 1 "A B C")
    (getkword "\nAnd Another [A/B/C]: ")
    (princ)
)

Thanks, Lee.
I tested it and this is what I got:
Quote
Command: DOIT

Choose a Letter [D/E/F]: e

And Another [A/B/C]: b

If I copy this line
Code: [Select]
(getkword "\nAnd Another [A/B/C]: ")
to command prompt then enter letter "A", "B" or "C" (without quotation marks) it returns "Invalid option keyword" again.

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Question about "initget"
« Reply #12 on: April 22, 2013, 06:46:40 PM »
If I copy this line
Code: [Select]
(getkword "\nAnd Another [A/B/C]: ")
to command prompt then enter letter "A", "B" or "C" (without quotation marks) it returns "Invalid option keyword" again.

As is expected, since an initget expression has not been evaluated prior to the getkword call.

MeasureUp

  • Bull Frog
  • Posts: 465
Re: Question about "initget"
« Reply #13 on: April 22, 2013, 07:11:49 PM »
As is expected, since an initget expression has not been evaluated prior to the getkword call.

Now I copy one line to command prompt per time. This is what I get:

Quote
Command: (initget 1 "A B C")
nil

Command: (getkword "\nAnd Another [A/B/C]: ")

And Another [A/B/C]: a
"A"

Command: (initget 1 "D E F")
nil

Command: (getkword "\nChoose a Letter [D/E/F]: ")

Choose a Letter [D/E/F]: d

Invalid option keyword.

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Question about "initget"
« Reply #14 on: April 22, 2013, 07:29:32 PM »
Why are you copying the code to the command line? Seems like the VLIDE would be the best place to troubleshoot  :?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC