@Anonymous wrote:
dbhunia Your code worked great! I was able to delete all the frozen layers. rperez I am not sure if I did something incorrectly, but it only deleted some of the objects, ignored most of them, and did not delete the layers. Since it worked for you, I am pretty sure it is my fault, but it does not matter anymore. Thanks everyone for helping me with this!
I have another question, which might be dumb. Is there a way to remove x-ref layers in the same way?
Might just need to add a purge at the end of the code to remove the layers. You cannot remove xref layers.
Tried to modify the code above but missed the magical 30 minute mark ;/ .. so here it is again:
(defun c:frzlaydel (/ doc err fzl msg n n2)
;; RJP » 2019-07-19
(setq err 0)
(setq n 0)
(setq n2 0)
;; Get frozen layers
(vlax-for lay (vla-get-layers (setq doc (vla-get-activedocument (vlax-get-acad-object))))
(and (not (wcmatch (vla-get-name lay) "*|*"))
(or (eq (vla-get-freeze lay) :vlax-true) (eq (vla-get-layeron lay) :vlax-false))
(setq fzl (cons lay fzl))
(vla-put-lock lay :vlax-false)
)
)
(if (setq fzl (mapcar 'vla-get-name fzl))
(progn (vlax-for b1 (vla-get-blocks doc)
(vlax-for b2 b1
(if (vl-position (vla-get-layer b2) fzl)
(if (vl-catch-all-error-p (vl-catch-all-apply 'vla-delete (list b2)))
(setq err (1+ err))
(setq n (1+ n))
)
(setq n2 (1+ n2))
)
)
)
(setq msg (strcat (strcat (itoa err) " errors deleting objects...\n")
(strcat (itoa n) " objects were deleted, ")
(strcat (itoa n2) " objects were ignored.")
)
)
(if (zerop (getvar 'cmdactive))
(alert msg)
(princ msg)
)
(repeat 2 (vla-purgeall doc))
)
(princ (strcat "\nNo eligible layers found."))
)
(princ)
)