CAD / BIM
Automating AutoCAD With Python: Batch-Fix 50 Drawings in Minutes
Two practical Python tools for engineering firms: run a cleanup script on every DWG in a folder without opening AutoCAD, and audit layer standards across a whole project automatically.
April 16, 2026
AutoLISP is perfect for automating what happens inside one drawing. But a lot of the repetitive work in an engineering firm happens across many drawings:
- Purge and audit every sheet in a 40-sheet set before submittal.
- Check that a client's base files follow your layer standard before you start.
- Find which of 120 archived drawings still use an old title block.
Opening each file by hand is the slow way. Python is the fast way.
In this post we'll build two small tools you can use this week. You don't need to be a developer. If you can follow a recipe, you can run these.
What you need
- Python 3.10 or newer, free from python.org. During installation on Windows, check "Add Python to PATH."
- AutoCAD (for Tool 1): any recent full version includes the console tool we'll use.
- The
ezdxflibrary (for Tool 2): install it by opening a command prompt and typing:
pip install ezdxf
Tool 1: Run a script on every DWG without opening AutoCAD
AutoCAD ships with a little-known program called accoreconsole.exe, the AutoCAD engine without the user interface. It opens a drawing, runs a script, saves and closes, much faster than the full program because there's nothing to draw on screen.
On its own it handles one file at a time. Python turns it into a batch machine.
Step 1: Write the AutoCAD script
A .scr file is just a list of commands, exactly as you'd type them at the command line, one answer per line. Save this as cleanup.scr:
-PURGE A * N -PURGE A * N AUDIT Y ZOOM E QSAVE
This purges unused items twice, fixes database errors with AUDIT, zooms to extents and saves.
Step 2: The Python batch runner
Save this as batch_cleanup.py:
"""Run an AutoCAD script on every DWG in a folder, working on copies."""
import csv
import shutil
import subprocess
import sys
from pathlib import Path
# Adjust to your AutoCAD version and install location
ACCORE = Path(r"C:\Program Files\Autodesk\AutoCAD 2026\accoreconsole.exe")
SCRIPT = Path("cleanup.scr").resolve()
def run_batch(source: Path, output: Path) -> None:
output.mkdir(parents=True, exist_ok=True)
results = []
for dwg in sorted(source.glob("*.dwg")):
copy = output / dwg.name
shutil.copy2(dwg, copy) # never touch the original
proc = subprocess.run(
[str(ACCORE), "/i", str(copy), "/s", str(SCRIPT), "/l", "en-US"],
capture_output=True,
timeout=300,
)
status = "OK" if proc.returncode == 0 else f"ERROR {proc.returncode}"
results.append([dwg.name, status])
print(f"{status:10} {dwg.name}")
with (output / "batch_log.csv").open("w", newline="") as f:
writer = csv.writer(f)
writer.writerow(["file", "status"])
writer.writerows(results)
print(f"\nDone: {len(results)} drawings processed. Log: {output / 'batch_log.csv'}")
if __name__ == "__main__":
run_batch(Path(sys.argv[1]), Path(sys.argv[2]))
Run it from a command prompt:
python batch_cleanup.py "C:\Projects\26-114\Sheets" "C:\Projects\26-114\Sheets_clean"
Python copies every drawing into the new folder, runs the script on each copy, and writes a CSV log so you can see which files had problems.
What else you can put in the script
Anything you can type at the command line can go in a .scr file. Common batch jobs:
- Set system variables across a set (e.g.
PSLTSCALE,MSLTSCALE) so linetypes plot the same on every sheet. - Run
-LAYERto freeze or turn off a layer in every drawing. - Load and run one of your LISP routines with
(load "kronos-tools.lsp")followed by the command name. - Plot every sheet to PDF with
-PLOT(test this on two files first, since plot prompts are long).
One warning: a script answers prompts in a fixed order. If a command asks something unexpected (a missing layer, a drawing that needs recovery), the script can get out of step. That's why the log matters: check the files marked as errors by hand.
Tool 2: Audit your layer standard across a whole project
Before your team starts drawing over a client's base files, wouldn't you like to know which ones break your standards?
This tool reads every DXF in a folder (export from AutoCAD with DXFOUT, or batch-convert with Tool 1 using SAVEAS in DXF format) and reports:
- every layer that isn't in your standard, with how many objects are on it
- every piece of text that's sitting on the wrong layer
Save as audit_layers.py:
"""Audit every DXF in a folder against your layer standard and write a CSV report."""
import csv
import sys
from collections import Counter
from pathlib import Path
import ezdxf
STANDARD_LAYERS = {"0", "Defpoints", "C-ROAD", "C-STRM", "C-TOPO", "C-ANNO-TEXT", "C-BORE"}
def audit(folder: Path, report: Path) -> None:
rows = []
for path in sorted(folder.glob("*.dxf")):
try:
doc = ezdxf.readfile(path)
except (IOError, ezdxf.DXFStructureError) as err:
rows.append([path.name, "ERROR", str(err), ""])
continue
counts = Counter(e.dxf.layer for e in doc.modelspace())
for layer in doc.layers:
name = layer.dxf.name
if name not in STANDARD_LAYERS:
rows.append([path.name, "NON-STANDARD LAYER", name, counts.get(name, 0)])
for e in doc.modelspace().query("TEXT MTEXT"):
if e.dxf.layer != "C-ANNO-TEXT":
rows.append([path.name, "TEXT ON WRONG LAYER", e.dxf.layer, 1])
with report.open("w", newline="") as f:
writer = csv.writer(f)
writer.writerow(["file", "issue", "layer", "objects"])
writer.writerows(rows)
print(f"Checked {len(list(folder.glob('*.dxf')))} files, {len(rows)} issues -> {report}")
if __name__ == "__main__":
audit(Path(sys.argv[1]), Path(sys.argv[2]) if len(sys.argv) > 2 else Path("layer_audit.csv"))
Run it:
python audit_layers.py "C:\Projects\26-114\ClientBase" report.csv
You get a spreadsheet that looks like this:
file | issue | layer | objects |
|---|---|---|---|
| site_base.dxf | NON-STANDARD LAYER | road-old | 214 |
| site_base.dxf | TEXT ON WRONG LAYER | C-ROAD | 1 |
Open it in Excel, sort by file, and you know exactly what needs fixing before anyone starts drawing. Edit STANDARD_LAYERS to match your own layer table. This is your CAD standards document turned into an automated check.
How much time does this save?
Let's be concrete instead of quoting a made-up percentage.
Opening a drawing, purging, auditing, saving and closing by hand takes a careful person about two to three minutes per file once you count load times. On a 50-sheet set, that's roughly two hours. The batch tool does the same work while you do something else, and it never skips a file because it was Friday afternoon.
The layer audit is even more lopsided. Manually checking layers on 50 client base files is a full day nobody actually does, which is why problems usually get discovered halfway through the drawing set. Automated, it's a coffee break.
The real savings aren't the minutes. It's that the check happens every time, not only when someone remembers.
When to automate (and when not to)
A simple rule we use: if a task is repetitive, rule-based and done more than a few times a month, it's a candidate for automation. If it requires judgment (design decisions, interpreting a messy markup, deciding what a client meant), keep a human on it.
Automation doesn't replace your drafters. It removes the part of their job that nobody enjoys and everybody gets wrong eventually.
Where we come in
At Kronos GMT, Python and AutoLISP automation is part of how we deliver drafting. It's how we keep quality consistent no matter who on our team draws your project. We also build custom tools for clients: batch plotting, standards checks, quantity extraction to Excel, GIS-to-CAD conversions and more.
