Welcome to AUGI.
There's no way to make this automatic, if the prefix is constantly different.
To do this more quickly when you receive a new drawing, this old routine seems to do the trick:
Code:
(vl-load-com)
(defun c:LAYREN () (c:LayerRename))
(defun c:LayerRename
(/ *error* old new acDoc oLayers i oldName newName)
(defun *error* (msg)
(if acDoc
(vla-endundomark acDoc)
)
(cond ((not msg)) ; Normal exit
((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit)
((princ (strcat "\n** Error: " msg " ** "))) ; Fatal error, display it
)
(princ)
)
(if (and (setq old (getstring T "\nEnter string to replace: "))
(setq new (getstring T "\nEnter replacement string: "))
)
(progn
(vla-startundomark
(setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
)
(setq oLayers (vla-get-layers acDoc))
(setq i 0)
(vlax-for x oLayers
(if (vl-string-search old (setq oldName (vla-get-name x)))
(if
(tblsearch "layer"
(setq newName (vl-string-subst new old oldName)) ; single replacement only
)
(prompt
(strcat
"\nLayer \""
newName
"\" already exists. "
"Move all objects, then delete layer \""
oldName
"\" "
)
)
(progn
(vla-put-name x newName)
(setq i (1+ i))
)
)
)
)
(prompt
(strcat "\n"
(itoa i)
" layer"
(if (= 1 i)
" "
"s "
)
"renamed. "
)
)
)
)
(*error* nil)
)
Example from Command Line:
Code:
Command:
Command: LAYREN
Enter string to replace: X_Base_000_Prelim.Rnd 7$0$X_Base_000_Prelim.Rnd 4$0$
Enter replacement string:
1 layer renamed.
Command:
Note - the replacement string above, was an <Enter> (empty string).
Cheers