Hi Andre,
Give this a try:
Code:
(defun c:test (/ dis ans) ;dis is local - no, i'm not dis'n you :)
(or *dis* (setq *dis* "Mechanical")) ;leave *dis* global
(initget "Mechanical,M Plumbing,P FireProtection,F Electrical,E");initget the keywords
(setq ans (getkword
(strcat
"\nWhat discipline are you working in? <M>ech.,<P>lumbing,<F>irePro or <E>lect:"
"<" *dis* ">"
);strcat
);getkword
);setq
(cond ((= ans "Mechanical")(setq dis "Mech")(setq *dis* "Mechanical"))
((= ans "Plumbing")(setq dis "Plum")(setq *dis* "Plumbing"))
((= ans "FireProtection")(setq dis "Fire")(setq *dis* "FireProtection"))
((= ans "Electrical")(setq dis "Elec")(setq *dis* "Electrical"))
(T (cond ((= *dis* "Mechanical")(setq dis "Mech"))
((= *dis* "Plumbing")(setq dis "Plum"))
((= *dis* "FireProtection")(setq dis "Fire"))
((= *dis* "Electrical")(setq dis "Elec"))
)
)
)
(layers-exst dis)
(princ (strcat *dis* "layers renamed"))
(princ)
);defun
(defun layers-exst (dis_match / layers_col nam)
(vl-load-com)
(or *acaddoc* (setq *acaddoc* (vla-get-activedocument (vlax-get-acad-object))))
;get the acad document
(setq layers_col (vla-get-layers *acaddoc*))
;get the layers collection from the acad document
(vlax-for item layers_col;walk through the layers collection
(if
(and
(wcmatch (strcase (vlax-get-property item 'Name))(strcase (strcat dis_match "*")))
;if the characters match
(not (wcmatch (strcase (vlax-get-property item 'Name)) "*-EXST"))
;and hasn't already been changed (cheers Chris)
)
(vlax-put-property item 'Name (strcat (vlax-get-property item 'Name) "-EXST"))
;rename the layer
)
)
(princ)
)
With slight modifications, c:layers-exst becomes layers-exst, a function that will process the layers based on the argument dis_match. dis_match needs to be a string that reflects the first letters that are common with the discipline depending on your layer naming scheme. In this example, I used Mech, Plum, Fire and Elec, thinking that your layer scheme may look something like:
Mech-Ductwork
Mech-Annotation
Plum-Fittings
Elec-Conduit
Etc.
Etc.
Change the values in the cond section (in red) to reflect your actual situation. Don't worry about the stuff in the prompt, and you can even spell out the disciplines, like changing FirePro to Fire Protection - I just ran out of room in the post editor.
Let us know if you need more help.