Here is an old one you can look at, not the best example.
;;;=================[ GetLayerProp.lsp ]=======================
;;; Author: Copyright© 2007 Charles Alan Butler
;;; Version: 1.0 Oct. 23, 2007
;;; Purpose: To get list of layers matching the property
;;; Sub_Routines: -None
;;;===========================================================
;;; Argument: property
;;; property is a flag for which layer property to get
;;; property may be a single string or a list of strings
;;; valid strings are not case sensitive:
;;; "OFF" "FROZEN" "LOCKED" "NoPLOT" "COLOR"
;;; "ON" "THAWED" "UNLOCKED" "PLOT" "ALL"
;;; If "ALL" is not included a list of list is returned
;;; The lists are of matching layers, nil if none
;;; The return list is in the order of the properties quired
;;; "COLOR" returns a list of '(layername color)
;;; Other options return a list of layer names
;;; "ALL" is the flag to combine into one list where the layers
;;; must meet all the conditions
;;; Like All layers that are ON, THAWED & LOCKED
;;; Properties that may not be used together with "ALL" are:
;;; "OFF" "ON"
;;; "FROZEN" "THAWED"
;;; "LOCKED" "UNLOCKED"
;;; "NoPLOT" "PLOT"
;;; "COLOR" "ALL"
;;; If they are used togather with ALL, nil is returned
;;; If COLOR is used with ALL, COLOR is ignored
(defun GetLayerProp (property / bit layName Offlayers Onlayers
Frozenlayers Thawedlayers NoPlotlayers Plotlayers
Lockedlayers UnLockedlayers itm lst ColorOk
Colorlayers layName Result IndexList)
(setq lst '("OFF" "FROZEN" "LOCKED" "NOPLOT" "COLOR"
"ON" "THAWED" "UNLOCKED" "PLOT" "ALL"))
(cond
((null property)
(prompt "\n*** ERROR: NULL properties ***")
nil ; return nil
)
((and (not (listp property)) ; single condition
(setq property (list property))
nil ; cause a fall through
)
)
((and (setq property (mapcar 'strcase property))
(vl-remove-if '(lambda (x) (member x lst)) property))
(prompt "\n*** Error in properties name ***")
nil ; error in properties name
)
(t
(if (and (vl-position "ALL" property)(vl-position "COLOR" property))
(progn
(setq property (vl-remove "COLOR" property))
(prompt "\n*** ERROR: Color property removed ***")
)
)
(setq ColorOk (vl-position "COLOR" property))
;; Get list of layer names
(vlax-for layobj (vla-get-layers
(vla-get-activedocument (vlax-get-acad-object)))
(setq layName (vla-get-name layobj))
(if (= (vla-get-layeron layobj) :vlax-false)
(setq Offlayers (cons layName Offlayers))
(setq Onlayers (cons layName Onlayers))
)
(if (= (vla-get-freeze layobj) ':vlax-true)
(setq Frozenlayers (cons layName Frozenlayers))
(setq Thawedlayers (cons layName Thawedlayers))
)
(if (= (vla-get-lock layobj) ':vlax-true)
(setq Lockedlayers (cons layName Lockedlayers))
(setq UnLockedlayers (cons layName UnLockedlayers))
)
(if (= (vla-get-plottable layobj) ':vlax-false)
(setq NoPlotlayers (cons layName NoPlotlayers))
(setq Plotlayers (cons layName Plotlayers))
)
(if ColorOk
(setq Colorlayers
(cons (list layName (vla-get-color layobj)) Colorlayers))
)
)
)
)
;; return set up
(setq IndexList '(("ON" Onlayers)
("OFF" Offlayers)
("FROZEN" Frozenlayers)
("THAWED" Thawedlayers)
("LOCKED" Lockedlayers)
("UNLOCKED" UnLockedlayers)
("NOPLOT" NoPlotlayers)
("PLOT" Plotlayers)
("COLOR" Colorlayers)
))
(if (vl-position "ALL" property)
(progn ; Return names common to all list in property
(foreach itm IndexList
(if (vl-position (car itm) property)
(if Result
(setq Result (vl-remove-if-not '(lambda (x) (member x Result)) (eval (cadr itm))))
(setq Result (eval (cadr itm)))
)
)
)
Result
)
(progn ; Return individual list in order of request
(foreach itm property
(if (setq lst (eval (cadr (assoc itm IndexList))))
(setq Result (cons lst Result))
)
)
(setq Result (reverse Result))
)
)
Result
)
(defun c:test(/ lst)
;; return a single list with all of these properties
;; i.e. Frozen and locked and on
(setq lst '("ALL" "FROZEN" "LOCKED" "ON"))
;; i.e. Frozen and locked and off
(setq lst '("ALL" "FROZEN" "LOCKED" "OFF"))
;; i.e. Frozen and locked, could be on or off
(setq lst '("ALL" "FROZEN" "LOCKED"))
;; return a list of off and a seperate list of locked
(setq lst '("OFF" "locked"))
;; return a list of off and a seperate list of color
(setq lst '("OFF" "color"))
(setq lst '("ALL" "FROZEN" "LOCKED" "ON"))
(setq result (GetLayerProp lst))
(princ)
)