woodman78 Posted July 31, 2009 Posted July 31, 2009 Hi, I want to use the rename command to put a prefix with all the layers in a drawing. However if i run the rename command at the command line it won't let me enter the * as the old_layer_name to select all layres. It will with the dialog box. Anyway around this cause I want to create a lisp with the rename command. Thanks Quote
Lee Mac Posted July 31, 2009 Posted July 31, 2009 You could make your own (defun c:test (/ wcm new pos) (vl-load-com) (setq wcm (getstring t "\nSpecify Old Name: ")) (setq new (getstring t "\nSpecify New Name: ")) (vlax-for lay (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object))) (setq Nme (vla-get-Name lay)) (if (and (wcmatch Nme wcm) (/= "0" Nme)) (if (setq pos (vl-string-position 42 new)) (vla-put-Name lay (strcat (substr new 1 pos) Nme (substr new (+ 2 pos))))))) (princ)) Quote
woodman78 Posted July 31, 2009 Author Posted July 31, 2009 I was looking at making it more specific. How do i take control from the user and hard code in that all layers get "CCC_OSMAP_" as a prefix? Quote
Lee Mac Posted July 31, 2009 Posted July 31, 2009 In which the user has no choice over the prefix, much shorter: (defun c:test (/ pref) (vl-load-com) (setq pref "CCC_OSMAP_") ;; <<-- Prefix (vlax-for lay (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object))) (if (/= "0" (vla-get-Name lay)) (vla-put-name Lay (strcat pref (vla-get-Name lay))))) (princ)) Quote
Lee Mac Posted July 31, 2009 Posted July 31, 2009 I think VL is the way to go on this one. The AutoLISP alternative is a bit less intuitive: (defun c:test (/ pref tdef tObj) (setq pref "CCC_OSMAP_") ;; <<-- Prefix (while (setq tdef (tblnext "LAYER" (not tdef))) (setq tObj (entget (tblobjname "LAYER" (cdr (assoc 2 tdef))))) (if (/= "0" (cdr (assoc 2 tObj))) (entmod (subst (cons 2 (strcat pref (cdr (assoc 2 tObj)))) (assoc 2 tObj) tObj)))) (princ)) Quote
David Bethel Posted July 31, 2009 Posted July 31, 2009 A few things to watch out for: XREF Layers Layers that already have the prefix Layers that already exist with the new name Layer 0 that Lee caught Layer name string length ( I guess that there still a limit some where ) That I can think of anyway. -Davud Quote
Lee Mac Posted July 31, 2009 Posted July 31, 2009 Thanks David, I hadn't thought of all that! So I suppose something like this: (defun c:test (/ pref Nme) (vl-load-com) (setq pref "CCC_OSMAP_") ;; <<-- Prefix (vlax-for lay (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object))) (setq Nme (strcase (vla-get-Name lay))) (cond ((= "0" Nme)) ((vl-string-position 124 Nme)) ((eq (strcase (strcat pref Nme)) Nme)) ((wcmatch Nme (strcat (strcase pref) "*"))) (t (vla-put-name Lay (strcat pref (vla-get-Name lay)))))) (princ)) Quote
woodman78 Posted July 31, 2009 Author Posted July 31, 2009 Thanks guys, It shouldn't be too much of an issue though because the drawings I'll be running this on are maps that are limited to about 30 standard layers but I suppose it could be handy for other types of drawings. 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.