Author Topic: Help getkword  (Read 1767 times)

0 Members and 1 Guest are viewing this topic.

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Help getkword
« on: October 07, 2016, 03:12:27 PM »
Hi, I need help please.

What I need is that after selecting an action, example "1", ask the options again.   :-(

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Rev1 ()
  2. (if (not opcionrev) (setq opcionrev "1"))
  3. (initget "1 2 3 eXit")
  4. (setq opcionrev (cond ( (getkword (strcat "\nSpecify option [1 /2 / 3 / eXit] <" opcionrev "> : " ))) ( opcionrev )))
  5. ((= opcionrev "1") (alert "\nOption 1..."))
  6. ((= opcionrev "2") (alert "\nOption 2..."))
  7. ((= opcionrev "3") (alert "\nOption 3..."))
  8. ((= opcionrev "eXit") (prompt "\n** Exit **")))
  9.   (princ))
  10.  
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

QuestionEverything

  • Guest
Re: Help getkword
« Reply #1 on: October 07, 2016, 03:17:24 PM »
Perhaps wrap it within a while loop:
Code: [Select]
(defun c:Rev1 ()
(if (not opcionrev) (setq opcionrev "1"))
(while
(initget "1 2 3 eXit")
(setq opcionrev (cond ( (getkword (strcat "\nSpecify option [1 /2 / 3 / eXit] <" opcionrev "> : " ))) ( opcionrev )))
(cond
((= opcionrev "1") (alert "\nOption 1..."))
((= opcionrev "2") (alert "\nOption 2..."))
((= opcionrev "3") (alert "\nOption 3..."))
((= opcionrev "eXit") (prompt "\n** Exit **"))
)
)
(princ))

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Help getkword
« Reply #2 on: October 07, 2016, 03:26:05 PM »
You need to put (not (initget ...)) since it returns nil. That loop will never start & it needs a way to exit since the option always returns something.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:rev1 ()
  2.   (if (not *opcionrev*)
  3.     (setq *opcionrev* "1")
  4.   )
  5.   (while (and (not (initget "1 2 3 eXit"))
  6.               (setq *opcionrev*
  7.                      (cond
  8.                        ((getkword (strcat "\nSpecify option [1 /2 / 3 / eXit] <" *opcionrev* "> : "))
  9.                        )
  10.                        (*opcionrev*)
  11.                      )
  12.               )
  13.               (/= *opcionrev* "eXit")
  14.          )
  15.     (cond ((= *opcionrev* "1") (alert "\nOption 1..."))
  16.           ((= *opcionrev* "2") (alert "\nOption 2..."))
  17.           ((= *opcionrev* "3") (alert "\nOption 3..."))
  18.           ((= *opcionrev* "eXit") (prompt "\n** Exit **"))
  19.     )
  20.   )
  21.   (princ)
  22. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: Help getkword
« Reply #3 on: October 07, 2016, 03:33:54 PM »
Hi, ronjonp

Thanks.  :yay!:
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Help getkword
« Reply #4 on: October 07, 2016, 03:39:24 PM »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help getkword
« Reply #5 on: October 08, 2016, 12:04:57 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.