Jump to content

select item and delete entire layer ...help


leonucadomi

Recommended Posts

 

hello all:

 

 

Is there a routine that allows me to select an element and delete all the elements including the layer ?

 

 

thanks

 

 

 

Link to comment
Share on other sites

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

 

  • Like 2
Link to comment
Share on other sites

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 by mhupp
Code Updated
  • Like 3
Link to comment
Share on other sites

What about Laydel.

 

(command "-laydel" "Name" (cdr (assoc 8 (car (entesel "\nPick object for layer ")))) "" "Y")

 

Edited by BIGAL
  • Like 1
  • Agree 1
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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

 

image.thumb.png.48d3aecabcd8d8c598ed305db6f775a3.png

 

 

it's possible?

 

 

 

 

 

 

Link to comment
Share on other sites

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 by mhupp
Link to comment
Share on other sites

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

  • Funny 2
Link to comment
Share on other sites

@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 by Jonathan Handojo
  • Like 1
Link to comment
Share on other sites

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