lisp to delete layers using laydel with wildcards in the name?

lisp to delete layers using laydel with wildcards in the name?

zasanil
Advocate Advocate
6,786 Views
15 Replies
Message 1 of 16

lisp to delete layers using laydel with wildcards in the name?

zasanil
Advocate
Advocate
I have been searching but haven't found something that does this. I'm looking for a lisp to delete a set of layers that all start with the same text using wildcards. The layers have stuff on them, so it would need to make use of the laydel command. If an one has a lisp like this, please let me know.
Thanks!
Dan Nicholson C.I.D.
PCB Design Engineer
0 Likes
Accepted solutions (3)
6,787 Views
15 Replies
Replies (15)
Message 2 of 16

pbejse
Mentor
Mentor

@zasanil wrote:
I have been searching but haven't found something that does this. I'm looking for a lisp to delete a set of layers that all start with the same text using wildcards. The layers have stuff on them, so it would need to make use of the laydel command. If an one has a lisp like this, please let me know.
Thanks!

Hope you area aware of laydels' capability to delete objects of particular layer inside a block. Is that what you really want?  What is the reason for deleting the target layers? are those layers a product of XREF bind? would you consider layer merge instead?

0 Likes
Message 3 of 16

zasanil
Advocate
Advocate
I am aware that the objects on the layers which are processed by laydel is removed. That is precisely what I need.
I have drawings that are generated from a different program, and it brings it in with all these extra layers which I am manually deleting now. The data on these layers is not important. I just wish to automate this process, and one way to efficiently do that is by having -laydel take wildcards in the name.
Dan Nicholson C.I.D.
PCB Design Engineer
0 Likes
Message 4 of 16

pbejse
Mentor
Mentor

@zasanil wrote:
I am aware that the objects on the layers which are processed by laydel is removed. That is precisely what I need.
I have drawings that are generated from a different program, and it brings it in with all these extra layers which I am manually deleting now. The data on these layers is not important. I just wish to automate this process, and one way to efficiently do that is by having -laydel take wildcards in the name.

Ok, hang in there, i'll write a quick one for this

 

0 Likes
Message 5 of 16

zasanil
Advocate
Advocate

Thanks pbejse! That would be great!

Dan Nicholson C.I.D.
PCB Design Engineer
0 Likes
Message 6 of 16

