Author Topic: Problem with grread and allkeys  (Read 1214 times)

0 Members and 1 Guest are viewing this topic.

mkweaver

  • Bull Frog
  • Posts: 352
Problem with grread and allkeys
« on: September 27, 2013, 12:16:10 AM »
I understand that grread with bit 8 (allkeys) set should allow my routine to capture the escape key being pressed.  However, the routine below still gives me an "; error: Function cancelled", when I press the escape key.

What am I missing here?

Code: [Select]
(defun c:test2()
    (while (and ;loop until escape is pressed
   (setq readinfo (grread T (+ 1 2 4 8)))
   (not (and (= 2 (car readinfo))
     (= 27 (cadr readinfo))
)
   )
)
    (princ (strcat "\n" (vl-princ-to-string readinfo)))
    )
    (princ (strcat "\n\n" (vl-princ-to-string readinfo)))
  (princ)
  )

Mike

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Problem with grread and allkeys
« Reply #1 on: September 27, 2013, 08:42:13 AM »
It may not display the error message but you still need to trap escape.
Here is one of my old test routines.
Code - Auto/Visual Lisp: [Select]
  1. ;;  With trap for ESCape by CAB
  2.  
  3. (defun c:test2()
  4.   (while ; stay in loop until one of the COND statements return nil
  5.     (progn
  6.       (setq input (vl-catch-all-apply 'grread (list T (+ 1 2 0)))
  7.     (cond
  8.       ((vl-catch-all-error-p input)
  9.      (princ "\nPressed escape ")
  10.      nil ; exit
  11.       )
  12.       ((= 5 (car input)) ; pointing device
  13.        (cond
  14.          ((and LastPT (< (distance (cadr input) LastPT) 0.0001))) ; no update if same point
  15.          ((setq ent (nentselp (setq LastPT (cadr input))))
  16.       (setq obj (vlax-ename->vla-object (car ent)))
  17.       (princ (strcat "\nFound a " (vla-get-objectname obj) " at "(vl-princ-to-string (cadr ent))))
  18.    )
  19.        )
  20.        t ; stay in loop
  21.       )
  22.       ((= 2 (car input)) ; Keyboard input
  23.        (princ (vl-prin1-to-string input))
  24.        t ; stay in loop
  25.        )
  26.       ((= 3 (car input))  ; Selected 3d point
  27.        (if (setq ent (nentselp (cadr input)))
  28.    (progn
  29.       (setq obj (vlax-ename->vla-object (car ent)))
  30.       (princ (strcat "\nFound a " (vla-get-objectname obj) " at the point selected: "(vl-princ-to-string (cadr ent))))
  31.       )
  32.    )
  33.        t ; stay in loop
  34.        )
  35.       )
  36.      )
  37.     ) ; while
  38.   (princ)
  39.   )
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.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Problem with grread and allkeys
« Reply #2 on: September 28, 2013, 01:22:06 PM »
@ CAB: there is a parentheses missing on line 6.