Author Topic: Retrieve the last command call  (Read 1601 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Swamp Rat
  • Posts: 765
Retrieve the last command call
« on: July 01, 2017, 08:57:04 AM »
Hi everyone,

Is there a way to obtain the last called command ?
I tried with command reactor, but its successful only with the standard commands, not the lisp defined.
Or maybe theres a variable I'm not aware about?

My intention is to wire it with a mouse reactor (so when double-clicking somewhere [and not on any object, (nentselp) = nil ] it will reinvoke the last command).
Just like hitting space behavoiur, but using the mouse only.

The reason is that I'm tired to reach the keyboard, while lying on my comfy couch and looping [SPACE] key, selecting and pressing [RMB] .  :yawn:
So I'm trying to translate this loop to: [LMB] double-click, selecting and pressing [RMB] (which requires only the mouse).
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)

Lee Mac

  • Seagull
  • Posts: 12502
  • London, England
Re: Retrieve the last command call
« Reply #1 on: July 01, 2017, 09:08:58 AM »
Maybe something like this?

Code - Auto/Visual Lisp: [Select]
  1. (defun dblclk:enable ( key )
  2.     (dblclk:remove key)
  3.         (vlr-mouse-reactor key '((:vlr-begindoubleclick . dblclk:callback)))
  4.         'active-document-only
  5.     )
  6.         (vlr-dwg-reactor key '((:vlr-beginclose . dblclk:release)))
  7.         'active-document-only
  8.     )
  9. )
  10. (defun dblclk:remove ( key )
  11.         (foreach rtr (cdr grp)
  12.             (if (= key (vlr-data rtr)) (vlr-remove rtr))
  13.         )
  14.     )
  15.     (if (and (= 'vla-object (type dblclk:wsh:object)) (not (vlax-object-released-p dblclk:wsh:object)))
  16.         (progn
  17.             (vlax-release-object dblclk:wsh:object)
  18.             (setq dblclk:wsh:object nil)
  19.         )
  20.     )  
  21. )
  22. (defun dblclk:callback ( rtr arg )
  23.     (vl-catch-all-apply 'vlax-invoke (list (dblclk:wsh) 'sendkeys "{ESC}{UP}~"))
  24.     (princ)
  25. )
  26. (defun dblclk:release ( rtr arg )
  27.     (dblclk:remove "dblclk:reactor")
  28. )
  29. (defun dblclk:wsh ( )
  30.     (cond (dblclk:wsh:object) ((setq dblclk:wsh:object (vlax-create-object "wscript.shell"))))
  31. )
  32. (   (lambda ( )
  33.         (vl-load-com)
  34.         (dblclk:enable "dblclk:reactor")
  35.         (princ)
  36.     )
  37. )

But why not simply enable right-click enter?
« Last Edit: July 01, 2017, 09:12:00 AM by Lee Mac »

Grrr1337

  • Swamp Rat
  • Posts: 765
Re: Retrieve the last command call
« Reply #2 on: July 01, 2017, 09:42:25 AM »
Maybe something like this?
...

Ahh, SendKeys - I've forgot about this! :)

But why not simply enable right-click enter?

Thats a second option, haven't thought about it - although my suggested double-click LMB approach would be lazier.



Thank you Lee, I wasn't expecting a whole code reactor - but just an advice how to obtain that same last command.
Even your reply was super fast, like you coded it instantly, inside the quick reply post. :D

I guess it would be better to include this check to the callback function:

Code - Auto/Visual Lisp: [Select]
  1. (defun dblclk:callback ( rtr arg )
  2.   (and
  3.     (null (nentselp (car arg)))
  4.     (vl-catch-all-apply 'vlax-invoke (list (dblclk:wsh) 'sendkeys "{ESC}{UP}~"))
  5.   )
  6.   (princ)
  7. )
  8.  

Since doublecliking on polylines, AutoCAD invokes some other reactor that prompts with getkword (the "PEDIT" command)

You could patent it as "Lazy Reactor" under your name! :)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)

VovKa

  • Swamp Rat
  • Posts: 1352
  • Ukraine
Re: Retrieve the last command call
« Reply #3 on: July 01, 2017, 01:16:49 PM »
Thats a second option, haven't thought about it - although my suggested double-click LMB approach would be lazier.
i doubt that
(double-click LMB + programming) is no way lazier than (single click RMB + no programming)
;)

Grrr1337

  • Swamp Rat
  • Posts: 765
Re: Retrieve the last command call
« Reply #4 on: July 02, 2017, 03:13:58 AM »
Thats a second option, haven't thought about it - although my suggested double-click LMB approach would be lazier.
i doubt that
(double-click LMB + programming) is no way lazier than (single click RMB + no programming)
;)

You are right Vovka (I was wrong again), however I remembered why I purposely disabled my right click enter option - because I was using this "isolateobjects" tool.



Ofcourse theres the ribbon also, but I hate using it and I always keep it hidden (to work on a larger viewport size).

I remember that someone wrote this:
Quote
Every AutoCAD user works differently than the other.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)

Lee Mac

  • Seagull
  • Posts: 12502
  • London, England
Re: Retrieve the last command call
« Reply #5 on: July 02, 2017, 09:29:23 AM »
You are right Vovka (I was wrong again), however I remembered why I purposely disabled my right click enter option - because I was using this "isolateobjects" tool.


But you can have both - just do a long right-click to open the shortcut menu.

Grrr1337

  • Swamp Rat
  • Posts: 765
Re: Retrieve the last command call
« Reply #6 on: July 02, 2017, 04:45:48 PM »
But you can have both - just do a long right-click to open the shortcut menu.

I wasn't aware of this!
Thank you so much, Lee - I still appreciate the reactor solution you provided !
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)