pbejse
Mentor
Mentor
Accepted solution
(defun c:DLAO (/ Layn a ln)
  (if (and
	(setq Layn (strcase (getstring "\nEnter Layer to Delete: ")))
	(not (member layn '("0" "" "DEFPOINTS")))
      )
    (while (setq a (tblnext "LAYER" (null a)))
      (if (wcmatch (setq ln (strcase (cdr (assoc 2 a)))) layn)
	(command "-Laydel" "Name" ln "" "Y")
      )
    )
  )
  (princ)
)

 

command: DLAO

Enter Layer to Delete: *dim*

 

If there are no objects on the specified layer, a simple purge commnad will remove it.

HTH

Message 7 of 16

hmsilva
Mentor
Mentor
Accepted solution

Hi zasanil,

my attempt

 

(defun c:dellayers ( / hms:LayerList* cla ech lay* laylst)

  (defun hms:LayerList* (path / LayName TblName TblNameList)
    (while (setq TblName (tblnext "Layer" (null TblName)))
      (if (wcmatch (setq LayName (strcase (cdr (assoc 2 TblName)))) (strcase path))
        (setq TblNameList (cons LayName TblNameList))
      )
    )
    (acad_strlsort TblNameList)
  );; hmsLayerList*
  
(if (and (setq lay* (getstring T "\n Enter Layer Name to delete, wild-cards can be used: "))
         (not (wcmatch (strcase lay*) "0*,DEFPOINTS*"))
         (setq LayList (hms:LayerList* lay*))
         )
  (progn
    (setq ech (getvar 'CMDECHO))
    (setvar 'CMDECHO 0)
    (command "_.undo" "G")
    (command "_.-layer" "_U" lay* "_T" lay* "")
    (setq cla (strcase (getvar 'CLAYER)))
    (if (member cla LayList)
      (command "_.-layer" "_U" "0" "_T" "0" "_S" "0" "")
      )
    (foreach l LayList
      (command "_.-laydel" "_N" l "" "_Y")
      )
    (command "_.undo" "E")
    (setvar 'CMDECHO ech)
    )
  (prompt "\n Layer Name not valid, or no matching layers... ")
  )
  (princ)
)

 

Hope this helps,
Henrique

EESignature

Message 8 of 16

pbejse
Mentor
Mentor

@hmsilva wrote:

Hi zasanil,

my attempt

   

..
(command "_.-layer" "_U" lay* "_T" lay* "")
..

 

Hope this helps,
Henrique


 

I keep forgetting about locked layers Smiley Very Happy

 

I was thinking of allowing more than one layer name to search

 

(While
    	  (and
    	   (setq Layn (getstring "\nEnter Layer to Delete: <Enter for none>"))
           (/= Layn "")
      	   (print (setq laylst (cons (strcase Layn) laylst)))
	   )
    )

 in conjunction with this inside while tblnext to collect all targeted layer names

 

(vl-some '(lambda (l)
			 (wcmatch (strcase (setq ln (strcase  (cdr (assoc 2 a))))) l)) laylst)

 

Also though of writing a code with not using the native laydel command but decided not to, we'll just keep it simple for now.

 

 

Message 9 of 16

zasanil
Advocate
Advocate

Thank you guys!. Both of these work great for what I was doing.

/cheers

Dan Nicholson C.I.D.
PCB Design Engineer
0 Likes
Message 10 of 16

pbejse
Mentor
Mentor

@zasanil wrote:

Thank you guys!. Both of these work great for what I was doing.

/cheers


Good for you zasanil Glad it works.

 

cheers

 

0 Likes
Message 11 of 16

zasanil
Advocate
Advocate

pbejse,

If I wanted to change your code to include locked layers and the multiple names like you mentioned, how would I do that? I don't usually use locked layers, but you never know what might show up.

Dan Nicholson C.I.D.
PCB Design Engineer
0 Likes
Message 12 of 16

hmsilva
Mentor
Mentor

@zasanil wrote:

Thank you guys!. Both of these work great for what I was doing.

/cheers


You're welcome, zasanil.
Glad I could help

 

 @pbejse 


@pbejse wrote:

Also though of writing a code with not using the native laydel command but decided not to, we'll just keep it simple for now.


1+ Smiley Happy

 

Cheers
Henrique

EESignature

0 Likes
Message 13 of 16

pbejse
Mentor
Mentor
Accepted solution

@zasanil wrote:

pbejse,

If I wanted to change your code to include locked layers and the multiple names like you mentioned, how would I do that? I don't usually use locked layers, but you never know what might show up.


Henriques code is almost exactly what you want except the multiple names.

 

Question for you, why not use the native laydel command? by typing  "N' at this prompt

Select object on layer to delete or [Name]:

a list box will appear for multiple layer name selection, almost similar to wildcard matching.

 

Anyhoo, if you are skilled in lisp coding you can incorporate the snippet i posted at post#8 alongwith Hmsilva's code

 

FWIW. I would write it this way without the use laydel, allow multiple names and consider locked layers

 

(defun c:DLAO ( / aDoc ll laylst l2del Layn docLayers)
    (setq LL nil
	  l2del nil
	  laylst nil
	   aDoc (vla-get-activedocument (vlax-get-acad-object)))
    (vlax-for ln (setq docLayers (vla-get-layers aDoc))
        (if (eq :vlax-true (vla-get-lock ln))
            (progn
                (vla-put-lock ln :vlax-false)
                (setq ll (cons ln ll))
            )
        )
    )
  (While
    	  (and
    	   (setq Layn (getstring "\nEnter Layer to Delete: <Enter for none>"))
           (/= Layn "")
      	   (print (setq laylst (cons (strcase Layn) laylst)))
	   )
    )
    (vlax-for itm (vla-get-blocks adoc)
        (if (eq  (vla-get-isxref itm) :vlax-false)
            (vlax-for obj itm
	      (if (vl-some '(lambda (ln)
			 (wcmatch (strcase (vla-get-layer obj)) ln)) laylst)
			  (progn
			    (if (not (assoc (setq _ln (vla-get-layer obj)) l2del))
			      	(setq l2del (cons (list _ln (vla-item docLayers _ln)) l2del)))
			    (vla-delete obj)
			    )
            )
        )
    )
      )
    (foreach a ll (vla-put-lock a :vlax-true))
  
    (foreach l2d (mapcar 'cadr l2del)
      (vla-delete l2d))
      (vla-regen adoc acallviewports)
    
    (princ)
)
(vl-load-com) (princ)

 

Message 14 of 16

zasanil
Advocate
Advocate

That lisp works really well too! Thanks 😃

I would use the dialog box, but I'm hoping to automate a process of converting and cleaning up these drawings. Eventually I would like to issue one command (or a macro button) and have the whole drawing processed. This lisp is great for deleting all the extra layers at once as a first step.

Thanks again 

Dan Nicholson C.I.D.
PCB Design Engineer
0 Likes
Message 15 of 16

pbejse
Mentor
Mentor

@zasanil wrote:

That lisp works really well too! Thanks 😃

I would use the dialog box, but I'm hoping to automate a process of converting and cleaning up these drawings. Eventually I would like to issue one command (or a macro button) and have the whole drawing processed. This lisp is great for deleting all the extra layers at once as a first step.

Thanks again 


You are welcome zasanil , holler if you need help with the mod on previous DLAO lisp routine [one with native laydel]

 

Cheers

Message 16 of 16

danglar
Advocate
Advocate

is it possible to ISOLATE layers using wildcards in the name in a same way we can delete layers?

0 Likes