I use reactors to save the last entity to a variable when a command such as paste or copy will start, then collect the new entities created when a command ends. I access those entities with a command that uses the variable for selection, example c:SEPP selects previous created, c:MPP moves previous created. (I use c:MP to move previous selection).
(defun c:ML () (command "MOVE" "L" "") (princ))
(defun c:MP () (command "MOVE" "P" "") (princ))
(defun c:MPP () (if (not SAA_Previous) (setq SAA_Previous "P"))(command "MOVE" SAA_Previous "") (princ)) ;; move previous from saved variable
(defun c:SEPP () (if (not SAA_Previous) (setq SAA_Previous "P"))(command "SELECT" SAA_Previous "")(sssetfirst SAA_Previous SAA_Previous) (princ))
(defun c:CP () (command "COPY" "P" "") (princ))
(defun c:CPP () (if (not SAA_Previous) (setq SAA_Previous "P"))(command "COPY" SAA_Previous "") (princ)) ;; move previous from saved variable
I don't have time to extract just the reactor code for above as an example, but attached is my full reactor file. It won't run by itself as it depends on lots of subroutines from another file, but it contains the full structure of setting up reactors based on Eric Schneider's Autolay and vlr-manager. Search for SAA_Previous_Last for where it is called by the reactors.
This code does the same as mhupp above, except deals with last subentities.
;;;==============================================================================
;;; Returns selection set of all entities after passed in entity name
;;; taken from CAD Cookbook utilities
;;;==============================================================================
(defun SAA_AFTER (ename / ss)
(setq ss (ssadd)) ;create selection set
(if ename
(while (setq ename (entnext ename))
(ssadd ename ss) ;add entities to set
)
;;; (setq ss (ssget "X")) ;if no last entity, get all
) ;end if
(if (> (sslength ss) 0) ss) ;return nil if no entities
)
;;;==============================================================================
;;; Returns last entity, even subentities on polylines
;;; used to ensure SAA_AFTER skips to the next full entity, not just a subentity
;;;
;;; by roy_043 from http://www.theswamp.org/index.php?topic=35626.msg408522#msg408522
;;;==============================================================================
(defun SAA_GetLast ( / ent newEnt)
(setq ent (entlast))
(while (and
ent
(setq newEnt (entnext ent))
)
(setq ent newEnt)
)
ent
)
saa_reactors.lsp