spiker7221 Posted July 3, 2013 Posted July 3, 2013 I've got a routine that ask the user questions via STRCASE, etc. I use ECHOGET to set defaults. The only way the user can continue is by typing in a new choice or by hitting ENTER to use their last choice. I am old school Autocad and I use the space bar a lot for my ENTER. How can I program my LISP to use either SPACE BAR or ENTER to accept these defaults? Thanks, Mike Quote
rkmcswain Posted July 3, 2013 Posted July 3, 2013 I've got a routine that ask the user questions via STRCASE.... Do you mean (GETSTRING)? Look at the documentation for (getstring) on how to allow SPACE as ENTER. Quote
BlackBox Posted July 3, 2013 Posted July 3, 2013 Without seeing your code... Consider this quickly written example: (defun c:FOO (/ option) (initget "Yes No") (if (or (/= nil (setq option (getkword "\nBow ties are cool, right? [Yes/No]<Yes>: " ) ) ) (setq option "Yes") ) (if (= "Yes" option) (prompt "\n** Bow ties are cool ** ") (prompt "\n** Bow ties ARE cool (even if you don't think so) ** ") ) ) (princ) ) Quote
spiker7221 Posted July 3, 2013 Author Posted July 3, 2013 I understand how to add the T before the "\n...but when I hit space bar, it just adds a space to the command line. I just want it to behave as an ENTER instead. (setq choice2 (strcase (Echoget2 2xtxt "\nFraming size: 2x(6), 2x(, 2x(10), 2x(12)? "))) (cond ((= choice2 "6") (setq 2xtxt "")) ((= choice2 "8") (setq 2xtxt "(2x8)")) ((= choice2 "10") (setq 2xtxt "(2x10)")) ((= choice2 "12") (setq 2xtxt "(2x12)")) );end cond Without seeing your code... Consider this quickly written example: (defun c:FOO (/ option) (initget "Yes No") (if (or (/= nil (setq option (getkword "\nBow ties are cool, right? [Yes/No]<Yes>: " ) ) ) (setq option "Yes") ) (if (= "Yes" option) (prompt "\n** Bow ties are cool ** ") (prompt "\n** Bow ties ARE cool (even if you don't think so) ** ") ) ) (princ) ) Quote
BlackBox Posted July 3, 2013 Posted July 3, 2013 I understand how to add the T before the "\n...but when I hit space bar, it just adds a space to the command line. I just want it to behave as an ENTER instead. Respectfully, I'm not sure that you do, as adding the non-Nil 'cr' argument to the GetString function precludes the space bar from being accepted as an Enter: (setq foo (getstring [color="#2e8b57"];| do not include cr argument here |;[/color] "\nEnter one word, Space bar to Enter: ")) Further, we cannot assist you with, nor understand the behavior of, a custom sub-function (EchoGet*) which you've neglected to post. Here's one way of accomplishing presumably the same result, using nothing but built-in functions: (initget "6 8 10 12") (if (setq choice2 (getkword "\nFraming size: 2x... [6/8/10/12]: ")) (setq 2xtxt (cond ((= "6" choice2) "(2X6)") ((= "8" choice2) "(2X8)") ((= "10" choice2) "(2X10)") (T "(2X12)") ) ) ) More information is needed. Quote
neophoible Posted July 3, 2013 Posted July 3, 2013 I've got a routine that ask the user questions via STRCASE, etc. I use ECHOGET to set defaults. The only way the user can continue is by typing in a new choice or by hitting ENTER to use their last choice. I am old school Autocad and I use the space bar a lot for my ENTER. How can I program my LISP to use either SPACE BAR or ENTER to accept these defaults?Mike, it sounds like you did not write the routine yourself. Do you know how to edit LISP? I agree that it sounds like you didn't really understand about using T with getstring. If the routine uses getstring, then right after that there should be the prompt message or nil and then the prompt. Did you look at your 'echoget2' function? It is not a LISP function, but rather one included in whatever custom code you have. Also, is there some reason that the routine cannot use getkword instead? Like BlackBox said, if this is not enough, you really need to post the code for us to tell you how to get what you want here. Quote
neophoible Posted July 3, 2013 Posted July 3, 2013 I understand how to add the T before the "\n...but when I hit space bar, it just adds a space to the command line. I just want it to behave as an ENTER instead. (setq choice2 (strcase (Echoget2 2xtxt "\nFraming size: 2x(6), 2x(, 2x(10), 2x(12)? "))) (cond ((= choice2 "6") (setq 2xtxt "")) ((= choice2 "8") (setq 2xtxt "(2x8)")) ((= choice2 "10") (setq 2xtxt "(2x10)")) ((= choice2 "12") (setq 2xtxt "(2x12)")) );end cond BTW, the code looks a bit strange here. It looks like the only expected input is an integer, yet it's being treated as a string and even applying strcase to it. That would not change an integer in a string. Also, there is nothing shown for handling input that does not match the four allowable integers, though I guess that could happen elsewhere. Without seeing the rest of the code, it's hard to tell what's really going on. Quote
spiker7221 Posted July 3, 2013 Author Posted July 3, 2013 It has been awhile since I've coded in LISP. Am just now getting back into it. I am using lots of older parts of my older routines, but it seems these parts are causing issues. I am learning new ways of doing thing ever time I'm on here. It's been great. Here's my old ECHOGET* sub-routine... (defun Echoget2 (DEFAULT2 MSG2 / TEMP2) (setq TEMP2 (getstring T (strcat MSG2 " <<"DEFAULT2">>"))) (IF (/= "" TEMP2) TEMP2 DEFAULT2) ) Your suggestion works perfect and I understand why. Now I just need the last choice to come back to the command line. Again, thanks for all your expertise and help. Humbly, Mike Respectfully, I'm not sure that you do, as adding the non-Nil 'cr' argument to the GetString function precludes the space bar from being accepted as an Enter: (setq foo (getstring [color=#2e8b57];| do not include cr argument here |;[/color] "\nEnter one word, Space bar to Enter: ")) Further, we cannot assist you with, nor understand the behavior of, a custom sub-function (EchoGet*) which you've neglected to post. Here's one way of accomplishing presumably the same result, using nothing but built-in functions: (initget "6 8 10 12") (if (setq choice2 (getkword "\nFraming size: 2x... [6/8/10/12]: ")) (setq 2xtxt (cond ((= "6" choice2) "(2X6)") ((= "8" choice2) "(2X8)") ((= "10" choice2) "(2X10)") (T "(2X12)") ) ) ) More information is needed. Quote
BlackBox Posted July 3, 2013 Posted July 3, 2013 ... It looks like the only expected input is an integer, yet it's being treated as a string and even applying strcase to it. That would not change an integer in a string. Also, there is nothing shown for handling input that does not match the four allowable integers, though I guess that could happen elsewhere. Without seeing the rest of the code, it's hard to tell what's really going on. :: Speculation :: Methinks that EchoGet2 is a sub-function where the first argument (if non-Nil) is the previously entered value, and the second argument is the default prompt used (when no prior option was entered). Pseudo-code: (defun EchoGet2 (p d) (getstring (if p (strcat d " <" p ">: ") d ) ) ) ... Which does introduce the issue of space bar yielding Nil, rather than previous value. Perhaps the OP will be able to offer us more information, so we can better assist. Quote
neophoible Posted July 3, 2013 Posted July 3, 2013 Further, we cannot assist you with, nor understand the behavior of, a custom sub-function (EchoGet*) which you've neglected to post. Here's one way of accomplishing presumably the same result, using nothing but built-in functions: (initget "6 8 10 12") (if (setq choice2 (getkword "\nFraming size: 2x... [6/8/10/12]: ")) (setq 2xtxt (cond ((= "6" choice2) "(2X6)") ((= "8" choice2) "(2X8)") ((= "10" choice2) "(2X10)") (T "(2X12)") ) ) ) More information is needed. BlackBox, I think the actual input function should look a lot more like what you show. The only thing is that the OP obviously has a changeable default that is being handled via his Echoget and the setq. It looks easy enough to accomplish with your approach, but without further input from him, I doubt it's worth any effort at this point. Of course, to make it more AutoCADish, the default should be bracketed thus ": ", rather than using parentheses. But that's just my own perfectionistic attitude showing through. Quote
neophoible Posted July 3, 2013 Posted July 3, 2013 :: Speculation :: Methinks that EchoGet2 is a sub-function where the first argument (if non-Nil) is the previously entered value, and the second argument is the default prompt used (when no prior option was entered). Pseudo-code: (defun EchoGet2 (p d) (getstring (if p (strcat d " <" p ">: ") d ) ) ) ... Which does introduce the issue of space bar yielding Nil, rather than previous value. Perhaps the OP will be able to offer us more information, so we can better assist. Yes, I agree, in which case, one has to wonder why the need for a T allowing spaces. Perhaps there is an Echoget1 or just Echoget that would be more suited to the task? Quote
neophoible Posted July 3, 2013 Posted July 3, 2013 It has been awhile since I've coded in LISP. Am just now getting back into it. I am using lots of older parts of my older routines, but it seems these parts are causing issues. I am learning new ways of doing thing ever time I'm on here. It's been great. Here's my old ECHOGET* sub-routine... (defun Echoget2 (DEFAULT2 MSG2 / TEMP2) (setq TEMP2 (getstring T (strcat MSG2 " <<"DEFAULT2">>"))) (IF (/= "" TEMP2) TEMP2 DEFAULT2) ) Your suggestion works perfect and I understand why. Now I just need the last choice to come back to the command line. Again, thanks for all your expertise and help. Humbly, Mike Glad to be of help. Looks like we were still speculating while you were posting! I didn't really understand this part:Now I just need the last choice to come back to the command line.Are you saying you might need more help? Quote
BlackBox Posted July 3, 2013 Posted July 3, 2013 It has been awhile since I've coded in LISP. Am just now getting back into it. I am using lots of older parts of my older routines, but it seems these parts are causing issues. I am learning new ways of doing thing ever time I'm on here. It's been great. No worries, Mike; we all start (again?) somewhere. Your suggestion works perfect and I understand why. Now I just need the last choice to come back to the command line. Again, thanks for all your expertise and help. That is kind of you to say, Mike; I'm happy to help. Consider this small example: (defun c:FOO ( / oldChoice2) (setq *choice2* (if *choice2* *choice2* "6")) (initget "6 8 10 12") (if (and (setq oldChoice2 *choice2*) (or (setq *choice2* (getkword (strcat "\nFraming size, 2x... [6/8/10/12]" " <" *choice2* ">: " ) ) ) (setq *choice2* oldChoice2) ) ) (prompt (strcat "\nYou selected: " (cond ((= "6" *choice2*) "(2X6)") ((= "8" *choice2*) "(2X8)") ((= "10" *choice2*) "(2X10)") (T "(2X12)") ) ) ) ) (princ) ) Quote
BlackBox Posted July 3, 2013 Posted July 3, 2013 Sorry, I copied the wrong snippet of code... Code revised. Quote
neophoible Posted July 3, 2013 Posted July 3, 2013 If you keep to what you started with, you should be explicit with all the choices: (setq choice2 (strcase (Echoget2 2xtxt "\nFraming size: 2x(6), 2x(, 2x(10), 2x(12)? "))) (cond ((= choice2 "6") (setq 2xtxt "(2x6)")) ((= choice2 "8") (setq 2xtxt "(2x8)")) ((= choice2 "10") (setq 2xtxt "(2x10)")) ((= choice2 "12") (setq 2xtxt "(2x12)")) );end cond Quote
neophoible Posted July 3, 2013 Posted July 3, 2013 (edited) I would use the same basic approach as BlackBox: (if (not (member 2xtxt '("6" "8" "10" "12"))) (setq 2xtxt "6")) (initget "6 8 10 12") (setq choice2 (getkword (strcat "\nFraming size: 2x[6/8/10/12] 2x<" 2xtxt ">: " ) ) ) (if (= "" choice2) (setq choice2 2xtxt) (setq 2xtxt choice2)) Edited July 3, 2013 by neophoible didn't like the appearance Quote
BlackBox Posted July 3, 2013 Posted July 3, 2013 I would use the same basic approach as BlackBox: (if (not (member 2xtxt '("6" "8" "10" "12"))) (setq 2xtxt "6")) (initget "6 8 10 12") (setq choice2 (getkword (strcat "\nFraming size: 2x[6/8/10/12] <2x" 2xtxt ">: " ) ) ) (if (= "" choice2) (setq choice2 2xtxt) (setq 2xtxt choice2)) The only way 2xtxt will not be one of the allowed values is if the user manually uses LISP to change it, so I'd be comfortable with not checking for Member. Were that necessary, and I did not need the resultant list elements from Member, I'd employ vl-Position for expediency. Also, beware of: Quote
neophoible Posted July 3, 2013 Posted July 3, 2013 The only way 2xtxt will not be one of the allowed values is if the user manually uses LISP to change it, so I'd be comfortable with not checking for Member. Were that necessary, and I did not need the resultant list elements from Member, I'd employ vl-Position for expediency. Also, beware of: [ATTACH=CONFIG]42761[/ATTACH] [ATTACH=CONFIG]42762[/ATTACH] Yes, good points, BlackBox. I fixed that last item (by taking the 2x outside the brackets) before you were able to finish responding, but it's a good point I hadn't fully paid attention to. I was looking at 2xtxt as a global, which means any program could conceivably change it, including one the OP might write, though one would hope such would never happen. It's a long enough name, and unusual enough that it likely never would, except by the OP. As for vl-Position, well, I'm afraid I know too little about VLISP to have come up with that one. Thanks for the tips. Quote
alanjt Posted July 3, 2013 Posted July 3, 2013 (edited) ((lambda (/) (initget 0 "6 8 10 12") (strcat "2x" (setq *choice* (cond ((getkword (strcat "\nSpecify framing size: 2x [6/8/10/12] <" (cond (*choice*) ((setq *choice* "6")) ) ">: " ) ) ) (*choice*) ) ) ) ) ) Edited July 9, 2013 by alanjt I'm retarded. Quote
spiker7221 Posted July 8, 2013 Author Posted July 8, 2013 Thanks Blackbox and Neophoible, The code is nice and compact. My complete routine has 3 questions all using the structure below..setting defaults. I can press enter or spacebar to accept these defaults, but when I get to the last question, it bombs out unless I actually type the final choice at the command line. FYI...am getting an "Error: bad argument type: stringp nil" now. Does this mean there is a variable not getting reset? Thanks, Mike I would use the same basic approach as BlackBox: (if (not (member 2xtxt '("6" "8" "10" "12"))) (setq 2xtxt "6")) (initget "6 8 10 12") (setq choice2 (getkword (strcat "\nFraming size: 2x[6/8/10/12] 2x<" 2xtxt ">: " ) ) ) (if (= "" choice2) (setq choice2 2xtxt) (setq 2xtxt choice2)) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.