@michaelZCXYL
I once recently ran into a similar problem.
I could have changed the selection to a "HIDDEN" layer, but that would have changed their inherited "bylayer" properties. So I decided to make them invisible with the option to make them all visible again or just report and show the grips of the invisible ones. It includes Undo control...
(defun C:Visible ( / *error* vars vals ss E Obj i N)
;; v1.0 (8-31-21) John F. Uhden
;; Program makes each entity in a selection set invisible, or
;; Makes all invisible objects visible, and
;; Has a Report option to inform of the number of invisible objects.
(gc)
(prompt "\nVisible v1.0 (c)2021, John F. Uhden\n")
(defun *error* (Error)
(mapcar 'setvar vars vals)
(vla-endundomark *doc*)
(cond
((not Error))
((wcmatch (strcase Error) "*QUIT*,*CANCEL*")
(vl-exit-with-error "\r ")
)
((wcmatch (strcase Error) "*CANCEL*,*QUIT*")
(vl-exit-with-error (strcat "\r*ERROR*: " Error))
)
)
(princ)
)
(or *acad* (setq *acad* (vlax-get-acad-object)))
(or *doc* (setq *doc* (vla-get-ActiveDocument *acad*)))
(vla-endundomark *doc*)
(vla-startundomark *doc*)
(setq vars '("cmdecho"))
(setq vals (mapcar 'getvar vars))
(mapcar 'setvar vars '(0))
(command "_.expert" (getvar "expert")) ;; dummy command
(initget 1 "INvisible iNvisible Report Visible")
(setq ans (getkword "\nMake selected objects iNvisible/Visible/Report: "))
(cond
((= ans "Report")
(setq ss (ssget "x" '((60 . 1))))
(setq N (sslength ss))
(princ (strcat "\nFound " (itoa N) " invisible entities."))
(sssetfirst nil ss)
)
((= ans "Visible")
(princ "\nAll invisible objects will be made visible.")
(getstring "\nHit any key to continue, or Esc to stop.")
(setq ss (ssget "x" '((60 . 1))))
(repeat (setq i (sslength ss))
(setq e (ssname ss (setq i (1- i)))
obj (vlax-ename->vla-object e)
)
(vlax-put obj 'Visible -1)
)
(princ (strcat "\n Made " (itoa (sslength ss)) " objects visible."))
)
(1
(princ "\nSelect objects to make invisible.")
(setq ss (ssget))
(repeat (setq i (sslength ss))
(setq e (ssname ss (setq i (1- i)))
obj (vlax-ename->vla-object e)
)
(vlax-put obj 'Visible 0)
)
(princ (strcat "\n Made " (itoa (sslength ss)) " objects invisible."))
)
)
(*error* nil)
)
(defun c:VIS ()(c:Visible))