I haven't had my first coffee yet but perhaps this approach ...
(defun _change_layer ( type-pattern layer-name / ss i )
(if (setq ss (ssget "_X" (list (cons 0 type-pattern) (cons 8 (strcat "~" layer-name)))))
(progn
(vl-load-com)
(vl-catch-all-apply 'vla-add (list (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) layer-name))
(repeat (setq i (sslength ss))
(vl-catch-all-apply 'vlax-put (list (vlax-ename->vla-object (ssname ss (setq i (1- i)))) 'layer layer-name))
)
(sslength ss)
)
)
)
Then ...
(defun c:LV ( )
(_change_layer "VIEWPORT" "VIEWPORT")
(princ)
)
(defun c:DLDL ( )
;; may need to wildcard the type-pattern
(_change_layer "DIMENSION" "DIM")
(princ)
)
(defun c:DLHATCH ( )
(_change_layer "HATCH" "HATCH")
(princ)
)
Cheers.