Catch esc during move command

Catch esc during move command

davidlanesmith673
Enthusiast Enthusiast
657 Views
6 Replies
Message 1 of 7

Catch esc during move command

davidlanesmith673
Enthusiast
Enthusiast

I have a program that makes a label and then automatically starts the move command so you can move the label to where you want. I want to make it so that when you press esc during the move command, before you click the second point, the program can recognize that and handle it. In the program, sel is a selection set and pntb is a predefined point. em and lp are variables used to handle errors.

 

(setq err (vl-catch-all-apply 'moveL (list sel pntb)))
(if (vl-catch-all-error-p err)
(progn
(print "moveErr")
(if (equal (vl-catch-all-error-message err) "Function cancelled")
(setq em 1)
(progn
(print (strcat "Error: " (vl-catch-all-error-message err) "."))
(setq em 2)
)
)
(setq lp 0)
)
)

 

 

(defun moveL(sel pntb)
(command "._move" sel "" pntb pause)
(princ)
)

 

Right now in my program, when I press esc during the move command, it just cancels the command and the label goes back to where it started and the program continues, but the program doesn't recognize that esc has been pressed. Is there a way for the program to recognize that esc has just been pressed during the move command?

0 Likes
658 Views
6 Replies
Replies (6)
Message 2 of 7

john.uhden
Mentor
Mentor

I have one way that I like very much.  It uses (grread) which can interpret the Esc key being pressed and keep on going.

John F. Uhden

0 Likes
Message 3 of 7

hmsilva
Mentor
Mentor

@davidlanesmith673 wrote:

I have a program that makes a label and then automatically starts the move command so you can move the label to where you want. I want to make it so that when you press esc during the move command, before you click the second point, the program can recognize that and handle it. In the program, sel is a selection set and pntb is a predefined point. em and lp are variables used to handle errors.

....

(defun moveL(sel pntb)
(command "._move" sel "" pntb pause)
(princ)
)

Right now in my program, when I press esc during the move command, it just cancels the command and the label goes back to where it started and the program continues, but the program doesn't recognize that esc has been pressed. Is there a way for the program to recognize that esc has just been pressed during the move command?


One way

 

(defun c:demo ( / moveL)
  
  (defun moveL (sel pntb)
    (command "._move" sel "" pntb pause)
    t
  )

  (if (vl-catch-all-apply 'moveL (list selection_set point))
    (princ "\nMOVEL ended as expected.... ")
    (princ "\nMOVEL did not ended as expected.... ")
  )
  (princ)
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 4 of 7

hmsilva
Mentor
Mentor

Other way is testing a second point...

 

 

(defun c:demo1 ( / lastpt lastpt1 moveL)
  
  (defun moveL (sel pntb)
    (command "._move" sel "" pntb pause)
  )

  (setq lastpt (getvar 'lastpoint))
  (vl-catch-all-apply 'moveL (list selection_set point))
  (setq lastpt1 (getvar 'lastpoint))
  (if (equal lastpt lastpt1)
    (princ "\nMOVEL did not ended as expected.... ")
    (princ "\nMOVEL ended as expected.... ")
  )
  (princ)
)

 

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 5 of 7

davidlanesmith673
Enthusiast
Enthusiast

@john.uhden 

 

Would grread be able to detect esc being pressed during the move command though, like when move is asking for a point? If so, what would that look like?

0 Likes
Message 6 of 7

john.uhden
Mentor
Mentor
You wouldn't be using the MOVE command. Instead, grread would be
continuously picking up the pointer location and your code would be
modifying (I think transforming) its location. I thought I had posted an
example a couple of years back. I don't remember the subject, but
hopefully it's in my Freebies folder at home. You'll have to remind me to
look for it. Or maybe you can search for it in the forum using the word
grread.

John F. Uhden

0 Likes
Message 7 of 7

hmsilva
Mentor
Mentor

@davidlanesmith673 we can't use grread with move command.
We can use grread only to "Read values from any of the AutoCAD input devices" and Object Snap, Orthomode, Tracking, Dynamic Input, etc. are unavailable whilst the grread function is awaiting or receiving input.
We can mimic the move command using grread function , and we need to write 'tons' of code lines to do that...

 

As a starting point, try @Lee_Mac  's GrSnapV1-0.lsp  and GrSnapDemo.lsp  

see the Demo Program 3 with a full implementation with vector graphics...

 

Using the move command, and providing a selection set or an entity, and a base point, the command expects a:
"Specify second point or <use first point as displacement>:"
so, we need to catch if user press esc, and if user press enter, space bar or mouse right click to end the command...

 

My "demo" only catch the esc...
If the user press enter, space bar or mouse right click to end the command, we won't have an error, but a point was not provided to the move command....

 

My "demo1" was trying to catch the second point, it was not tested and was not a good example...

 

Try this "demo2", now tested...

 

 

(defun c:demo2 (/ lastpt lastpt1 moveL txt)

  (defun moveL (sel pntb)
    (command "._move" sel "" pntb pause)
  )

  (setq lastpt (getvar 'viewctr))
  (entmake (list (cons 0 "TEXT")
		 (cons 1 "Test string")
		 (cons 7 (getvar 'textstyle))
		 (cons 10 lastpt)
		 (cons 40 (getvar 'textsize))
	   )
  )
  (setq txt (entlast))
  (vl-catch-all-apply 'moveL (list txt lastpt))
  (setq lastpt1 (getvar 'lastpoint))
  (if (equal lastpt lastpt1 1e-6)
    (progn (princ "\nMOVEL did not ended as expected.... ")
	   (entdel txt)
    )
    (princ "\nMOVEL ended as expected.... ")
  )
  (princ)
)

 

 

Hope this helps,
Henrique

 

EESignature

0 Likes