You don't need another script.
But here's one anyway.
Maybe it helps someone who needs parts of this code some day
command Test2
(vl-load-com)
;; if no parameter if given, then a list of all layers is given.
;; if a layer is given, the function returns True when the layer is "On", "not frozen" and "not locked". Else nil is returned
(defun get_layers (lay / lyr table ret)
(setq ret T)
(vlax-for lyr
(vla-get-layers
(vla-get-activedocument
(vlax-get-acad-object)
)
)
(if (= (vla-get-name lyr) lay)
(if
(and
(= :vlax-true (vla-get-layeron lyr))
(= :vlax-false (vla-get-freeze lyr))
(= :vlax-false (vla-get-lock lyr))
)
(setq ret T)
(setq ret nil)
)
)
(setq table (cons (vla-get-name lyr) table))
)
(if lay
ret
table
)
)
(defun c:test ( / )
(get_layers nil)
)
(defun c:test2 ( / ss ss2 i)
(setq ss (ssget "_X" (list (cons 0 "*POLYLINE"))))
(setq i 0)
(setq ss2 (ssadd))
(repeat (sslength ss)
(setq obj (ssname ss i))
(if (get_layers (cdr (assoc 8 (entget obj)))) ;; will skip things of layers that are off/frozen/locked
(setq ss2 (ssadd (ssname ss i) ss2))
)
(setq i (+ i 1))
)
(sssetfirst nil ss2)
(princ)
)