TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: MeasureUp on April 18, 2013, 11:59:03 PM

Title: Question about "initget"
Post by: MeasureUp 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.
Title: Re: Question about "initget"
Post by: CAB 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): "))
Title: Re: Question about "initget"
Post by: MeasureUp 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): "))
Title: Re: Question about "initget"
Post by: Kerry 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
Title: Re: Question about "initget"
Post by: ronjonp 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*)
      )
       )
)
Title: Re: Question about "initget"
Post by: HasanCAD on April 20, 2013, 05:50:02 AM
Prompting with a Default Option
http://www.lee-mac.com/promptwithdefault.html
Title: Re: Question about "initget"
Post by: CAB on April 20, 2013, 07:39:29 AM
Lee has excellent examples.

Here are some other examples.
-----------   keyword examples  -------------
http://www.theswamp.org/index.php?topic=15173.0
http://www.theswamp.org/index.php?topic=6992.0
http://www.theswamp.org/index.php?topic=15173.0
http://www.theswamp.org/index.php?topic=6992.msg93574#msg93574
Title: Re: Question about "initget"
Post by: MeasureUp 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.
Title: Re: Question about "initget"
Post by: CAB 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 ?
Title: Re: Question about "initget"
Post by: MeasureUp 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): "))
Title: Re: Question about "initget"
Post by: Lee Mac 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)
)
Title: Re: Question about "initget"
Post by: MeasureUp 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.
Title: Re: Question about "initget"
Post by: Lee Mac 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.
Title: Re: Question about "initget"
Post by: MeasureUp 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.
Title: Re: Question about "initget"
Post by: ronjonp 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  :?
Title: Re: Question about "initget"
Post by: CAB on April 22, 2013, 11:07:13 PM
In ACAD2006
Code: [Select]
Command: (initget 1 "D E F")
nil

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

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

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

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

Invalid option keyword.

Choose a Letter [D/E/F]: f
"F"
Title: Re: Question about "initget"
Post by: MeasureUp on April 22, 2013, 11:24:06 PM
In ACAD2006
Code: [Select]
Command: (initget 1 "D E F")
nil

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

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

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

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

Invalid option keyword.

Choose a Letter [D/E/F]: f
"F"

Thanks CAB, have you tried (initget 1 "A B C") first, then (initget 1 "D E F") and (getkeyword "D/E/F: ")?
Title: Re: Question about "initget"
Post by: CAB on April 22, 2013, 11:37:24 PM
Oh it ignores the second initget.  :o
Title: Re: Question about "initget"
Post by: CAB on April 22, 2013, 11:39:31 PM
In VLIDE it behaves normally.  8)

Title: Re: Question about "initget"
Post by: MeasureUp on April 23, 2013, 12:04:43 AM
In VLIDE it behaves normally.  8)

I can't find any errors by using VLIDE.
And that is why I don't mention of using it.
From the command prompt, the 1st set of "initget" looks fine:
Code: [Select]
(initget "A B C")
(setq ABC (getkword "\nSelect A/B/C: "))
Select A/B/C: -> A
"A"

but the 2nd set has a problem:
Code: [Select]
(initget "D E F")
(setq DEF (getkword "\nSelect D/E/F: "))
Select D/E/F: -> D
Invalid option keyword.
Title: Re: Question about "initget"
Post by: Kerry on April 23, 2013, 01:50:50 AM
What happens if you put the code into a function body and load the file containing it and run the function.

Not many of us would expect to enter the code line by line at the command line ...