I tried that but still slow. This is in a drawing that has 18k objects.
This seems to do the business, it's more or less instant.
Not sure why it says "*Invalid selection*" in the command line though....
(defun c:QSLAYERS_SELECTED_QUICK (/ *error* var_cmdecho var_osmode var_selectsimilarmode ss1)
(defun *error* (errmsg)
(and acDoc (vla-EndUndoMark acDoc))
(and errmsg
(not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*"))
(princ (strcat "\n<< Error: " errmsg " >>\n"))
)
(setvar 'cmdecho var_cmdecho)
(setvar 'osmode var_osmode)
(setvar 'selectsimilarmode var_selectsimilarmode)
)
(setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc))
(setq var_cmdecho (getvar 'cmdecho))
(setq var_osmode (getvar 'osmode))
(setq var_selectsimilarmode (getvar 'selectsimilarmode))
(setvar 'cmdecho 0)
(setvar 'osmode 0)
(setvar 'selectsimilarmode 2) ; Select by layer
(princ "Filter select all on selected object/s Layer/s :\n")
(setq ss1 (cond
((ssget "_I")) ; preselection, if any
((vl-cmdf "_.selectsimilar" pause)) ; User selection if no pre-selection
)
)
(if ss1 (vl-cmdf "_.selectsimilar" "")) ;; If the ss1 variable is a selection set
(*error* nil)
(princ)
)
; (c:QSLAYERS_SELECTED_QUICK)