@zasanil wrote:
pbejse,
If I wanted to change your code to include locked layers and the multiple names like you mentioned, how would I do that? I don't usually use locked layers, but you never know what might show up.
Henriques code is almost exactly what you want except the multiple names.
Question for you, why not use the native laydel command? by typing "N' at this prompt
Select object on layer to delete or [Name]: N
a list box will appear for multiple layer name selection, almost similar to wildcard matching.
Anyhoo, if you are skilled in lisp coding you can incorporate the snippet i posted at post#8 alongwith Hmsilva's code
FWIW. I would write it this way without the use laydel, allow multiple names and consider locked layers
(defun c:DLAO ( / aDoc ll laylst l2del Layn docLayers)
(setq LL nil
l2del nil
laylst nil
aDoc (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for ln (setq docLayers (vla-get-layers aDoc))
(if (eq :vlax-true (vla-get-lock ln))
(progn
(vla-put-lock ln :vlax-false)
(setq ll (cons ln ll))
)
)
)
(While
(and
(setq Layn (getstring "\nEnter Layer to Delete: <Enter for none>"))
(/= Layn "")
(print (setq laylst (cons (strcase Layn) laylst)))
)
)
(vlax-for itm (vla-get-blocks adoc)
(if (eq (vla-get-isxref itm) :vlax-false)
(vlax-for obj itm
(if (vl-some '(lambda (ln)
(wcmatch (strcase (vla-get-layer obj)) ln)) laylst)
(progn
(if (not (assoc (setq _ln (vla-get-layer obj)) l2del))
(setq l2del (cons (list _ln (vla-item docLayers _ln)) l2del)))
(vla-delete obj)
)
)
)
)
)
(foreach a ll (vla-put-lock a :vlax-true))
(foreach l2d (mapcar 'cadr l2del)
(vla-delete l2d))
(vla-regen adoc acallviewports)
(princ)
)
(vl-load-com) (princ)