Jump to content

Erase layer...


LISP2LEARN

Recommended Posts

What 'em I doing wrong here? I have several entities on the sketch layer and after sketching I want to delete that layer and all entities under it. I want to use the "laydel" command but I can't suppress the dialog box. I know that I can't delete a layer if it has entities referencing it. Can you point me out on the right direction. Thanks

 

(vl-load-com)
(setq MYLAYERS (vla-get-activedocument (vlax-get-acad-object))) 
(vla-delete (vla-get-layers MYLAYERS) "A-Sketch")

Link to comment
Share on other sites

I still find plain autolisp much more elegant and simple :

 

(if (setq ss (ssget "X" '((8 . "A-Sketch")))
   (command "_.ERASE" ss ""))

Link to comment
Share on other sites

I want to use the "laydel" command but I can't suppress the dialog box.

 

Have you tried this?

(vl-cmdf "-laydel" "_N" "A-BLDG" "" "_Y")
;;; replace "A-BLDG" with the layer name you want to delete

Link to comment
Share on other sites

thanks David,

 

Yes, this erase all entities under the A-Sketch layer but still, it doesn't delete the attributes on the blocks which are on this layer and doesn't delete the layer itself. I have some blocks with attributes and the attributes are on the A-Sketch also but not the block which is on a different layer. I want to delete those attributes also under the block but not the block.

 

I still find plain autolisp much more elegant and simple :

 

(if (setq ss (ssget "X" '((8 . "A-Sketch")))
   (command "_.ERASE" ss ""))

Link to comment
Share on other sites

thanks David,

 

I have some blocks with attributes and the attributes are on the A-Sketch also but not the block which is on a different layer. I want to delete those attributes also under the block but not the block.

 

Now that sounds dangerous...

 

-David

Link to comment
Share on other sites

If nothing is referencing your layer (including objects in blocks etc.), then this demonstrates how to delete the layer from the layer collection (assuming the layer exists):

 

(setq LayerCollection (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
     LayerItem       (vla-item LayerCollection [color=red]"YourLayerName"[/color])
)
(vla-delete LayerItem)

Link to comment
Share on other sites

Thanks David & rkmcswain,

 

The answer is right in front of me. Didn't know about "_(user input)" which suppress the dialog box.

Link to comment
Share on other sites

Thanks David & rkmcswain,

 

The answer is right in front of me. Didn't know about "_(user input)" which suppress the dialog box.

 

As you probably know by now, LAYDEL will delete entities on the selected layer and redefine blocks, deleting entities on that layer.

Another similar, less dangerous route would be to use LAYMRG and merge all of the unwanted layers to a new layer that you can review later. Just a thought.

Link to comment
Share on other sites

Thanks Lee, very informative. I'm always impress on how you squeeze your code.

 

I guess, I can do that too. Here it goes..

 

(Setq thanks "tnx li, ur da besttttttttttttttttttttttttttttt")

(setq tnx (vl-string-right-trim "ttttttttttttttttttttttttttt " thanks))

(princ (strcat (tnx "LOL"))

Link to comment
Share on other sites

Thanks for the concern, I'm fairly knowledgeable with autocad commands but not with lisp and now, I'm trying to write simple code to make my autocad life much simpler. Thanks rkmcswain, I owe you one.

 

As you probably know by now, LAYDEL will delete entities on the selected layer and redefine blocks, deleting entities on that layer.

Another similar, less dangerous route would be to use LAYMRG and merge all of the unwanted layers to a new layer that you can review later. Just a thought.

Link to comment
Share on other sites

Thanks for the concern, I'm fairly knowledgeable with almost all autocad commands but not with lisp and now, I'm trying to write simple code to make my autocad life much simpler. Thanks rkmcswain, I owe you one.

 

As you probably know by now, LAYDEL will delete entities on the selected layer and redefine blocks, deleting entities on that layer.

Another similar, less dangerous route would be to use LAYMRG and merge all of the unwanted layers to a new layer that you can review later. Just a thought.

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