Jump to content

Simple Layer Delete Lisp


GregGleason

Recommended Posts

This is a simple "delete these layers" lisp program.

 

I get drawings where I have to delete layers that are not on an approved list. So I just figure out what the unapproved layers are, make sure they don't have objects and are not frozen, then run the lisp to delete them.

 

It seems to works ok. Is this the way to do it?

 

Here is the code:

 

(defun C:DelLayers ()
(setvar 'CMDECHO 0)
(command "_.-layer" "_T" "0" "_ON" "0" "_S" "0" "")
; -----------------------------------------------
(command "_PURGE" "_LAY" "_11-2605G1K-1-24" "_NO")
(command "_PURGE" "_LAY" "_11-2606G1K-1-24" "_NO")
(command "_PURGE" "_LAY" "_11-2607G1K-1-24" "_NO")
(command "_PURGE" "_LAY" "_11-2608G1K-1-24" "_NO")
(command "_PURGE" "_LAY" "_G1K-1" "_NO")
; -----------------------------------------------
(setvar 'CMDECHO cmdecho)
)

Greg

Link to comment
Share on other sites

Looks good to me. You could purge them all on one line using commas if you like.

 

You might explore using the LAYDEL command, if you don't care about the entities on those layers. It will delete them and the layer.

LAYMRG can delete the layer and move the objects to another layer first.

Link to comment
Share on other sites

You could give this a try too:

(defun c:dellayers (/ e)
 (foreach layer '("_11-2605G1K-1-24" "_11-2606G1K-1-24" "_11-2607G1K-1-24" "_11-2608G1K-1-24")
   (if	(setq e (tblobjname "layer" layer))
     (vl-catch-all-apply 'vla-delete (list (vlax-ename->vla-object e)))
   )
 )
 (princ)
)

 

I'm surprised that your code works .. it should fail here: (setvar 'CMDECHO cmdecho) since 'cmdecho' is never set?? Perhaps you have a global set from somewhere else.

Link to comment
Share on other sites

You could give this a try too:

(defun c:dellayers (/ e)
 (foreach layer '("_11-2605G1K-1-24" "_11-2606G1K-1-24" "_11-2607G1K-1-24" "_11-2608G1K-1-24")
   (if	(setq e (tblobjname "layer" layer))
     (vl-catch-all-apply 'vla-delete (list (vlax-ename->vla-object e)))
   )
 )
 (princ)
)

 

I'm surprised that your code works .. it should fail here: (setvar 'CMDECHO cmdecho) since 'cmdecho' is never set?? Perhaps you have a global set from somewhere else.

 

Hmmmm... well that explains the error. I'll comment it out and see what it should be set to.

 

Your code looks interesting in that I think I might be able to use a file to read the approved layers and then take out all the ones not on the list. Thanks!

 

Greg

Link to comment
Share on other sites

Hmmmm... well that explains the error. I'll comment it out and see what it should be set to.

 

Your code looks interesting in that I think I might be able to use a file to read the approved layers and then take out all the ones not on the list. Thanks!

 

Greg

 

This is what you should do for resetting your variable:

(defun c:dellayers (/ cmd)
 (setq cmd (getvar 'cmdecho))
 (setvar 'cmdecho 0)
 ;; Code ...
 (setvar 'cmdecho cmd)
)

Link to comment
Share on other sites

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...