If all drawings reside in one single directory, this should take care of it:
(defun c:Batcher (/ wutdir wutfiles scrfile n2 scrline)
(vl-load-com)
(setq wutdir (LM:browseforfolder "Select directory to process:" "C:\\" 512));;;<--Starting Directory
(setq wutfiles (vl-directory-files wutdir "*.dwg"))
(setq scr_name (strcat wutdir "\\scrfile.scr"))
(setq scrfile (open scr_name "w"))
(close scrfile)
(setq scrfile (open scr_name "a"))
(foreach n wutfiles
(setq n2 (strcat "\""wutdir "\\" n "\""))
(setq n2 (vl-string-translate "\\" "\\" n2))
(setq scrline (strcat "open" " " n2 " " "(load\"batcher\")" " " "(batcher_layer_chgclr)" " " "qsave" " " "close"))
(write-line scrline scrfile)
(princ)
)
(close scrfile)
(command "script" scr_name)
(princ "\n***Batch complete.***")
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;START batcher_layer_chgclr
(defun batcher_layer_chgclr ()
(command "_.layer" "_color" 5 "Equipment" "")
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;START LM:browseforfolder
;; THANKYOU Mr. M!
;; 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)
I'd backup the folder first, just for safety purposes. Make sure the LISP file resides in one of your support paths, and if you need assistance in loading and running a LISP file: https://www.lee-mac.com/runlisp.html
Edit (my apologies, I forgot a few key notes):
- Copy/Paste the code into a txt file and name it Batcher.lsp.
- Place Batcher.lsp in a support/trusted directory.
- Run the code from a drawing that will not be in the directory. Start a new drawing and run it from there.
AutoCad 2018 (full)
Win 11 Pro