Author Topic: Yes or No < Yes > :  (Read 3794 times)

0 Members and 1 Guest are viewing this topic.

Didge

  • Bull Frog
  • Posts: 211
Re: Yes or No < Yes > :
« Reply #15 on: August 04, 2006, 09:42:15 AM »
Couldn't help playing with MP's coding, this version returns T if the "Y" key is pressed or NIL  if the "N" key is pressed.

Code: [Select]
(defun YesNo ( prmpt / GetKey response )
  (defun GetKey ( / result )(while (null (eq 2 (car (setq result (grread))))))(chr (cadr result)))
  (princ (strcat prmpt ", Y/N: "))
  (while (null (member (setq response (strcase (GetKey))) '("Y" "N"))))
  (princ (strcat " <" (if (eq "Y" response) "Yes" "No") ">."))
  (eq response "Y")
)

;  example:   (if (yesno "Shoot?")(prompt "\nBANG")(prompt "\nDOH!!"))

EDIT: Question changed.
« Last Edit: August 04, 2006, 09:45:39 AM by Didge »
Think Slow......

ronjonp

  • Needs a day job
  • Posts: 7085
Re: Yes or No < Yes > :
« Reply #16 on: August 04, 2006, 11:11:47 AM »
Here is another:

Code: [Select]
(if (not *YN*)
  (setq *YN* "Yes")
)
(initget 0 "Yes No")
(setq P
       (cond
((getkword
    (strcat
      "\n Do you like donuts (Y\\N) <Hit Enter for "
      *YN*
      ">: "
    )
  )
)
(*YN*)
       )
)
(setq *YN* P)

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

MP

  • Seagull
  • Posts: 17530
Re: Yes or No < Yes > :
« Reply #17 on: August 04, 2006, 11:45:52 AM »
And yet more fun (on the fly dcl) --

Code: [Select]
(defun GetYesNoCancel ( title question / _MakeDcl _Main )

    ;;  returns 1 for yes, -1 for no, 0 for cancel (you
    ;;  could mod to return nil for cancel if you prefer)

    (defun _MakeDcl ( / tempname handle )
        (cond
            (   (setq
                    tempname (vl-filename-mktemp "ync.tmp")
                    handle   (open tempname "w")
                )
                (foreach stream
                   '(
                        "yesnocancel : dialog {\n"
                        "    key = \"title\";\n"
                        "    label = \"Yes / No / Cancel\";\n"
                        "    spacer;spacer;\n"
                        "    :   column {\n"
                        "        :   text {\n"
                        "            alignment = centered;\n"
                        "            key = \"question\";\n"
                        "            label = \"xxxx xxxx xxxx xxxx xxxx\";\n"
                        "        }\n"
                        "    }\n"
                        "    spacer;spacer;\n"
                        "    :   row {\n"
                        "        spacer;spacer;\n"
                        "        :   button { label = \"Yes\"; "
                        "key = \"accept\"; is_default = true; }\n"
                        "        :   button { label = \"No\"; "
                        "key = \"no\"; }\n"
                        "        :   button { label = \"Cancel\"; "
                        "key = \"cancel\"; is_cancel = true; }\n"
                        "        spacer;spacer;\n"
                        "    }\n"
                        "    spacer;\n"
                        "}\n"
                    )
                    (princ stream handle)
                )   
                (close handle)
                tempname
            )
        )
    )
   
    (defun _Main ( title question / _Action dclname dclid result)

        (defun _Action ( argument )
            (setq result argument)
            (done_dialog)
        )

        (cond
            (   (and
                    (setq dclname (_MakeDcl))
                    (< 0 (setq dclid (load_dialog dclname)))
                    (new_dialog "yesnocancel" dclid)
                )

                (vl-file-delete dclname)
                (set_tile "title" title)
                (set_tile "question" question)
                (action_tile "accept" "(_Action 1)")
                (action_tile "no" "(_Action -1)")
                (action_tile "cancel" "(_Action 0)")
                (start_dialog)

                result

            )
        )
    )
   
    (_Main title question)
   
)

Example --

Code: [Select]
(GetYesNoCancel "Question of the day" "Is this superfluous?")


:-D
« Last Edit: August 04, 2006, 12:03:39 PM by MP »
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Oak3s

  • Bull Frog
  • Posts: 321
Re: Yes or No < Yes > :
« Reply #18 on: August 04, 2006, 02:06:25 PM »
<*blink>
a lot of different ways. thank you.

"Freedom is not defined by safety. Freedom is Defined by the ability of citizens to live without government interference"
-- Ron Paul

Oak3s

  • Bull Frog
  • Posts: 321
Re: Yes or No < Yes > :
« Reply #19 on: August 04, 2006, 08:47:53 PM »
i am appreciative of the input and i thought i could handle it from there. but i havent been able to put it to use. here is my go at it. could someone point me in the right direction.
Code: [Select]
(DEFUN c:Yesno (/ ansr)
    (INITGET 0 "Yes No")
    (OR (SETQ ansr (GETKWORD "\nAre you sure? [Yes/No] < Yes >: "))
(SETQ ansr "Yes")
)
ansr
     (if (= ansr yes)
(setvar "osmode" 1)
     )
)

"Freedom is not defined by safety. Freedom is Defined by the ability of citizens to live without government interference"
-- Ron Paul

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Yes or No < Yes > :
« Reply #20 on: August 04, 2006, 10:47:27 PM »
ansr is a STRING .. so ..
Quote
    (if (= ansr "Yes")
      (setvar "osmode" 1)
     )
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Yes or No < Yes > :
« Reply #21 on: August 04, 2006, 10:50:41 PM »
.. or considering the context of your sample, perhaps something like this ..
Quote
(DEFUN c:Yesno (/ ansr)
    (INITGET 0 "Yes No")
    (IF (= "Yes" (GETKWORD "\nAre you sure? [Yes/No] < Yes >: "))
        (SETVAR "osmode" 1)
    )
)
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Yes or No < Yes > :
« Reply #22 on: August 06, 2006, 03:16:03 PM »
.. or considering the context of your sample, perhaps something like this ..
Quote
(DEFUN c:Yesno (/ ansr)
    (INITGET 0 "Yes No")
    (IF (= "Yes" (GETKWORD "\nAre you sure? [Yes/No] < Yes >: "))
        (SETVAR "osmode" 1)
    )
)
Kerry, with this, if enter is hit, then the osmode won't get set.  That is why I usually test for the answer that is not the default, so something like
Code: [Select]

(DEFUN c:Yesno (/ ansr)
    (INITGET "Yes No")
    (IF (/= "No" (GETKWORD "\nAre you sure? [Yes/No] < Yes >: "))
        (SETVAR "osmode" 1)
    )
)

Edit:  Oops, didn't see the bit code 0 of the initget.  Sorry.
« Last Edit: August 06, 2006, 03:17:28 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

sinc

  • Guest
Re: Yes or No < Yes > :
« Reply #23 on: August 10, 2006, 12:55:20 PM »
Perhaps try something like  this
.. note also the square brackets around the options ...  try a right click to display the popup options menu when the command is running, you'll see the options displayed .. which you can also click ..
Quote
(DEFUN c:Yesno (/ return)
    (INITGET 0 "Yes No")
    (OR (SETQ return (GETKWORD "\nAre you sure? [Yes/No] < Yes >: "))
        (SETQ return "Yes")
    )
    return
)

I just wanted to second that about using the square brackets for your prompt.  In the newer versions of Autocad, Autocad uses those square brackets to determine the available choices for the Dynamic Input prompt.  It also pays attention to those angle brackets, for the "default".  For example, in the following:

Code: [Select]
(initget 128 "Current Jump Options")
(setq sel
   (getpoint
(VLutil:getPointAtDist e curDist)
(strcat
"\nEnter end elev <"
(rtos CogoPtLastEl)
"> or pick grd brk "
"[Current elev/Jump to point/Options]: "
) ;_ strcat
   ) ;_ getpoint
) ;_ setq

Say the value for CogoPtLastEl is "2600.00".  The above code will result in a Dynamic Input prompt composed of a list that contains the following choices:

Code: [Select]
* 2600.00
  Current elev
  Jump to point
  Options

The "2600.00" will be flagged as the "current value" in the list.