I have some code to put the Xref on the right layer it works for all commands part from when I use the attachments window and use Attach DWG..., I am working on Bricscad and on the command line the command is ._-XREF however when I add that command to my .lsp it does not seem to work.
Please see code below.
;;Command Reactor for Xref layer
;;D.C. Broad 2012
(if (null myxr-react)
(setq myxr-react (vlr-command-reactor nil '((:vlr-commandwillstart . myxr-swaplayer)
(:vlr-commandended . myxr-restorelayer)
(:vlr-commandcancelled . myxr-restorelayer))))
)
(defun setormakelayer (layn doc)
(if (null (tblsearch "layer" layn))
(vla-add (vla-get-layers doc) layn))
(setvar "clayer" layn)
)
;;commandwillstart callback (reactor commandlist)
(defun myxr-swaplayer (r cl / doc)
(if (member (car cl) '("XATTACH" "XREF" "._-XREF" "_.XATTACH"));allowance for other commands
(progn
(setq doc (vlr-document r))
(vlr-data-set r (getvar "clayer"))
(if
(= 1 (vla-get-activespace doc))
(setormakelayer "z_xref" doc)
(setormakelayer "z_xref" doc)
))))
;;commandended callback (reactor commandlist)
(defun myxr-restorelayer (r cl)
(if (and (member (car cl) '("XREF" "XATTACH"))
(vlr-data r))
(setvar "clayer" (vlr-data r))
(vlr-data-set r nil)
)
)