TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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:
(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.
-
Try this:
(initget "D E F")
(setq DEF (getkword "\nSelect a Letter (D/E/F): "))
-
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?
(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): "))
-
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?
(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
-
You could also do something like this to "remember" your last selection.
(or *global* (setq *global* "A"))
(initget "A B C")
(alert (setq *global* (cond ((getkword (strcat "\n[A/B/C] <" *global* ">: ")))
(*global*)
)
)
)
-
Prompting with a Default Option
http://www.lee-mac.com/promptwithdefault.html
-
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
-
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
(setq DEF (getkword "\nSelect a Letter (D/E/F): "))
Otherwise it returns "Invalid option keyword."
It looks likely it holds the variable active:
(setq ABC (getkword "\nSelect a Letter (A/B/C): "))
BTW, I use AutoCAD Mech v2013.
-
You must use a new initget before each getkword.
Did you use this (initget "D E F") just before the getkword ?
-
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:
...
(initget "D E F")
(setq DEF (getkword "\nSelect a Letter (D/E/F): "))
-
To clarify, try the following program:
(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)
)
-
To clarify, try the following program:
(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:
Command: DOIT
Choose a Letter [D/E/F]: e
And Another [A/B/C]: b
If I copy this line
(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.
-
If I copy this line
(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.
-
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:
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.
-
Why are you copying the code to the command line? Seems like the VLIDE would be the best place to troubleshoot :?
-
In ACAD2006
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"
-
In ACAD2006
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: ")?
-
Oh it ignores the second initget. :o
-
In VLIDE it behaves normally. 8)
-
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:
(initget "A B C")
(setq ABC (getkword "\nSelect A/B/C: "))
Select A/B/C: -> A
"A"
but the 2nd set has a problem:
(initget "D E F")
(setq DEF (getkword "\nSelect D/E/F: "))
Select D/E/F: -> D
Invalid option keyword.
-
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 ...