Alan, because this sort of list is needed frequently I have some stuff in my library to deal with it.
firstly, name the collections
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
(or g:AcadApplication
(setq g:AcadApplication (vlax-get-acad-object)))
(or g:ActiveDocument
(setq g:ActiveDocument (vla-get-activedocument g:AcadApplication)))
(or g:Layers
(setq g:Layers (vla-get-layers g:ActiveDocument)))
(or g:Blocks
(setq g:Blocks (vla-get-blocks g:ActiveDocument)))
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
Then, a routine to iterate over the collections, extracting the names
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;; Return list of all collection member names
;;;
(DEFUN KDUB:ListCollectionMemberNames (collection / itemname returnvalue)
(SETQ returnvalue '())
(VLAX-FOR each collection
(SETQ itemname (VLA-GET-NAME each)
returnvalue (CONS itemname returnvalue)
)
)
(REVERSE returnvalue)
)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
So that this becomes possible in your code
(setq Layer-List (KDUB:ListCollectionMemberNames g:Layers))
(setq Block-List (KDUB:ListCollectionMemberNames g:Blocks))
or in your particular case ;
(if (wcmatch "MyLayerName" (KDUB:ListCollectionMemberNames g:Layers))
;;>>
added: fixed the global variable initialisation