Jump to content

Rename all layers


woodman78

Recommended Posts

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

Link to comment
Share on other sites

You could make your own :P

 

(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))

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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))

Link to comment
Share on other sites

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))

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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))

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...