Here's one more take. Commented in code.
(setq CHK (tblsearch "Layer" "Xref")) ;
(if (= CHK Nil)
(command "_.Layer" "_N" "Notes" "_c" "9" "Notes" "")
) ;
(vl-load-com)
;; No need for separate reactors, one can handle all
;; Also, to avoid creation of more reactors, you
;; might want to check if it exists already by
;; assigning a global
(if (not *myCommandRectors*)
(setq *myCommandRectors*
(vlr-command-reactor
nil
'((:vlr-commandWillStart . startCommand)
(:vlr-commandEnded . endCommand)
(:vlr-commandCancelled . cancelCommand)
(:vlr-commandFailed . failedCommand)
)
)
)
)
;; Layer could have been purged in the meanwhile,
;; so it would probably be good to check if it exists
(defun startCommand (calling-reactor startcommandInfo / BGN)
(setq OLD (getvar 'CLAYER))
(setq BGN (nth 0 startcommandInfo))
(if (tblsearch "LAYER" "Notes")
(cond
((= BGN "TEXT") (setvar "CLAYER" "Notes"))
((= BGN "MTEXT") (setvar "CLAYER" "Notes"))
((= BGN "DTEXT") (setvar "CLAYER" "Notes"))
) ;cond
)
) ;defun
;; Just a precaution to check for global variable
;; before using it. To make it more failsafe it
;; should check for the OLD layer but .. let's not
;; get carried away?
(defun endCommand (calling-reactor endcommandInfo / EXT)
(setq EXT (nth 0 endcommandInfo))
(and (= (type OLD) 'STR)
(cond
((= EXT "TEXT") (setvar "CLAYER" OLD))
((= EXT "MTEXT") (setvar "CLAYER" OLD))
((= EXT "DTEXT") (setvar "CLAYER" OLD))
)
) ;cond
) ;defun
(defun cancelCommand (calling-reactor cancelcommandInfo / CNL)
(setq CNL (nth 0 cancelcommandInfo))
(and (= (type OLD) 'STR)
(cond
((= CNL "TEXT") (setvar "CLAYER" OLD))
((= CNL "MTEXT") (setvar "CLAYER" OLD))
((= CNL "DTEXT") (setvar "CLAYER" OLD))
)
) ;cond
) ;defun
(defun failedCommand (calling-reactor failedcommandInfo / FLD)
(setq FLD (nth 0 failedcommandInfo))
(and (= (type OLD) 'STR)
(cond
((= FLD "TEXT") (setvar "CLAYER" OLD))
((= FLD "MTEXT") (setvar "CLAYER" OLD))
((= FLD "DTEXT") (setvar "CLAYER" OLD))
) ;cond
)
) ;defun