Author Topic: unable the escape key..  (Read 11719 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
unable the escape key..
« on: October 06, 2006, 12:31:26 PM »
hi all....

I work to make a little function detection...

Code: [Select]
(defun INGcommand( / g)
(while (setq g (strcase (getstring "INGcommand: ")))
  (progn
(if (vl-string-search "ING" g)(alert "You have entered a ING command"))
(if (eq g "COMMAND")(exit))
(if (and
      (not (vl-string-search "ING" g))
      (not (eq g "COMMAND"))
    )
      (alert "Invalid ING command.\n Type \"Command\" to return to AutoCAd command.")
)
)
  (INGcommand)
  )
)
(INGcommand)

It work great....since press the ESCAPE key.

any suggestion ?
Keep smile...

kpblc

  • Bull Frog
  • Posts: 396
Re: unable the escape key..
« Reply #1 on: October 09, 2006, 02:30:20 AM »
You can try to use (vl-catch-all-apply) function or check the errno system variable value.
Sorry for my English.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: unable the escape key..
« Reply #2 on: October 09, 2006, 05:48:38 AM »
Andrea,
you could modify or use something like this  ...

Code: [Select]
;;;--------------------------------------------------------------------------
;;;--------------------------------------------------------------------------
;| #lib.
kb:getString (<Promptmsg><Default><InitBit><AllowSpaces>)

Revised Library : kwb 20051031
20051101 kwb : ESC test added.
Build 2.0 :

(SETQ tmpVal (kb:getString "Lot Description" nil (+ 1 ) T))
(SETQ tmpVal (kb:getString "Name" "Me" (+ 1 ) Nil))
(SETQ tmpVal (kb:getString nil nil nil Nil))
|;

(DEFUN kb:getString (Promptmsg                    ; The prompt string.
                     Default                      ; Value to return if response is <enter>
                     InitBit                      ; Initget bit
                     AllowSpaces                  ; spaces Flag < T or nil )
                                                  ;
                     / returnvalue)
   ;;------------------------------
   (OR InitBit (SETQ InitBit 0))
   ;;------------------------------
   (SETQ Promptmsg (STRCAT "\n"
                           (COND (Promptmsg)
                                 ("Specify String Value")
                           )
                   )
   )
   ;;------------------------------
   (IF (AND Default (= (TYPE Default) 'str) (/= Default ""))
      (PROGN
         (SETQ Promptmsg (STRCAT "\n" Promptmsg " << " Default " >>: "))
         (IF (VL-CATCH-ALL-ERROR-P
                (SETQ returnvalue (VL-CATCH-ALL-APPLY
                                     'GETSTRING
                                     (LIST AllowSpaces Promptmsg)
                                  )
                )
             )
            ;; ESC was pressed.
            (SETQ ReturnValue nil
                  Default nil
            )
         )
         (SETQ returnvalue (IF (= returnvalue "")
                              Default
                              returnvalue
                           )
         )
      )
      ;; Else no default, so don't accept ENTER or SPACEBAR
      ;;
      (PROGN (SETQ Promptmsg (STRCAT "\n" Promptmsg ": "))
             (IF (= InitBit 1)
                (WHILE (= ""
                          (SETQ returnvalue (VL-CATCH-ALL-APPLY
                                               'GETSTRING
                                               (LIST AllowSpaces Promptmsg)
                                            )
                          )
                       )
                )
                ;;
                (SETQ returnvalue
                        (VL-CATCH-ALL-APPLY 'GETSTRING
                                            (LIST AllowSpaces Promptmsg)
                        )
                )
             )
             (IF (VL-CATCH-ALL-ERROR-P returnvalue)
                ;; ESC was pressed.
                (SETQ ReturnValue nil)
             )
      )
   )
   ;;------------------------------
   returnvalue
)

;;;--------------------------------------------------------------------------
;;;--------------------------------------------------------------------------
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: unable the escape key..
« Reply #3 on: October 09, 2006, 10:26:13 AM »
<warning, I just woke up>

Abused from this post --

Code: [Select]
(defun Evaluate ( expression / result )
    (vl-catch-all-apply
       '(lambda ( )
            (setq result
                (eval expression)
            )   
        )
    )
    result
)

Possible useage --

Code: [Select]
(defun INGcommand ( / g done )

    (while
   
        (and
            (not done)
            (setq g (Evaluate '(strcase (getstring "INGCommand: "))))
        )   
   
        (cond
            (   (eq g "COMMAND")
                (setq done t)
            )
            (   (vl-string-search "ING" g)
                (alert "You have entered a ING command")
            )
            (   t
                (alert
                    (strcat
                        "Invalid ING command.\n"
                        "Type \"Command\" to return"
                        "to AutoCAD command."
                    )   
                )
            )
        )   
           
    )
   
    (princ)
   
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Patrick_35

  • Guest
Re: unable the escape key..
« Reply #4 on: October 09, 2006, 10:58:04 AM »
Hi

Code: [Select]
(defun INGcommand(/ g)
  (while (setq g (vl-catch-all-apply 'getstring (list "\nINGcommand: ")))
    (if (not (vl-catch-all-error-p g))
      (progn
        (if (vl-string-search "ING" g)(alert "You have entered a ING command"))
        (if (eq g "COMMAND")(exit))
        (if (and
          (not (vl-string-search "ING" g))
          (not (eq g "COMMAND")))
          (alert "Invalid ING command.\n Type \"Command\" to return to AutoCAd command.")
        )
      )
      (if (member (vl-catch-all-error-message a) (list "Fonction annulée" "Function cancelled"))
        (setq g T)
      )
    )
  )
)

(INGcommand)

@+

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: unable the escape key..
« Reply #5 on: October 09, 2006, 04:56:34 PM »
<warning, I just woke up>

Abused from this post --


DejaVu
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: unable the escape key..
« Reply #6 on: October 10, 2006, 09:06:04 AM »
Thanks guys...

but...

MP...your code have same result....when user press escape it return to the AutoCAd command line.

Patrick35....see the picture below when pressing escape..
Keep smile...

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: unable the escape key..
« Reply #7 on: October 10, 2006, 09:27:54 AM »
...when user press escape it return to the AutoCAd command line.

Without specification what are we to imagine you want aside from standard behavior?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Patrick_35

  • Guest
Re: unable the escape key..
« Reply #8 on: October 10, 2006, 10:20:04 AM »
oh !
I'm stupid  :-o
Replace
Code: [Select]
(if (member (vl-catch-all-error-message a) (list "Fonction annulée" "Function cancelled"))by
Code: [Select]
(if (member (vl-catch-all-error-message g) (list "Fonction annulée" "Function cancelled"))
@+

Andrea

  • Water Moccasin
  • Posts: 2372
Re: unable the escape key..
« Reply #9 on: October 10, 2006, 10:28:36 AM »
Sorry MP....if wasn't clear.. :|
all i need to do its to prevent user while using the escape key.

eg:

INGcommand: (user press escape here)
return to
INGcommand:

but don't know how...
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: unable the escape key..
« Reply #10 on: October 10, 2006, 10:32:32 AM »
Bravo Patrick !..

it work great !.

a simple question..
why using a list here ..

Code: [Select]
...(list "\nINGcommand: ")
Keep smile...

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: unable the escape key..
« Reply #11 on: October 10, 2006, 10:34:30 AM »
I have to ask why? Elegant or not standard behavior is that hitting the <Esc> terminates a function/command.

Anyway, if you're bent on this approach (which I don't recommend) all you have to do is have the Evaluate function return an empty string instead of nil.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Patrick_35

  • Guest
Re: unable the escape key..
« Reply #12 on: October 10, 2006, 10:51:23 AM »
In the help of Autolisp
(vl-catch-all-apply 'function list)

Arguments

'function

A function. The function argument can be either a symbol identifying a defun, or a lambda expression.

list

A list containing arguments to be passed to the function.

@+

Andrea

  • Water Moccasin
  • Posts: 2372
Re: unable the escape key..
« Reply #13 on: October 10, 2006, 11:22:43 AM »
Merci..

there is another problem....

Code: [Select]
(defun INGcommand(/ g)
  (while (setq g (strcase (vl-catch-all-apply 'getstring (list "\nINGcommand: "))))
    (if (not (vl-catch-all-error-p g))
      (progn
        (if (vl-string-search "ING" g)
  (progn
    (setq g1 g)
    (ing_go)
  ))
        (if (eq g "COMMAND")(exit))
        (if (and
          (not (vl-string-search "ING" g))
          (not (eq g "COMMAND")))
          (alert "Invalid ING command.\n Type \"Command\" to return to AutoCAd command.")
        )
      )
      (if (member (vl-catch-all-error-message g) (list "Fonction annulée" "Function cancelled"))
        (setq g T)
      )
    )
  )
)

(INGcommand)


(defun ing_go ()
(setq g T)
  (if (eq g1 "ING_SAVE")
    (progn
    (initdia 1)
    (command "_saveas"))
  ))
 
Keep smile...

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: unable the escape key..
« Reply #14 on: October 10, 2006, 11:27:34 AM »
Try this:

Code: [Select]
(defun INGcommand (/ g)
  (while
    (progn
      (setq g (vl-catch-all-apply 'getstring (list "INGcommand: ")))
      (cond
        ((vl-catch-all-error-p g) ; yes, error
         (alert "Escape not allowed.")
         t ; stay in loop
        )
        ((vl-string-search "ING" (setq g (strcase g)))
         (alert "You have entered a ING command")
         nil     ; exit loop & return the INGcommand entered.
        )
        ((eq g "COMMAND")
         (exit) ; bye bye
        )
        (t
         (alert
           "Invalid ING command.\n Type \"Command\" to return to AutoCAd command."
         )
         t
        )
      )
    )
  )
  g
)


Code: [Select]
(setq cmd (INGcommand))
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.