Lisp to Batch Process Files
Comments
-
If you’re running v24 or later, you can try https://github.com/CEXT-Dan/PyRx
Here’s a sample of batch exploding blocks https://gist.github.com/CEXT-Dan/87675323bf83b053daa155217710bc45
It’s a couple of other patterns.
# see https://github.com/CEXT-Dan/PyRx import traceback from pyrx import Db, Ed, Ge, Ap, Rx, Gs, Ax from collections import defaultdict def using_scope(f): f() # use brx @Ap.Command() def doit(): try: names = defaultdict(int) for file in Ap.Application.listFilesInPath("E:\\temp", ".dwg"): sdb = Db.Database(False, True) sdb.readDwgFile(file) sdb.closeInput(True) @using_scope def _() -> None: ms = sdb.modelSpace() ents = [Db.Entity(id) for id in ms.objectIds()] for ent in ents: names[ent.isA().dxfName()] +=1 print(names) except Exception as err: traceback.print_exception(err) # use axtiveX fter axdb @Ap.Command() def doitx(): try: names = defaultdict(int) for file in Ap.Application.listFilesInPath("E:\\temp", ".dwg"): sdb = Db.Database(False, True) sdb.readDwgFile(file) sdb.closeInput(True) @using_scope def _() -> None: axdb = sdb.acadDatabase() for axobj in axdb.modelSpace(): names[axobj.entityName()] +=1 print(names) except Exception as err: traceback.print_exception(err)0 -
For us our dwg's were controlled using layouts and always with title block at 0,0 a simple step. We had lisp programs that plotted the dwg using a predefined printer setup, so it would walk through all layouts and print them.
So part 2 it is easy to use a script to OPEN a dwg then call the lisp plot routine, close dwg, open the next and so on.
By using the (command "plot" you can ignore the current sheet settings as the program does a temporary over write.
Are you dwg's all similar and use layouts ?
Final comment for a client did do plot all layouts and they could be a mix of title blocks rather than just one size.
So provide some details about your dwg's.
0 -
The drawings do have layouts. The lisp that runs on each one plots a PDF, exports some image files, generates a rendering. All that works on a single file, but looking for one that would run that lisp multiple times.
Tried, this but can't multiselect in the dialog box, and while it says it Batch Processing Complete when 1 is selected, it's not running ExportAllFormats on that drawing.
(defun c:BatchProcessDrawings ( / filelist currentfile )
(setq filelist (getfiled "Select Drawings" "" "dwg" 16)) ; Allows multiple file selection
(load "A:\ExportFiles.lsp")
(if filelist
(progn
(foreach currentfile filelist
(princ (strcat "\nProcessing: " currentfile))
(command "_open" currentfile) ; Open the drawing
(command "ExportAllFormats") ; Call your desired LISP commands here
(command "-purge" "a" "*" "n") ; Example: Purge all unused items
(command "qsave") ; Save the changes
(command "_close") ; Close the drawing
)
(princ "\nBatch processing complete.")
)
(princ "\nNo files selected.")
)
(princ)
)0 -
As I mentioned use a script, wont go into it now but you can write scripts using lsip so say select dwgs to process.
A Script, just put correct path and file name in the load. Or appload the BatchProcessDrawings.lsp on startup then its there for every dwg.
You need to remove the coding about getting the dwg names. Just keep the plot parts if you want a message must be before CLOSE as that must be last command. Just get a new lisp to work on current open dwg.
Open dwg1
(load "BatchProcessDrawings.lsp")
(c:BatchProcessDrawings)
close n
Open dwg2
(load "BatchProcessDrawings")
(c:BatchProcessDrawings)
close n
0

