If you want to check upon opening a drawing, you just need to have the routine autoload, and run it. You can have it autoload serval different ways. If the layer if going to be in a xref ALWAYS, then maybe something like
Code:
(defun LayExist (LayName)
(vl-catch-all-error-p
(vl-catch-all-apply
'(lambda ()
(vlax-for Lay (vla-get-Layers (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(if (wcmatch (strcase (vla-get-Name Lay)) (strcase (strcat "*|" LayName)))
(exit)
)
)
)
)
)
)
Edit: Didn't see the other part.
Code:
(defun LayExist (LayName)
(vl-catch-all-error-p
(vl-catch-all-apply
'(lambda ()
(vlax-for Lay (vla-get-Layers (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(if (wcmatch (strcase (vla-get-Name Lay)) (strcase (strcat "*|" LayName)))
(progn
(prompt (strcat "\n Layer on status = " (vl-princ-to-string (vla-get-LayerOn Lay))))
(prompt (strcat "\n Layer froze status = " (vl-princ-to-string (vla-get-Freeze Lay))))
(exit)
)
)
)
)
)
)
(princ)
)