I was searching for a lisp to rename all blocks in a dwg and came upon this code, written by Lee Mac in 2009. I'll insert the full code and a hyperlink to where I got it at the bottom.
It works as I would like, but missing a small feature that I'm assuming wouldn't be too difficult to fix.
In the place where is changes the name to "Block-", I would like it to ask me what I would like the prefix to be, then use that.
For example, I would like all blocks in a drawing to begin with 48925-, but in another drawing I would like it to start with 49134-... etc.
Any help would be greatly appreciated!
(defun c:BLR (/ Allblocks num count ename edata bname nprefix rname)
;; Localise your variables buddy, good programming practice. :)
(if (setq AllBlocks (ssget "_X" '((0 . "INSERT")))) ; begin if
(progn
(setq num (sslength AllBlocks) Count 0)
(princ (strcat "\n Total Blocks found : " (itoa num)))
;; This is where your program was failing, remember,
;; "princ" requires a STRING, you supplied it with an
;; INTEGER.
(repeat num
;;this cycles number of items
(setq Ename (ssname AllBlocks Count))
;;get entity name
(setq Edata (entget Ename))
(setq Count (+ 1 Count))
(princ "\n\n Count : ")
(print Count)
(princ " of ")
(print Numblocks)
(princ "\n\n Edata :")
(print Edata)
(princ "\n\n ------------- cdr assoc 2 data ------------\n")
(setq bName (cdr (assoc 2 Edata)))
(print bName)
(princ "\n=============================================\n")
(setq nPrefix (strcase "Block-"))
(princ "\n nPrefix : ")
(princ nPrefix)
(setq rName (strcat nPrefix (itoa Count)))
(princ "\n rName :")
(princ rName)
(princ "\n Block found!! Please Wait......") ;amusement
(princ "\n Count = [ ")
(print Count)
(princ " ] sorting next.....\n :")
;(princ rName)
(princ "\n Renaming block found....")
(command "-rename" "block" bName rName)
)
) ;then
(prompt "\n No Block objects found!") ;else
)
(princ)
;===========================================================================Turn on command line responses
;(setvar "CMDECHO" 1)
;===========================================================================
)
http://www.theswamp.org/index.php?topic=29839.15