Author Topic: unable the escape key..  (Read 11727 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.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: unable the escape key..
« Reply #15 on: October 10, 2006, 12:00:59 PM »
hhhmm.....seem having same problem..


Code: [Select]
(defun goto_INGcommand ()
  (if (eq g "ING_SAVE")
    (progn
  (initdia 1)
  (command "_saveas")
))
)


(defun INGcommand ()
  (setq g nil)
  (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)))
         (goto_INGcommand)
         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
)



(setq cmd (INGcommand))

maybe need to think for another solution....
using reactor..or something else....

Thanks. CAB.
Keep smile...

Patrick_35

  • Guest
Re: unable the escape key..
« Reply #16 on: October 10, 2006, 12:06:51 PM »
Salut

Code: [Select]
(defun INGcommand(/ g)
  (while (setq g (vl-catch-all-apply 'getstring (list "\nINGcommand: ")))
    (if (not (vl-catch-all-error-p g))
      (progn
        (setq g (strcase g))
        (if (vl-string-search "ING" g)
          (ing_go g)
)
        (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)
        (setq g nil)
      )
    )
  )
)

(defun ing_go (g1)
  (if (eq g1 "ING_SAVE")
    (progn
    (initdia 1)
    (command "_saveas"))
  ))

(INGcommand)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: unable the escape key..
« Reply #17 on: October 10, 2006, 12:09:32 PM »
Works for me.   :-o
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
)

(defun c:test (/ cmd)
  (setq cmd (INGcommand))
  (cond
    ((eq cmd "ING_SAVE")
     (initdia 1)
     (command "_saveas")
    )
    (t
     (alert "Invalid ING Command")
     )
  )
)
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.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: unable the escape key..
« Reply #18 on: October 10, 2006, 02:02:27 PM »
Works for me. 

hug ?..   :?
hmm....bizzarre..!..

Thanks CAB nice try !..   :wink:

Patrick,..your code work perfectly. thank you.  :roll:
Keep smile...

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: unable the escape key..
« Reply #19 on: October 10, 2006, 02:16:18 PM »
Works for me. 

hug ?..   :?
hmm....bizzarre..!..

Thanks CAB nice try !..   :wink:
Andrea did you copy the second test routine without any changed & test it?
Did you get an error? If it works in the test the problem is in your implementation.  8-)

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.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: unable the escape key..
« Reply #20 on: October 10, 2006, 02:33:34 PM »
Andrea did you copy the second test routine without any changed & test it?

Yes, CAB...
copy and paste in a new lisp file...

but the result is that return to AutoCAd command line..
Keep smile...

GDF

  • Water Moccasin
  • Posts: 2081
Re: unable the escape key..
« Reply #21 on: October 10, 2006, 02:49:59 PM »
Works for me.   :-o
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
)

(defun c:test (/ cmd)
  (setq cmd (INGcommand))
  (cond
    ((eq cmd "ING_SAVE")
     (initdia 1)
     (command "_saveas")
    )
    (t
     (alert "Invalid ING Command")
     )
  )
)

Alan

Work fine for me.

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Andrea

  • Water Moccasin
  • Posts: 2372
Re: unable the escape key..
« Reply #22 on: October 10, 2006, 05:01:16 PM »
ok....let see ...
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: unable the escape key..
« Reply #23 on: October 10, 2006, 05:05:53 PM »
ok guys...

I think i have wrong start...
The program that i'm trying to do...
is to permit only some AutoCad function to the user...
like:

_SAVEAS
_OPEN
_PLOT
_PREVIEW
_LINE
_PLINE
...and some few other...

before continuing this project..
is this program a good way to do it ?

need your experience.   :kewl:
Keep smile...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: unable the escape key..
« Reply #24 on: October 10, 2006, 05:10:35 PM »
What a waste of energy ... why didn't you say that at the start. ?
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 #25 on: October 10, 2006, 05:16:41 PM »
sorry Kerry..
your right....

