Message 1 of 8

Not applicable
03-25-2021
07:10 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I Have a routine ive hodgepodged together that deletes date and initials from layers. where im struggling is if that layer already exists in the drawing (either via a previous layer being renamed or not) the program crashes as I cant create a new layer with an existing layers name.
What would be preferable would be if it checked for an existing layer and merged together outputs that would normally result in a duplicate layer name
(defun layerrenamer (/ doc lyrs nme flg len str);remove "GPSYYYMMDD LL " and variants from all layer names in a drawing file. will require Autodesk Visual Lisp installed on the machine
(vl-load-com)
(setq doc (vla-get-activedocument (vlax-get-acad-object))
lyrs (vla-get-layers doc)
);end_setq
(vlax-for lyr lyrs
(setq nme (vlax-get lyr 'name))
(cond ( (wcmatch (strcase nme) "TXT RL @@@######## @@ *") (setq flg t len 22))
( (wcmatch (strcase nme) "TXT RL @@@########@@ *") (setq flg t len 21))
( (wcmatch (strcase nme) "TXT RL @@######## @@ *") (setq flg t len 21))
( (wcmatch (strcase nme) "TXT RL @@########@@ *") (setq flg t len 20))
( (wcmatch (strcase nme) "TXT RL @@###### @@ *") (setq flg t len 19))
( (wcmatch (strcase nme) "TXT RL @@######@@ *") (setq flg t len 18))
);end_cond
(cond (flg (setq flg nil str (substr nme 1 len))
(vlax-put lyr 'name (vl-string-subst "txt rl TOPO " str nme))
)
);end_cond
(cond ( (wcmatch (strcase nme) "TXT CODE @@@######## @@ *") (setq flg t len 24))
( (wcmatch (strcase nme) "TXT CODE @@@########@@ *") (setq flg t len 23))
( (wcmatch (strcase nme) "TXT CODE @@######## @@ *") (setq flg t len 23))
( (wcmatch (strcase nme) "TXT CODE @@########@@ *") (setq flg t len 22))
( (wcmatch (strcase nme) "TXT CODE @@###### @@ *") (setq flg t len 21))
( (wcmatch (strcase nme) "TXT CODE @@######@@ *") (setq flg t len 20))
);end_cond
(cond (flg (setq flg nil str (substr nme 1 len))
(vlax-put lyr 'name (vl-string-subst "txt code TOPO " str nme))
)
);end_cond
(cond ( (wcmatch (strcase nme) "@@@######## @@ *") (setq flg t len 15))
( (wcmatch (strcase nme) "@@@########@@ *") (setq flg t len 14))
( (wcmatch (strcase nme) "@@######## @@ *") (setq flg t len 14))
( (wcmatch (strcase nme) "@@########@@ *") (setq flg t len 13))
( (wcmatch (strcase nme) "@@###### @@ *") (setq flg t len 12))
( (wcmatch (strcase nme) "@@######@@ *") (setq flg t len 11))
);end_cond
(cond (flg (setq flg nil str (substr nme 1 len))
(vlax-put lyr 'name (vl-string-subst "TOPO " str nme))
)
);end_cond
);end_for
(princ)
);end_defun
thanks in advance for any assistance
Solved! Go to Solution.