No error handling.
(defun c:batchRename (/ fileSCR dir run)
(setq dir (strcat (LM:browseforfolder
"Select a folder"
(strcat (getenv "UserProfile") "\\Desktop")
0
)
"\\"
)
fileSCR (open (strcat dir "batchFile.scr") "w")
)
(foreach dwg (vl-directory-files dir "*.dwg" 1)
(write-line "_.open" fileSCR)
(write-line (strcat "\"" dir dwg "\"") fileSCR)
(write-line ;load your lisp here
"(load \"C:/Users/Augusto/Desktop/rename.lsp\")"
fileSCR
)
(write-line "_.qsave" fileSCR)
(write-line "_.close" fileSCR)
)
(close fileSCR)
(if (findfile (setq fileSCR (strcat dir "batchFile.scr")))
(command "_script" fileSCR)
)
)
;; Browse for Folder - Lee Mac
;; Displays a dialog prompting the user to select a folder.
;; msg - [str] message to display at top of dialog
;; dir - [str] [optional] root directory (or nil)
;; bit - [int] bit-coded flag specifying dialog display settings
;; Returns: [str] Selected folder filepath, else nil.
(defun LM:browseforfolder ( msg dir bit / err fld pth shl slf )
(setq err
(vl-catch-all-apply
(function
(lambda ( / app hwd )
(if (setq app (vlax-get-acad-object)
shl (vla-getinterfaceobject app "shell.application")
hwd (vl-catch-all-apply 'vla-get-hwnd (list app))
fld (vlax-invoke-method shl 'browseforfolder (if (vl-catch-all-error-p hwd) 0 hwd) msg bit dir)
)
(setq slf (vlax-get-property fld 'self)
pth (vlax-get-property slf 'path)
pth (vl-string-right-trim "\\" (vl-string-translate "/" "\\" pth))
)
)
)
)
)
)
(if slf (vlax-release-object slf))
(if fld (vlax-release-object fld))
(if shl (vlax-release-object shl))
(if (vl-catch-all-error-p err)
(prompt (vl-catch-all-error-message err))
pth
)
)
(princ)
Lisp file to rename blocks attached.
(setq btable '(
("OLDBLOCK1" . "NEWBLOCK1")
("OLDBLOCK2" . "NEWBLOCK2")
("OLDBLOCK3" . "NEWBLOCK3")
)
)
(foreach b btable
(if
(and
(not (tblsearch "BLOCK" (cdr b)))
(tblsearch "BLOCK" (car b))
)
(command "_.RENAME" "_Block" (car b) (cdr b))
)
)
Best regards, Luís Augusto.