but i have lurn something again....
maybe is wasting time for you..
but when i lurn.....is not wasting time for me.

I'm here to understand and lurn
how of all of guru like you, make a program better.

 :oops:
« Last Edit: October 10, 2006, 05:17:47 PM by Andrea »
Keep smile...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: unable the escape key..
« Reply #26 on: October 10, 2006, 05:20:59 PM »
Andrea, dont play the old "I want to learn" card.

We have been having this same discussion for years.

You continually think that people can read your mind .. and expect it.
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 #27 on: October 10, 2006, 06:00:47 PM »
this is my another way...
what is your comment about this one..

Code: [Select]
(defun loadFreactor ()

(vl-load-com)
(vlr-command-reactor nil '((:vlr-commandWillStart . startFCommand)))
)


(defun startFCommand (getcommand / CMD)
  (setq CMD (nth 0 getcommand))
  (cond
   
    ((and (/= CMD "TEXT")
  (/= CMD "MTEXT")
  (/= CMD "DTEXT")
  )
     (progn
     (alert "Command disable.")
     (exit)
     )
     
)))

(loadFreactor)

the problem is..that the (exit) do not exit the command.

« Last Edit: October 10, 2006, 07:15:39 PM by Andrea »
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: unable the escape key..
« Reply #28 on: October 10, 2006, 06:01:45 PM »
Kerry..please...don't start.. :x
Keep smile...

sinc

  • Guest
Re: unable the escape key..
« Reply #29 on: October 10, 2006, 08:32:31 PM »
ok guys...

I think i have wrong start...
The program that i'm trying to do...
is to permit only some AutoCad function to the user...
like:

_SAVEAS
_OPEN
_PLOT
_PREVIEW
_LINE
_PLINE
...and some few other...

before continuing this project..
is this program a good way to do it ?

need your experience.   :kewl:

You could always just UNDEFINE certain commands.  For example, you could put lines like the following in your ACAD.LSP file:
Code: [Select]
(command "undefine" "circle")
It is a simple matter for a moderately-savvy user to override this by using REDEFINE or by preceding the command name with a period ("."), but it might work for low-level users.  Anyway, a moderately-savvy user could probably get around anything you try to do...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: unable the escape key..
« Reply #30 on: October 11, 2006, 09:24:28 AM »
thanks sinc....

but i can't use undefine command..
because as you said...users can put the " . " symbol.
or use "redefine".

 :|
Keep smile...

sinc

  • Guest
Re: unable the escape key..
« Reply #31 on: October 11, 2006, 12:32:44 PM »
thanks sinc....

but i can't use undefine command..
because as you said...users can put the " . " symbol.
or use "redefine".

 :|

If that's important, then the solution you are trying to create probably won't work either.  Lisp is not very robust, and is not designed to be used as a "user shell" inside of Autocad.  It would be very easy for a command to error in such a way that your Lisp routine gets interrupted, and the user is right back at a normal Autocad prompt.  Your user would have to manually restart your little ING thing, and it sounds like you can't trust your users to do this.

I don't think Autocad has any built-in support for what you are trying to do, and I don't think it's possible to create a robust solution in Lisp.  There might be a way in some other language, but I doubt that, too.  Autocad is designed so that the built-in commands can always be accessed, even if they are redefined or undefined, and I can't think of any way of changing that.  I suspect it would be a challenge even if you write your own complete vertical app and run "Autocad inside".

There may be some sort of incredibly clever "trick" you can do and get the results you're after, but I can't think of what it would be...  The usual solution is to just train your users...   :-D

Andrea

  • Water Moccasin
  • Posts: 2372
Re: unable the escape key..
« Reply #32 on: October 11, 2006, 01:20:29 PM »
Ok...

thanks Sinc..
I will try another way....

599 users to train !!....ouf !.   :lol:
Keep smile...