Well, as I see it, the only advantage that this routine offers over the regular LayWalk command is the ability to ZOOM.
IMHO that's unnecessarily limited. I'll want to do more than that - the ability to do something with objects... select them, check the types, check the length, move them to a different layer, remove them for good... or whatever.
So my solution would be different. My routine does not stay active during the whole process. You will need to recall the routine to move to the next layer. But that is quite easy because the command is the last one, so just hit <enter>. When you need to run another command during the process - you're good to go... after you're done, recall the routine and you'll move to the next layer.
Well, to be honest, I wrote it according to my own idea of preferable workflow, for my own usage. But if you find that this makes sense to you as well, your welcome to use it. Feel free to rename it.
(vl-load-com)
; Funtions of LayerWalkOnebyOne
; LWOneByOne or NL - main funtion. Set the mask if any, command will show the first layer.
; For next layer run the command again.
; The run next to the last layer will reset layer state.
; LW_RestoreLayerState - restore layer state from "$NL-TMP" which will be erase. But you can still continue in LWOneBeOne
; LW_NewWalkRestoreLayerState - restore layer state from "$NL-TMP" which will be erase. You will start over.
; BeekeeCZ 2018-11
;-----
(defun c:LW_RestoreLayerState ()
(and (layerstate-restore "$NL-TMP" nil)
(layerstate-delete "$NL-TMP"))
(princ))
;-----
(defun c:LW_NewWalk ()
(and (layerstate-restore "$NL-TMP" nil)
(layerstate-delete "$NL-TMP"))
(setq *lw1-lst* nil)
(princ "\nType to run 'LWOnebyOne'")
(princ))
;-----
(defun c:NL nil (c:LWOnebyOne))
(defun c:LWOnebyOne (/ *error* cmd :GetLayers doc flt)
(defun *error* (errmsg)
(if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
(princ (strcat "\nError: " errmsg)))
(if cmd (setvar 'cmdecho cmd))
(princ))
(defun :GetLayers (doc flt / layname lst)
(vlax-for layer (vla-get-layers doc)
(if (and (not (wcmatch (setq layname (vla-get-name layer)) "*|*"))
(wcmatch (strcase layname) (strcase (strcat "*" flt "*")))
)
(setq lst (cons layname lst))))
(vl-sort lst '<))
(setq cmd (getvar 'cmdecho))
(setvar 'cmdecho 0)
(if (cond (*lw1-lst*)
((layerstate-restore "$NL-TMP" nil)
(layerstate-delete "$NL-TMP")
*lw1-lst*)
((setq flt (getstring T "\nFilter layer by mask <all>: ")
doc (vla-get-activedocument (vlax-get-acad-object))
*lw1-lst* (:GetLayers doc flt))
(vl-cmdf "_.-LAYER" "_stAte" "_Save" "$NL-TMP" "" "" "")
(not (graphscr))))
(progn
(command "_.-LAYER" "_Thaw" (car *lw1-lst*) "_Set" (car *lw1-lst*) "_Freeze" "*" "")
(princ (strcat "\rCurrent layer: " (car *lw1-lst*) " >> next " (itoa (length (setq *lw1-lst* (cdr *lw1-lst*)))) " layers "))))
(*error* "end")
)