Author Topic: Possible for grread to return coordinates and keyboard input at the same time?  (Read 2418 times)

0 Members and 1 Guest are viewing this topic.

Brick_top

  • Guest
Hi there.

question is in the title

I'm using a routine that loads and unloads images according to coordinates inside some polygons.

But I want to cycle through some images by pressing a key.

thanks
« Last Edit: April 20, 2016, 10:12:21 AM by Brick_top »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Grread will not return a point and a character code at the same time.
But you can create code that stores point values while waiting for keyboard input:
Code - Auto/Visual Lisp: [Select]
  1. (defun test ( / doneP gr pt ret)
  2.   (while
  3.     (and
  4.       (not doneP)
  5.       (setq gr (grread T 11))
  6.     )
  7.     (cond
  8.       ((and pt (= 2 (car gr)))
  9.         (setq ret (list (cadr gr) pt))
  10.         (setq doneP T)
  11.       )
  12.       ((= 5 (car gr))
  13.         (setq pt (cadr gr))
  14.       )
  15.     )
  16.   )
  17.   ret
  18. )

Brick_top

  • Guest
thanks a lot man.. this stuff is a bit over my head.

I'm going to try to incorporate it into my code.

I was almost making it work with a workaround, but just couldn't write an *error* function for when I hit Esc

this is the part where I almost got it to work

Code: [Select]
(while (setq gr (grread T))
  (setq imagedict (dictsearch (namedobjdict) "ACAD_IMAGE_DICT")
        imagefiles (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 3 (car x))) imagedict))
gr_lst (cons gr gr_lst)
  );setq
  (if
    (or
      (= 2 (car gr))
      (= 11 (car gr))
    );or
    (progn
      (setq gr2 (chr (cadr gr))
        gr (nth 1 gr_lst)
      );setq
    );progn
  );if

I was storing all the grread input into the gr_lst list so that when I press a key it would define a variable for it and would retrieve the coordinate prior to the key press, because the routine would stop whenever the gr variable was not a coordinate.

the problem now was how to write a proper *error* function


edit - by the way how do you create that code section with the color?
« Last Edit: April 21, 2016, 04:33:44 AM by Brick_top »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
edit - by the way how do you create that code section with the color?
See: https://www.theswamp.org/index.php?topic=48309.0

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
I am not sure how you want to employ your *error* function.
If you want to 'catch' escaping out of the 'grread' loop I would suggest something like this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test2 ( / doneP gr pt ret)
  2.   (if
  3.       (vl-catch-all-apply
  4.         (function
  5.           (lambda ()
  6.             (while
  7.               (and
  8.                 (not doneP)
  9.                 (setq gr (grread T 11))
  10.               )
  11.               (cond
  12.                 ((and pt (= 2 (car gr)))
  13.                   (setq ret (list (cadr gr) pt))
  14.                   (setq doneP T)
  15.                 )
  16.                 ((= 5 (car gr))
  17.                   (setq pt (cadr gr))
  18.                 )
  19.               )
  20.             )
  21.           )
  22.         )
  23.       )
  24.     )
  25.     (progn
  26.       (princ "\nEscape has been pressed ")
  27.       ; ...
  28.       ; ...
  29.     )
  30.     (progn
  31.       (print ret)
  32.       ; ...
  33.       ; ...
  34.     )
  35.   )
  36.   (princ)
  37. )

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
In your code you are defining imagedict and imagefiles inside the while loop. Since these values do not change it would make more sense to define them before starting the loop.

Brick_top

  • Guest
hi roy thanks again for your help. I never used those vl-catch functions I'll have to get used to them.

regarding my variables "imagedict" and "imagefiles" hopefully I'm not defining them in vain. Sorry to put that code in there without a context.

In the function I'm trying to write I'm moving the cursor over some polygons and while it is inside a polygon it loads a "corresponding" image. if then I move to another polygon it has to load another image and unload the previous.
thats why I'm doing the dictionary search because if I'm not mistaken as I load an image there is an entry written to the dictionary, and when I unload an image the entry gets removed right?

thank you!

edit - sorry if my english sounds strange


Brick_top

  • Guest
oops... :o I knew I should have done a search before posting

thank you for your input :)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
regarding my variables "imagedict" and "imagefiles" hopefully I'm not defining them in vain. Sorry to put that code in there without a context.
No, the mistake is mine, I should not have made assumptions regarding your code. Scratch my post #5.

Brick_top

  • Guest
hi roy, I tried your test functions and if I'm using them correctly they exit withouth an error when I press a key.

I should have been more clear.

What I'm trying to do is for the function to continue while I don't press "esc"
and keep returning the pointer coordinates and key presses.

my problem is that my function "freezes" when I press esc.

edit - I'm reading the topic suggested by ymg and I might find my answer there.
« Last Edit: April 27, 2016, 04:12:34 AM by Brick_top »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
What I'm trying to do is for the function to continue while I don't press "esc"
and keep returning the pointer coordinates and key presses.
...
my problem is that my function "freezes" when I press esc.
This is still not clear. What should happen if Esc is pressed? You don't want the function to continue, but you don't want the function to stop (freeze) either.

If you want the function to continue after 'normal' key input, all you have to do is completely remove the doneP variable from the c:Test2 function in one of my previous posts.


Brick_top

  • Guest
lets see if I say it right this time  :laugh:

I want the function to continue after normal key input (if there is a key input I need a coordinate aswell), and to exit without freezing when i press "esc"

Brick_top

  • Guest
I'm sorry... I should just study more  :oops:


edit - ok now I get it.

when removing the doneP variable I get a key and a coordinate in the ret variable

thanks a lot, sorry for all the trouble

Brick_top

  • Guest
Hi there roy! just wanted to tell you that I got what I wanted working!

thanks again for all the help! and to ymg aswell