Autocad Lisp, remove all text after layer name

Autocad Lisp, remove all text after layer name

kieran.leadbetter
Advocate Advocate
2,039 Views
20 Replies
Message 1 of 21

Autocad Lisp, remove all text after layer name

kieran.leadbetter
Advocate
Advocate

Hello, I posted a similar request earlier, however this might be easier

I was hoping someone would have a lisp or know how to create one to remove all characters after a specific layer name, i.e. if my layer name was 

A200_Demolitions

But there was a variant of this within the drawing, A200_demolitions123, could I have any characters before or after the layer *A200_Demolitions* removed, and if the layer already exists once these characters are removed, can it be added to said existing layer. Got thousands of drawings I need to tidy the layers up in, and doing this manually will take me months

Kind Regards

0 Likes
2,040 Views
20 Replies
Replies (20)
Message 21 of 21

Sea-Haven
Mentor
Mentor

As I suggested earlier for 135 layers use a text file. You can dump out layers to a file step1, then use 2nd file to make your baselayers step2. 

 

(setq fo (open "d:\\yourdirectory\\layers.txt" "w"))
(vlax-for lay (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
(write-line (vlax-get lay 'name) fo)
(princ (strcat "\n" (vlax-get lay 'name)))
)
(close fo)

Read layer text file 

 

(setq BaseLayerNames '())
(setq fo (open "d:\\yourdirectory\\layers.txt" "R"))
(while (setq newline (read-line fo))
(setq BaseLayerNames (cons newline BaseLayerNames))
)
(close fo)

If you have problems with the size of the list can instead process 1 layer name at a time.

 

You can edit the text file should only need to run once, I open in Excel and sort the column then its alphabetical, copy column back to TXT file.

0 Likes