Author Topic: Delete frozen layers. Nested blocks layers included.  (Read 1995 times)

0 Members and 1 Guest are viewing this topic.

Lonnie

  • Newt
  • Posts: 175
Delete frozen layers. Nested blocks layers included.
« on: January 09, 2020, 02:58:37 PM »
I am posting here instead of a first round at autodesk because I found this routine here. I need to change it slightly but I've failed at doing it.
I have been asked to delete all frozen layers and the entities on them. Including the entities in nested blocks. Here is what I am trying to use.

Quote
(defun c:lcu (/ ActDoc LayList LayNameList)
    ; Erases all objects on frozen layers, then purges drawing.
   
    (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
    (vlax-for Lay (vla-get-Layers ActDoc)
        (if
            (or
                (= (vla-get-Freeze Lay) ':vlax-true)
            )
            (progn
                (vla-put-Lock Lay :vlax-false)
                (setq LayList (cons Lay LayList)
                    LayNameList (cons (vla-get-Name Lay) LayNameList)
                )
            )
        )
    )
    (vla-StartUndoMark ActDoc)
    (if LayList
        (progn
            (vlax-for Layout (vla-get-Layouts ActDoc)
                (vlax-for Obj (vla-get-Block Layout)
                    (if (member (vla-get-Layer Obj) LayNameList)
                        (vla-Delete Obj)
                    )
                )
            )
            (vla-PurgeAll ActDoc)
        )
    )
    (vla-EndUndoMark ActDoc)
    (princ)
)


Nested blocks seem to be my problem. I've gotten it to work with blocks but never with nested blocks.
as a side note I have also tried to add versions of (command (c:-laydel) "n" lay "y") to the routine. That seems to clean the blocks pretty well but I can't seem to incorporate into the lisp well.
Thank you in advance.
« Last Edit: January 09, 2020, 03:40:45 PM by Lonnie »

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Delete frozen layers. Nested blocks layers included.
« Reply #1 on: January 09, 2020, 03:50:24 PM »
Try this quick mod:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:lcu (/ actdoc lnl n)
  2.   ;; Erases all objects on frozen layers, then purges drawing.
  3.   (vlax-for lay (vla-get-layers actdoc)
  4.     (and (not (wcmatch (setq n (vla-get-name lay)) "*|*"))
  5.          (= -1 (vlax-get lay 'freeze))
  6.          (progn (vlax-put lay 'lock 0) (setq lnl (cons n lnl)))
  7.     )
  8.   )
  9.   (if lnl
  10.     (progn (vla-startundomark actdoc)
  11.            (vlax-for b (vla-get-blocks actdoc)
  12.              (vlax-for obj b
  13.                (if (vl-position (vla-get-layer obj) lnl)
  14.                  (vl-catch-all-apply 'vla-delete (list obj))
  15.                )
  16.              )
  17.            )
  18.            (vla-purgeall actdoc)
  19.            (vla-endundomark actdoc)
  20.     )
  21.   )
  22.   (princ)
  23. )
« Last Edit: January 09, 2020, 04:11:40 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lonnie

  • Newt
  • Posts: 175
Re: Delete frozen layers. Nested blocks layers included.
« Reply #2 on: January 09, 2020, 03:54:14 PM »
That seems to work. Thank you.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Delete frozen layers. Nested blocks layers included.
« Reply #3 on: January 09, 2020, 04:12:50 PM »
That seems to work. Thank you.
Glad to help. FWIW, I edited the code above to exclude xref layers too.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lonnie

  • Newt
  • Posts: 175
Re: Delete frozen layers. Nested blocks layers included.
« Reply #4 on: January 09, 2020, 04:46:33 PM »
Ah yes thank you for that one. I am not sure I would have caught that.  :uglystupid2:
Typically we'll use this for base setups. It will be particularly handy for dwg's that are exported from Revit.