Don't you run into an error from trying to rename Layer 0?
Some suggestions.... [I changed variable names involving "b" from the Block routine.]
(defun C:LN- (/ lay laylist i)
; don't need to "nil out" variables in localized list above
(while (setq lay (tblnext "layer" (not lay)))
(and
(zerop (logand 21 (cdr (assoc 70 lay)))); not frozen, locked, or in Xref [don't need 32 bit]
(setq lay (cdr (assoc 2 lay))); don't need (wcmatch) which was for anonymous Blocks
(/= lay "0"); can't rename that
(setq laylist (cons lay laylist)); don't need to check whether already in list [it won't be]
)
)
(setq i 0)
(foreach lname laylist; a little simpler for a list than (while)
(setq i (1+ i))
(command "_.-rename" "_la" lname (strcat "LAYER" (if (< b 10) "0" "") (itoa i)))
)
(princ)
)
I confess to wondering whether you really want to leave Layers un-renamed if they happen to be frozen or locked. You'll have a mishmash of Layer names that I assume you're trying to eliminate with such a routine.
Also, would you ever try to run something like this in a drawing in which you have already done so? That will encounter problems with already-existing Layer names. That can be accounted for, with some more code, if needed.
thanks! yes, i did run into a few errors, but it did the job. Yes, if you run it twice, it gets grumbly but a simple solution is to just change it to rename as "layers" instead of "layer" and then back, and you're good to go.
I ended up wrapping my original hack job into a longer routine as a way of preparing and example dwg that is stripped of any identifying info. It is probably like using a 2x4 to drive finish nails, and also runs into errors, but got the job done.
(defun C:MAKEALLGENERIC ( / blist bl b n)
;; ALL BLOCKS
(setq blist '() bl nil b 0 n "BLOCK")
(while (setq bl (tblnext "block" (not bl)))
(and (zerop (logand 53 (cdr (assoc 70 bl))))
(not (wcmatch "`**" (setq bl (cdr (assoc 2 bl)))))
(or (member bl blist) (setq blist (cons bl blist)))
)
)
(while (and (car blist) (setq b (1+ b)))
(command "_.-rename" "_b" (car blist)
(strcat n (if (< b 10) "0" "") (itoa b)))
(setq blist (cdr blist))
)
;; ALL DIMSTYLES
(setq blist '() bl nil b 0 n "DIMS")
(while (setq bl (tblnext "dimstyle" (not bl)))
(and (zerop (logand 53 (cdr (assoc 70 bl))))
(not (wcmatch "`**" (setq bl (cdr (assoc 2 bl)))))
(or (member bl blist) (setq blist (cons bl blist)))
)
)
(while (and (car blist) (setq b (1+ b)))
(command "_.-rename" "_d" (car blist)
(strcat n (if (< b 10) "0" "") (itoa b)))
(setq blist (cdr blist))
)
;; ALL TEXTSTYLES
(setq blist '() bl nil b 0 n "TEXT")
(while (setq bl (tblnext "style" (not bl)))
(and (zerop (logand 53 (cdr (assoc 70 bl))))
(not (wcmatch "`**" (setq bl (cdr (assoc 2 bl)))))
(or (member bl blist) (setq blist (cons bl blist)))
)
)
(while (and (car blist) (setq b (1+ b)))
(command "_.-rename" "_s" (car blist)
(strcat n (if (< b 10) "0" "") (itoa b)))
(setq blist (cdr blist))
)
;; ALL LAYOUTS
(vl-load-com)
(vlax-for layt (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
(if (> (vla-get-TabOrder layt) 0)
(setq layt_lst (cons (cons (vla-get-TabOrder layt) (vla-get-Name layt)) layt_lst))
)
)
(setq layt_lst (vl-sort layt_lst '(lambda (x y) (< (car x) (car y)))))
(setq name (vl-filename-base (getvar "dwgname"))
i 0
)
(if (= 1 (length layt_lst))
(command "_-layout" "_rename" "" name)
(foreach layt layt_lst
(command "_-layout" "_rename" (cdr layt) (strcat name " (" (itoa (setq i (1+ i))) ")"))
)
)
;; ALL LAYERS
(setq blist '() bl nil b 0 n "LAYER")
(while (setq bl (tblnext "layer" (not bl)))
(and (zerop (logand 53 (cdr (assoc 70 bl))))
(not (wcmatch "`**" (setq bl (cdr (assoc 2 bl)))))
(or (member bl blist) (setq blist (cons bl blist)))
)
)
(while (and (car blist) (setq b (1+ b)))
(command "_.-rename" "_la" (car blist)
(strcat n (if (< b 10) "0" "") (itoa b)))
(setq blist (cdr blist))
)
;; ALL LINETYPES
;; ALL LINETYPES
(setq blist '() bl nil b 0 n "LINE")
(while (setq bl (tblnext "ltype" (not bl)))
(and (zerop (logand 53 (cdr (assoc 70 bl))))
(not (wcmatch "`**" (setq bl (cdr (assoc 2 bl)))))
(or (member bl blist) (setq blist (cons bl blist)))
)
)
(while (and (car blist) (setq b (1+ b)))
(command "_.-rename" "_lt" (car blist)
(strcat n (if (< b 10) "0" "") (itoa b)))
(setq blist (cdr blist))
)
;; ALL TABLESTYLES
(setq blist '() bl nil b 0 n "TABLE")
(while (setq bl (tblnext "Tablestyle" (not bl)))
(and (zerop (logand 53 (cdr (assoc 70 bl))))
(not (wcmatch "`**" (setq bl (cdr (assoc 2 bl)))))
(or (member bl blist) (setq blist (cons bl blist)))
)
)
(while (and (car blist) (setq b (1+ b)))
(command "_.-rename" "_t" (car blist)
(strcat n (if (< b 10) "0" "") (itoa b)))
(setq blist (cdr blist))
)
(princ)
)
This Lisp is great. Thank you.
Is there an option so that the lisp asks the user to type a desired block name rather than "NEWJOB"
Thank you in advance.
@dgoutz wrote:
.....
Is there an option so that the lisp asks the user to type a desired block name rather than "NEWJOB"
....
In case they're not still watching after 12-1/2 years [it's an archived account, and they haven't posted anything since around that time]....
Change this line:
(setq blist '() bl nil b 0 n "NEWJOB")
to this:
(setq blist '() bl nil b 0 n (getstring "\nBlock base name: "))
Can you get this to work with xrefs? I would like to rename the reference names with a find and replace option.
You seem to be modifying incrementally.
What if you have...
"blabla-REV.A-blabla-OPTION.1-blabla"
But there already is a...
"blabla-REV.B-blabla-OPTION.2-blabla"
And why should the Option identifier change just because there's a revision?
Actually, I would think the Options take precedence over the revision level, so to me it would make more sense being...
"blabla-OPTION.A-blabla-REV.2-blabla"
and
"blabla-OPTION.B-blabla-REV.0-blabla"
John F. Uhden