filter empty layers

Discussion in 'AutoCAD' started by p.bassetto, Jun 2, 2004.

  1. p.bassetto

    p.bassetto Guest

    How could I filter layers that contain no objects or freeze them using lisp?
    thanks for tips.
    paolo
     
    p.bassetto, Jun 2, 2004
    #1
  2. p.bassetto

    Jürg Menzi Guest

    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
     
    Jürg Menzi, Jun 2, 2004
    #2
  3. p.bassetto

    p.bassetto Guest

    thanks it works
     
    p.bassetto, Jun 2, 2004
    #3
  4. p.bassetto

    Jürg Menzi Guest

    Hi Paolo

    Welcome...

    Cheers
     
    Jürg Menzi, Jun 2, 2004
    #4
  5. 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:
     
    R. Robert Bell, Jun 2, 2004
    #5
  6. p.bassetto

    Jürg Menzi Guest

    Hi Robert
    Cool, I wasn't aware about this new implemenation in VL - thx.

    Cheers
     
    Jürg Menzi, Jun 2, 2004
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.