Jump to content

Delete everything on a layer (including what's inside a block)


Recommended Posts

Posted
Yeah, but it would have just been wierd to let that go on too long.

 

Oh I know, baby.:wink:

  • 3 months later...
  • Replies 26
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    8

  • alanjt

    7

  • KRBeckman

    6

  • ksperopoulos

    2

Posted
Perhaps:

 

(defun c:DeleteAll (/ *error* LAYER UFLAG)
 (vl-load-com)
 ;; Lee Mac  ~  23.02.10

 (defun *error* (msg)
   (and UFlag (vla-EndUndoMark *doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))

 (setq layer "Blah")

 (setq *doc (cond (*doc) ((vla-get-ActiveDocument
                            (vlax-get-acad-object)))))

 (if (and (tblsearch "LAYER" layer)
          (eq :vlax-false
              (vla-get-lock
                (vla-item (vla-get-Layers *doc) layer))))
   (progn
     (setq uFlag (not (vla-StartUndoMark *doc)))

     (vlax-for lay (vla-get-Layouts *doc)

       (vlax-for obj (vla-get-Block lay)

         (if (eq (strcase layer)
                 (strcase (vla-get-layer obj)))

           (vl-catch-all-apply
             (function vla-delete) (list obj)))))

     (vlax-for blk (vla-get-Blocks *doc)

       (vlax-for obj blk

         (if (eq (strcase layer)
                 (strcase (vla-get-layer obj)))

           (vl-catch-all-apply
             (function vla-delete) (list obj)))))

     (setq uFlag (vla-EndUndomark *doc)))

   (princ "\n** Layer Locked or Not Found **"))

 (princ))


 

Is there any way to get this to select all non-plotting layers even if they are frozen, off, locked, in a block, or in an attribute?

Posted

VVA - This didn't delete the objects on the non plotting layers. This is a lot of code. Not knowing how to manipulate something this large, is there something in particular I need to change to get it to delete the non plotting layers?

Posted
VVA - This didn't delete the objects on the non plotting layers.
BGLAYDEL - delete frozen and off layers with objects

There are 2 ways -

1. off non plotting layers

2. Found string vla-get-freeze. You will find this part of the code:

(if (or (= (vla-get-freeze item) :vlax-true)
    (= (vla-get-layeron item) :vlax-false)
) ;_ end of or

Add one more string

(if (or (= (vla-get-freeze item) :vlax-true)
   (= (vla-get-layeron item) :vlax-false)
[b][color="Red"]    (= (vla-get-Plottable item) :vlax-false)[/color][/b]
) ;_ end of or

  • 7 years later...
Posted

WCMATCH

(defun c:deleteall (/ *error* layer uflag)
 (vl-load-com)
 ;; Lee Mac  ~  23.02.10
 ;; RJP - 06.30.2017
 (defun *error* (msg)
   (and uflag (vla-endundomark *doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )
 ;; Separate layer names with commas for WCMATCH below ( removed check if layers are locked so it's up to you  )
 (setq layer (strcase "Layer1,Layer2,Layer3"))
 (setq	*doc (cond (*doc)
	   ((vla-get-activedocument (vlax-get-acad-object)))
     )
 )
 (setq uflag (not (vla-startundomark *doc)))
 (vlax-for lay	(vla-get-layouts *doc)
   (vlax-for obj (vla-get-block lay)
     (if (wcmatch (strcase (vla-get-layer obj)) layer)
(vl-catch-all-apply (function vla-delete) (list obj))
     )
   )
 )
 (vlax-for blk	(vla-get-blocks *doc)
   (vlax-for obj blk
     (if (wcmatch (strcase (vla-get-layer obj)) layer)
(vl-catch-all-apply (function vla-delete) (list obj))
     )
   )
 )
 (setq uflag (vla-endundomark *doc))
 (princ)
)

  • 2 years later...
Posted
On 6/29/2017 at 11:22 AM, ronjonp said:

WCMATCH

 


(defun c:deleteall (/ *error* layer uflag)
 (vl-load-com)
 ;; Lee Mac  ~  23.02.10
 ;; RJP - 06.30.2017
 (defun *error* (msg)
   (and uflag (vla-endundomark *doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )
 ;; Separate layer names with commas for WCMATCH below ( removed check if layers are locked so it's up to you  )
 (setq layer (strcase "Layer1,Layer2,Layer3"))
 (setq	*doc (cond (*doc)
	   ((vla-get-activedocument (vlax-get-acad-object)))
     )
 )
 (setq uflag (not (vla-startundomark *doc)))
 (vlax-for lay	(vla-get-layouts *doc)
   (vlax-for obj (vla-get-block lay)
     (if (wcmatch (strcase (vla-get-layer obj)) layer)
(vl-catch-all-apply (function vla-delete) (list obj))
     )
   )
 )
 (vlax-for blk	(vla-get-blocks *doc)
   (vlax-for obj blk
     (if (wcmatch (strcase (vla-get-layer obj)) layer)
(vl-catch-all-apply (function vla-delete) (list obj))
     )
   )
 )
 (setq uflag (vla-endundomark *doc))
 (princ)
)
 

 

Thank you very much.  I have been searching for a lsp to do exactly this for a week!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...