Edi LISP routine to remove layers with equal name begining

Edi LISP routine to remove layers with equal name begining

Anonymous
Not applicable
1,761 Views
8 Replies
Message 1 of 9

Edi LISP routine to remove layers with equal name begining

Anonymous
Not applicable

Hi all,

 

A long ago and with the help of a friend we program a tool to automatize several task. Now i was trying to modify the tool to adapt it to a different purpose with a similar idea. can anyone help me, please?

 

Objectives:

 

1.- leave on or switch on "layer AA" in case is off

2.- remove all layers which name start by "X CCC" (this is just the prefix of the layers but the rest of the name might be different)

3.- Create a PDF 

4.- Create an E transmit

5.- Go back to initial stage (right before launching the routine)

6.- SAVE

 

unfortunately i have no lisp knowledge to program this tool even with my friend notes around. 😞

 

thanks in advance. I leave the lisp attached. 

 

0 Likes
1,762 Views
8 Replies
Replies (8)
Message 2 of 9

Kent1Cooper
Consultant
Consultant

Try replacing this part:

 

                (member name
                        '(
                          "X CCC" ;; I would like to add here All Layers starting with this
                         )
                )

 

with this:

 

                (wcmatch name "X CCC*")

 

The asterisk is a wildcard standing for any additional character(s) [including none].  Read about wildcards in Help for the (wcmatch) function [the wc stands for wildcard].

Kent Cooper, AIA
0 Likes
Message 3 of 9

john.uhden
Mentor
Mentor

Let's not forget about case...

 

(wcmatch (strcase name) "X CCC*")

Maybe we should also be careful with XRef layers.

John F. Uhden

0 Likes
Message 4 of 9

Anonymous
Not applicable

Hi Kent and John,

 

unfortunately the routine is not removing the layers after updating the string with your recommendations.. 

 

 

any idea why?

 

best,

 

J.

0 Likes
Message 5 of 9

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

unfortunately the routine is not removing the layers ....  any idea why?

....


Are there any messages?

 

Run LAYDEL manually and check that the prompt answers and option letters in the routine are correct.  I suggest that because prompts and options change now and then -- for example, in older versions of AutoCAD the option for spelling out a Layer name rather than picking an object on it was Type-it, rather than Name.

Kent Cooper, AIA
0 Likes
Message 6 of 9

john.uhden
Mentor
Mentor

As I am still running only ACAD 2002, I am not familiar with the "LAYDEL" command.  I presume it deletes all entities on specified layer names and then deletes the layer.  Does it handle subentities like attributes?  If not (and there are attributes on that layer), then the layer can not be deleted.  It would have to be purged too, right?  No, (vla-delete) takes care of that.

John F. Uhden

0 Likes
Message 7 of 9

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

As I am still running only ACAD 2002, I am not familiar with the "LAYDEL" command.  ....


It may have become a core command since, but back then, if it was around [it certainly was by 2004], it was an Express Tool.  Yes, it removes everything from the designated Layer(s), and Purges, and even removes things from within Block definitions [Attributes or otherwise].

Kent Cooper, AIA
0 Likes
Message 8 of 9

john.uhden
Mentor
Mentor

In this statement:

 

(wcmatch (strcase name) "X CCC*")

are you trying to add additional prefixes?  If so, then separate them by commas, as in:

 

(wcmatch (strcase name) "X CCC*,X_DDD*")

I finally noticed that you did avoid XRef layers.  That's good.

John F. Uhden

0 Likes
Message 9 of 9

Ranjit_Singh
Advisor
Advisor

Here is another version to try that should take care of 1 and 2. Although I believe the fix provided by @Kent1Cooper and @john.uhden should work. Also note post 8 and adjust this code accordingly to add other prefixes, if needed.

 

(while (setq a (tblnext "layer" (null a))) 
(or (and (wcmatch (strcase (cdr (assoc 2 a))) "LAYER AA") (minusp (cdr (assoc 62 a))) (entmod (subst (cons 62 (abs (cdr (assoc 62 a)))) (assoc 62 a) (entget (tblobjname "layer" (cdr (assoc 2 a)))))))
(and (wcmatch (strcase (cdr (assoc 2 a))) "~*|*") (wcmatch (strcase (cdr (assoc 2 a))) "X CCC*") (command "._laydel" "_name" (cdr (assoc 2 a)) "" "_y"))))