Catwoman Posted November 9, 2021 Posted November 9, 2021 Hello, I am looking for a LISP routine or instructions on how to create one that will delete (LAYDEL) specific layer names from the .dwg file. Any samples or assistance would be greatly appreciated, as I am new to writing lisp routines. Thank you! Quote
mhupp Posted November 9, 2021 Posted November 9, 2021 (edited) Do you want it to just delete the layer with out checking to see if anything is on it? (defun C:DeleteLayer () (vl-cmdf "_.Purge" "_LA" "layername" "_N") (princ) ) Change "layername" to the layer you want to delete. purged if empty. --EDIT--- Purging multiple layers by adding a , between layer names (vl-cmdf "_.Purge" "_LA" "layer1,layer2,layer3,layer4,layer5" "_N") or (setq layer "layer1,layer2,layer3,layer4,layer5") (vl-cmdf "_.Purge" "_LA" layer "_N") Edited November 10, 2021 by mhupp Quote
Catwoman Posted November 10, 2021 Author Posted November 10, 2021 @mhupp Thank you! The purge command is restricted to layers with no objects on them. I need to use the command LAYDEL in order to remove layers including elements on those layers, but it does not appear to allow me to delete multiple layers at one time. (defun C:delLayer () (vl-cmdf "_.laydel" "_Name" "S-WALL,S-WALL-BRNG,S-WALL-MISC,S-WALL-NBRG,S-WALL-OPEN,S-WALL-SHEA,1st_Floor_Dimensions,1st_Floor_Annotations,2nd_Floor_Dimensions,2nd_Floor_Annotations" "OK" "_deletelayer") (princ) ) Thank you for your assistance. c Quote
mhupp Posted November 10, 2021 Posted November 10, 2021 (edited) Forgot about that. This will delete everything on said layers then purge them. (defun C:DeleteLayer (/ layer) (vl-load-com) (setq layer "S-WALL,S-WALL-BRNG,S-WALL-MISC,S-WALL-NBRG,S-WALL-OPEN,S-WALL-SHEA,1st_Floor_Dimensions,1st_Floor_Annotations,2nd_Floor_Dimensions,2nd_Floor_Annotations") (vlax-for ent (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) ;deletes all objects on above layers (vlax-for obj ent ;regardless of where they are in the drawing. (if (wcmatch (vla-get-layer obj) layer) (vl-catch-all-apply (vla-delete obj)) ) ) ) ;(setvar 'clayer "0") ;change to a layer not getting deleted. (vl-cmdf "_.Purge" "_LA" layer "_N") ;purges layers listed above (princ) ) You could build a selection set and erase them, then purge. this would only work if everything is on the same tab like model space. if something was on another tab it wouldn't get deleted. (setq layer "S-WALL,S-WALL-BRNG,S-WALL-MISC,S-WALL-NBRG,S-WALL-OPEN,S-WALL-SHEA,1st_Floor_Dimensions,1st_Floor_Annotations,2nd_Floor_Dimensions,2nd_Floor_Annotations") (setq SS (ssget "_X" (list (cons 8 layer)))) (vl-cmdf "_.Erase" SS "") (vl-cmdf "_.Purge" "_LA" layer "_N") Edited November 10, 2021 by mhupp Quote
Jonathan Handojo Posted November 10, 2021 Posted November 10, 2021 (edited) 4 hours ago, mhupp said: You could build a selection set and erase them, then purge. this would only work if everything is on the same tab like model space. if something was on another tab it wouldn't get deleted. Using entdel would work though. Using SSGET X will get everything in the drawing. It's that when calling using commands that the selection set gets filtered to the current tab. Entdel or vla-delete will still take care of it. I also had to deal with this problem in my workplace and I came up with some dirty way to go about it though (it wasn't a good practice, but at least good enough to get it working for me). I gave up being very precise, because there's one key factor that I could not yet still solve. One factor you'd still need to check is if the layer is locked or frozen before deleting anything. But the worst factor is checking if you have any blocks that has objects currently using that layer and then purging that block first, and it gets worse with nested blocks. With nested blocks, you need to purge the inner block first before being able to purge the outer one, so finding that sequence (and blocks) matters as well. Otherwise entdel or vla-delete will either yield an error, or won't delete the object, which then the layer won't be deleted. Your DeleteLayer command gave me an idea though... I might try implementing some stuff. Edited November 10, 2021 by Jonathan Handojo 1 Quote
Recommended Posts
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.