How could I filter layers that contain no objects or freeze them using lisp? thanks for tips. paolo
Hi Paolo Try this: (defun C:FreezeUnusedLays ( / LayLst) (setq LayLst (mapcar '(lambda (l) (cdr (assoc 2 l)) ) (GetSymTbl "LAYER") ) ) (command "_.LAYER" "_SET" "0") (foreach Lay (cdr LayLst) (if (not (ssget "X" (list (cons 8 Lay)))) (command "_FRE" Lay) ) ) (command "") (princ) ) ; ; == Function GetSymTbl ; Reads the contents of a symboltable. ; Arguments [Type]: ; Nme = Symboltable name [STR] ; Return [Type]: ; > Symboltable list ; > False if table is empty ; Notes: ; None ; (defun GetSymTbl (Nme / CurTbl TblLst) (while (setq CurTbl (tblnext Nme (not CurTbl))) (setq TblLst (cons CurTbl TblLst)) ) (reverse TblLst) ) Cheers
A much faster approach is possible with AutoCAD 2005: (defun C:FreezeUnusedLayers (/ myDoc myLayers layer0) (vl-load-com) (setq myDoc (vla-Get-ActiveDocument (vlax-Get-Acad-Object)) myLayers (vla-Get-Layers myDoc)) (cond ((/= (getvar "CLayer") "0") (setq layer0 (vla-Item myLayers "0")) (vla-Put-Freeze layer0 :vlax-False) (vla-Put-ActiveLayer myDoc layer0))) (vla-GenerateUsageData myLayers) (vlax-For myLayer myLayers (cond ((= (vla-Get-Used myLayer) :vlax-False) (vla-Put-Freeze myLayer :vlax-True)))) (princ)) -- R. Robert Bell Hi Paolo Try this: