Display full version of the post: Retrieving last command

ver101101
13.02.2015, 19:14
Do you know how to retrieve the last command entered at the command prompt via autolisp program. Accessing this is only available at the pop-up menu or by pressing enter.  Is there a (getvar "lastcommand variable")? Thanks.

Kent Cooper
16.02.2015, 15:38
[QUOTE=ver101101]
Do you know how to retrieve the last command entered at the command prompt via autolisp program. Accessing this is only available at the pop-up menu or by pressing enter.  Is there a (getvar "lastcommand variable")? Thanks.[/QUOTE]





 
Here's one way to force it, by temporarily recalling the last command and looking at what commands are then active:
 
(progn (command "" (setq lastcommand (getvar 'cmdnames))))
 
That will put the command name into the lastcommand variable, and leave you with an error message about invalid input -- follow it with another (command) function with no arguments to cancel the re-invoked command, however including that additional (command) within the (progn) function doesn't work.  [There may be a way to use (vl-catch-all-apply) to avoid delivery of that error message, but in some quick tries I didn't find the right format.]
 
EDIT:  However, that will work only if the command requires input, and is therefore still running at the time it gets to the (setq) function.  It won't work if the last command was something requiring no input, such as REDRAW, REGEN, LAYERP, etc. -- the lastcommand variable will then have "" in it.  And if that's likely at times when you might use something like this, you might not want to -- you probably wouldn't want to run [for instance] LAYERP again just in order to find out that it was the last command.Kent Cooper2015-02-17 15:08:25