Purging contents of layer 0.

Please advise what I may be missing. I'm sure it's something simple. A missing "(" or ")". I am somewhat copying info from another source, too. Thanks!

; DLZ - Delete Contents of Layer 0 in Plasma Drawing
(defun c:DLZ ( / OldFormat ) ; Ignore "Oldformat". Is for additional routine.
(progn
(setvar "CLAYER" "3") ; set to Layer 3 - line layer
(command "_.LAYDEL" "_N" "0" "" "_Y")
(setvar "CLAYER" "0") ; reset to Layer 0
)
(princ (strcat "\Contents of Layer 0 deleted.")
)

(c:DLZ) ; auto run on loading

Comments

  • Jerryfiedler
    edited June 15

    I am not sure but I do not believe you can delete layer 0. This is a "system" layer that needs to exist. You, of course, can delete all of the data on layer 0 the same way you would delete data on any layer. Simply select everything and then delete.

    Sorry, I misread your post. You are not trying to delete the layer only the contents.

  • This should do what you want:

    ; Clear Layer Zero
    (defun c:clear0 (/ ss i entnm)
    (setq ss (ssget "_X" '((8 . "0"))))
    (setq i -1)
    (repeat (sslength ss)
    (setq entnm (ssname ss (setq i (1+ i))))
    (entdel entnm)
    )
    (princ (strcat "\Contents of Layer 0 deleted."))
    (princ)
    )
    (c:clear0)

    Sorry, I cannot get the insert code button to work!

  • Agree with Jerry delete via a selection set, you can make the code a bit more generic for any layer.

    (setq lay (cdr (assoc 8 (entget (car (entsel "\nPick an object for layer name "))))))
    (setq ss (ssget "_X" (list (cons 8 lay))))

    (princ (strcat "\nContents of Layer " lay " " (rtos (sslength ss) 2 0) " items deleted."))

  • Such approach however, will not delete objects inside blocks or elements which are parts of more complex objects like dimensions. If you want to clear selected layer from all objects (not necessarily delete them) the simplest way is to use ‘merge to’ command in layer panel.