leonucadomi Posted October 24, 2022 Posted October 24, 2022 hello all: Is there a routine that allows me to select an element and delete all the elements including the layer ? thanks Quote
Steven P Posted October 24, 2022 Posted October 24, 2022 Copied this in the depths of time, sorry no reference to where it came from. This deletes and then purges all objects on a layer doing what you want so long as there are no elements for example in a block that are on the specified layer. Can change this to have an 'entsel' an entity and grab the layer name from using assoc and 8, though I am sure someone will have this all set up, this will give you a start (defun c:laydelLayerNamw (/ ent l_name ss cntr amt ssent) (setq MyLayer "LayuerName") (setvar 'clayer "0") (progn (setq ss (ssget "X" (list (cons 8 MyLayer))) ;; create a selection set of all entites on layer cntr (1- (sslength ss)) ;; set 'cntr' to number of items in selection set amt (itoa cntr) ;; make a string from an integer ) ;; does the sel set have anything in it (if (> cntr 1) (while (>= cntr 0) ;; as long as 'cntr' is greater than or equal to 0 keep looping (setq ssent (ssname ss cntr)) ;; extract the ename from the sel set (entdel ssent) ;; delete that entity (setq cntr (1- cntr)) ;; subtract 1 from cntr ) ) ) (command "zoom" "all" "zoom" ".95x") (command "_.purge" "LA" MyLayer "N") (princ (strcat "\nErased " amt " items")) (princ) ) 2 Quote
mhupp Posted October 24, 2022 Posted October 24, 2022 (edited) Here is mine This allows you to just select with the mouse. and then prompts "Delete Contents and Layer: "layer name" [<Yes>/No]: " with the default answer being yes so you can just enter/right click. only changes current layer if its the one being deleted. ;;----------------------------------------------------------------------------;; ;; Delete everything on and the layer itself (defun c:Del-layer (/ lay SS rep e) (setq lay (cdr (assoc 8 (entget (car (entsel)))))) (setq SS (ssget "_X" (list (cons 8 lay)))) (sssetfirst nil ss) (initget "Yes No") (setq rep (cond ((getkword (strcat "\nDelete Layer \"" lay "\" & " (rtos (sslength ss) 2 0) " Entity's: [<Yes>/No]: "))) ("Yes") ) ) (cond ((= rep "Yes") (if (eq (getvar 'clayer) lay) (setvar 'clayer "0") ) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (vla-delete (vlax-ename->vla-object ent)) ;will delete even if in another paper space. ) (setq e (tblobjname "layer" lay)) (vla-delete (vlax-ename->vla-object e)) (prompt (strcat "\nLayer " lay " Deleted")) ) ) (princ) ) Edited October 25, 2022 by mhupp Code Updated 3 Quote
BIGAL Posted October 24, 2022 Posted October 24, 2022 (edited) What about Laydel. (command "-laydel" "Name" (cdr (assoc 8 (car (entesel "\nPick object for layer ")))) "" "Y") Edited October 24, 2022 by BIGAL 1 1 Quote
Jonathan Handojo Posted October 25, 2022 Posted October 25, 2022 Haha, BIGAL beat me to it... I was gonna say there's the LAYDEL command. You don't even need a LISP routine for this. 1 Quote
leonucadomi Posted October 25, 2022 Author Posted October 25, 2022 It's true I know LAYDEL , but I want to make the command more comfortable , and i like this lsp : ;;----------------------------------------------------------------------------;; ;; Delete everything on and the layer itself (defun c:dellayers (/ lay e) (setq lay (cdr (assoc 8 (entget (car (entsel)))))) (initget "Yes No") (setq rep (cond ((getkword (strcat "\nDelete Contents and Layer: \"" lay "\" [<Yes>/No]: "))) ("Yes") ) ) (cond ((= rep "Yes") (if (eq (getvar 'clayer) lay) (setvar 'clayer "0") ;switch to 0 if current layer is the one you want to delete ) (setq SS (ssget "_X" (list (cons 8 lay)))) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (vla-delete (vlax-ename->vla-object ent)) ) (setq e (tblobjname "layer" lay)) (vla-delete (vlax-ename->vla-object e)) ) ) (princ) ) from mhupp but i would like to improve it. for example: 1.- indicate the number of deleted elements 2.- show the selection of objects previus..before deleting it's possible? Quote
mhupp Posted October 25, 2022 Posted October 25, 2022 (edited) Yeah, but if your selection set is a large number of entity's grips wont show up and will only be dashed. --edit updated code above Edited October 25, 2022 by mhupp Quote
leonucadomi Posted October 25, 2022 Author Posted October 25, 2022 no matter. the purpose is to preview the selection in any way. that gives me comfort knowing that I decide to delete Quote
Steven P Posted October 25, 2022 Posted October 25, 2022 I'm going to give you a load of work mhupp..... zoom to each entity in the selection set and get the OP to confirm 'delete' or not, then once the selection set is empty, deleted everything, delete the layer? Can't have it both ways, delete the layer and everything or select the items and confirm them one at a time to delete 2 Quote
leonucadomi Posted October 25, 2022 Author Posted October 25, 2022 THANKS TO THE DISCONFORMITIES THE AUTOCAD EVERY TIME IS BETTER Quote
Jonathan Handojo Posted October 25, 2022 Posted October 25, 2022 (edited) @mhupp, Don't forget about object residing in blocks and nested blocks that are residing in the same layer. They will also need to be deleted before you can proceed to delete a layer. In which case I thought LAYDEL has all the calculations worked out already. You can still make improvements, but instead of looping through each object and deleting, simply using (command "_LAYDEL") I feel is more bulletproof: (defun c:foo ( / ent ly op ss) (and (setq ent (car (entsel "\nSelect object whose layer will be deleted <exit>: "))) (setq ly (assoc 8 (entget ent)) ss (ssget "_X" (list ly))) (progn (sssetfirst nil ss) (initget "Yes No") (setq ly (cdr ly) op (cond ((getkword (strcat "\n" (itoa (sslength ss)) " items to be deleted from layer \"" ly "\". Proceed? [Yes/No] <Yes>: "))) ("Yes")) ) (eq op "Yes") ) (progn (if (eq ly (getvar 'clayer)) (setvar 'clayer "0")) (command "_-laydel" "_Name" ly "" "Yes") ) ) (princ) ) Edited October 25, 2022 by Jonathan Handojo 1 Quote
mhupp Posted October 25, 2022 Posted October 25, 2022 (edited) Totally agree but have had an error with (command recently that kept crashing peoples computers when used (with a valid command) So i try and stay away from command prompt. Edited October 25, 2022 by mhupp Quote
BIGAL Posted October 25, 2022 Posted October 25, 2022 "but have had an error " no Laydel in Bricscad V20 maybe in latest version. 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.