Jump to content

Recommended Posts

Posted

Hi again,

 

I have another question to ask. unsure if anyone has done this before. I have layers that i'd like to change or rename. It'd be too much work if i do it one by one. I was thinking if there is a program or coding to do that for AutoCAD 2005.

 

Thank you in advance

Posted

Have you tried the "rename" command? It allows use of wildcards, which may allow you to reduce the number of steps.

Posted

You can use codes to do it but still got to type: name, chose color, linetype... It is easy in Layer Property Manager. Try this.

Or import your own layer set, but still got to create...

  • 2 years later...
Posted

The RENAME command only seems to work for prefixes not suffixes. If it comes at the beginning of a layer name, great. If not, you are out of luck, it won't rename.

Posted
The RENAME command only seems to work for prefixes not suffixes. If it comes at the beginning of a layer name, great. If not, you are out of luck, it won't rename.

 

You are responding to an old post, but you can rename prefix or suffix on layer names.

 

EX. M-DETL-0001, M-DETL-0002, ...

 

RENAME

M-DETL-????

TO

M-DETL-????-A

Posted

I realized that it was old, but as I was looking for a solution to batch renaming, these types of threads keep coming up. I have been trying to rename multiple layers such as: *-DEMO to *-DEMO-ALT and it does not work. I have never been able to get the rename command to rename multiple layers by adding a suffix. If someone knows the answer, please let me know.

Posted

not a whole lot of testing so be careful

(defun C:test ( / aDoc lyrs lyr-name suf)
(vl-load-com)
 (setq fil (strcase (getstring "Enter filter: ")));don't forget the wildcard(s)
(setq suf (getstring "Enter suffix: "))
(setq aDoc (vla-get-activedocument (vlax-get-acad-object)))
(setq lyrs (vla-get-layers aDoc))
(vlax-map-collection lyrs 'lyr-add)
(princ)
);defun

(defun lyr-add (lyr)
 (setq lyr-name (strcase (vlax-get-property lyr 'Name)))
 (if
   (wcmatch lyr-name fil)
     (vla-put-Name lyr (strcat  lyr-name suf))
 ) ;if
 (princ)
);defun

Posted

A type of merge could also work. Edit the laylist to meet your needs:

 

(defun c:mergel (/ vlist laylist ss tdef fe fd el)

 (setq vlist '(("ELEVATION" . 0) ("THICKNESS"  . 0)
               ("CELTSCALE" . 1) ("CECOLOR"   . "BYLAYER")
               ("CELTYPE"   . "BYLAYER")))
 (foreach v vlist
     (and (getvar (car v))
          (setvar (car v) (cdr v))))


 (setq laylist '(("OLD-LAYER" . "NEW-LAYER")
                 ("3D-SZG"    . "SNEEZE")))

 (command "_.LAYER")
 (foreach l laylist
      (if (not (tblsearch "LAYER" (cdr l)))
          (command "_New" (cdr l))))
 (command "")

 (foreach l laylist
      (and (setq ss (ssget "X" (list (cons 8 (car l)))))
           (command "_.CHPROP" ss "" "_LA" (cdr l) "")))

 (while (setq tdef (tblnext "BLOCK" (not tdef)))
        (setq fe (cdr (assoc -2 tdef)))
        (entmake tdef)
        (while fe
             (setq fd (entget fe)
                   el (cdr (assoc 8 fd)))
             (if (assoc el laylist)
                 (setq fd (subst (cons 8 (cdr (assoc el laylist)))
                                 (assoc 8 fd) fd)))
             (entmake fd)
             (setq fe (entnext fe)))
        (entmake (list (cons 0 "ENDBLK")(cons 8 "0"))))

 (prin1))

 

-David

Posted

Thanks people. I will try them out and let you know how they work.

Posted

lpseifert your lisp routine worked perfectly. It did exactly what I was trying to get rename to do, but couldn't. I wish my lisp skills were to that level, alas they are not. You should show the folks at Autodesk a thing or two about what their routine could be doing. You rock! Thanks a million.

Posted

You know that adage about blind squirrels and nuts...

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