feargt Posted June 26, 2009 Posted June 26, 2009 Does anybody know why this is not working using the rename command There are 100 layers beginning with PS Rename layers Old name = PS* New Name =PS*_E When I give PS* as the old name all the layers are highlighted but it won't change the name though Thanks Quote
feargt Posted June 26, 2009 Author Posted June 26, 2009 No, no xrefs in the drawing. I'm making a blank drawing to be used as a template for a project Quote
Zorg Posted June 26, 2009 Posted June 26, 2009 Would it affect them if they are locked? I've not had trouble with Rename command but i tend to use a lisp more oftenly now. Try this, makes renaming a doddle (defun c:layren (/ samObj filLst laySet layName Ans newName vlaLay) (vl-load-com) (if(setq samObj (entsel "\nSelect object at wanted layer > ")) (progn (setq filLst (assoc 8(entget(car samObj)))) (sssetfirst nil (setq laySet(ssget "_X" (list filLst)))) (initget "Yes No") (setq Ans(getkword (strcat "\n<<< Layer name: '" (setq layName(cdr filLst)) "' >>>\nDo you want to rename it [Yes/No]? : "))) (if(null Ans)(setq Ans "Yes")) (if(= Ans "Yes") (progn (if (/= "" (setq newName (getstring T "\nType new layer name: "))) (progn (setq vlaLay (vla-Item (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) layName)) (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-put-Name (list vlaLay newName))) (princ "\n>>> Cannot rename layer! <<< ") (princ (strcat "\n<<< Layer '" layName "' renamed to '" newName "' >>>")) ); end if ); end progn ); end if ); end progn ); end if (sssetfirst nil nil) ); end progn ); end if (princ) ); end of c:layren Z Quote
feargt Posted June 27, 2009 Author Posted June 27, 2009 Hi Zorg, Thanks for the lisp but, this appears only to work when there are objects already in the drawing. The only thing I have in my drawing is a set of layers. I need to rename the layers and don't want to do it manually if at all possible thanks Quote
eldon Posted June 27, 2009 Posted June 27, 2009 I think your difficulty is in the format of the New Name. It does not pick up anything after the *, so AutoCAD thinks that you are renaming everything with the original name. I think a solution can be found using ? and renaming layers with a similar number of letters in one go. Quote
feargt Posted June 27, 2009 Author Posted June 27, 2009 Hi, I found a solution here in another thread. The following code was posted by "kpbic" (defun c:layrename (/ adoc str) (vl-load-com) (initget "Prefix Suffix _ P S") (setq adoc (vla-get-activedocument (vlax-get-acad-object)) answer (getkword "\nUse string like [Prefix/Suffix] : ") str (getstring "\nString to add : ") ) ;_ end of setq (vla-startundomark adoc) (if (not answer) (setq answer "P") ) ;_ end of if (vlax-for item (vla-get-layers adoc) (vl-catch-all-apply 'vla-put-name (list item (cond ((= answer "P") (strcat str (vla-get-name item)) ) (t (strcat (vla-get-name item) str) ) ) ;_ end of cond ) ;_ end of list ) ;_ end of VL-CATCH-ALL-APPLY ) ;_ end of vlax-for (vla-endundomark adoc) (princ) ) ;_ end of defun It did exactly what I required Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.