The 4 Rules of Script Files

Before the recipes, four rules that prevent 90% of script failures. (If a script still misbehaves, our troubleshooting guide covers the failure modes one by one.)

  • Every line break is an Enter keypress. A blank line is also an Enter. Scripts fail when the prompt sequence and your line sequence drift apart, so count your Enters.
  • The file must end with a newline. The classic silent failure: the last command never executes because there's no Enter after it. Always leave a trailing newline.
  • Use hyphen-prefixed commands. -PURGE, -PLOT, -LAYER, -XREF, -INSERT. The hyphen forces the command-line version. Anything that opens a dialog will stall a headless session.
  • Test in full AutoCAD first. Type the commands manually at the AutoCAD command line and write down every prompt. Your script must answer exactly those prompts, in exactly that order.

Every recipe below runs with the same invocation pattern (see the main guide for the switches):

accoreconsole.exe /i "C:\Drawings\part001.dwg" /s "C:\Scripts\recipe.scr" /isolate

Recipe 1: Batch DWG to PDF

The most requested batch job. The simplest form uses the current export settings:

-EXPORTPDF

For controlled output (specific layout, named page setup, output folder), use -PLOT with a page setup that already exists in your drawings or template:

-PLOT
N
Layout1
ISO-A1-PDF
C:\Output\part001.pdf
N
Y

Line by line: don't do detailed configuration (N), plot this layout, use this saved page setup, write to this file, don't save changes to the layout (N), proceed with plot (Y). The page setup carries the printer (DWG To PDF.pc3), paper size, and plot style, which is why standardizing page setups in your template pays off before you automate.

Per-file output names: a static .scr can't vary the output path per drawing. Generate the .scr on the fly in your wrapper (one per drawing, with the filename substituted in), or move to a .NET plugin. The PowerShell wrapper below shows the generated-script pattern.

Recipe 2: Purge, Audit, and Save

Drawing hygiene across an entire library: remove unused blocks, layers, and styles, fix database errors, save.

-PURGE
A
*
N
AUDIT
Y
QSAVE

The prompts being answered: purge All object types, all names (*), no per-item verification. Then audit and fix any errors found (Y), then save. Run -PURGE twice in stubborn drawings: purging a block can orphan the layers and linetypes it referenced, and a second pass catches them.

Recipe 3: Convert DWG Versions

Clients on older AutoCAD versions, analysis tools that only read older formats, or archival standards often require saving down. This converts to the 2018 DWG format (used by AutoCAD 2018 through current releases; substitute 2013, 2010, etc. as needed):

SAVEAS
2018
C:\Converted\part001.dwg

If the target file already exists, SAVEAS will ask whether to overwrite, and your script must answer it. Add a Y line if your workflow overwrites, or write to an empty output folder so the prompt never appears (the safer pattern for batches).

Recipe 4: Update Title Block Text

Global attribute editing with -ATTEDIT handles the classic "change the revision on every sheet" request. This changes attribute value REV B to REV C in every TITLEBLOCK insert:

-ATTEDIT
N

TITLEBLOCK
REV

REV B
REV C

The prompts: not one at a time (N = global editing), edit attributes not visible on screen too (blank accepts the default), restrict to block name TITLEBLOCK, restrict to tag REV, any attribute value (blank), then the string to find and its replacement.

-ATTEDIT does string replacement, not assignment: it finds "REV B" and substitutes "REV C". If your drawings hold inconsistent current values, string replacement gets brittle. Setting an attribute to an absolute value regardless of what it currently holds is a five-line job in a .NET plugin, and that's the better tool once title block data comes from an ERP or document register.

Recipe 5: Enforce Layer Standards

Create standard layers (if missing), set their properties, and retire a legacy layer name in one pass:

-LAYER
M
DIM-ANNO
C
3
DIM-ANNO
LT
Continuous
DIM-ANNO

-RENAME
LA
DIMENSIONS
DIM-ANNO
-PURGE
LA
*
N
QSAVE

M makes (or makes current) the layer, C sets color 3 (green) on it, LT sets the linetype, and the blank line exits the layer command. Then -RENAME merges the legacy name into the standard one, and a layer purge sweeps anything now empty. Note: -RENAME fails if both layers already exist, so for drawings that may contain both, use LAYMRG (layer merge) instead, or handle the condition in a plugin.

Recipe 6: Repath or Bind Xrefs

After a server migration, every drawing points at dead xref paths. Repath a known xref:

-XREF
P
SITE-PLAN
\\newserver\projects\site-plan.dwg
QSAVE

Or bind all xrefs into the drawing before issuing to an external party (making it self-contained):

-XREF
B
*
QSAVE

P is the Path option (xref name, then new path), B binds, and * binds all attached references. Binding fails on unloaded or unresolved xrefs, so run a repath pass before a bind pass when in doubt.

Recipe 7: Replace a Block Definition

Roll out a new title block, north arrow, or standard detail across the library by redefining the block in place. The name=path syntax replaces the in-drawing definition with the external file; every existing insert updates instantly:

-INSERT
TITLEBLOCK=C:\Standards\TITLEBLOCK.dwg
0,0
1
1
0
ERASE
L

ATTSYNC
N
TITLEBLOCK
QSAVE

The trick: -INSERT with = redefines the block but then insists on placing an insert, so we place it at 0,0 (scale 1, 1, rotation 0) and immediately erase it (L = last object, blank line ends selection). ATTSYNC then pushes the new definition's attribute layout to all existing inserts. Skip ATTSYNC for non-attributed blocks.

Recipe 8: Run AutoLISP Routines

Scripts can load and invoke AutoLISP, which unlocks selection sets and entity-level logic:

(load "C:/Scripts/setbylayer.lsp")
FORCE-BYLAYER
QSAVE

Where the LISP file defines a command, for example forcing all entities to ByLayer color:

(defun c:FORCE-BYLAYER (/ ss i ent)
  (setq ss (ssget "X"))
  (if ss
    (repeat (setq i (sslength ss))
      (setq i (1- i)
            ent (entget (ssname ss i)))
      (entmod (append (vl-remove-if
        (function (lambda (p) (= 62 (car p)))) ent)
        (list (cons 62 256))))))
  (princ))
The big LISP limitation: AcCoreConsole supports core AutoLISP only. Anything using vla-* or vlax-* functions (the COM/ActiveX layer) fails with "no function definition" errors. Most LISP found online uses them. See the limitations section of the main guide before porting an existing routine.

The PowerShell Wrapper: Logging and Parallelism

A plain .bat loop works, but PowerShell gives you the two things production batches actually need: a log per drawing and parallel execution. This processes a whole tree, captures each drawing's console output, and runs four instances at once:

$acc    = "C:\Program Files\Autodesk\AutoCAD 2025\accoreconsole.exe"
$script = "C:\Scripts\clean.scr"
$logDir = "C:\Logs"

Get-ChildItem "D:\Projects" -Filter *.dwg -Recurse |
  ForEach-Object -ThrottleLimit 4 -Parallel {
    $log = Join-Path $using:logDir "$($_.BaseName).log"
    & $using:acc /i $_.FullName /s $using:script /isolate *>&1 |
      Out-File $log
    if (Select-String -Path $log -Pattern "Unknown command|error|Invalid" -Quiet) {
      Write-Warning "CHECK: $($_.Name)"
    } else {
      Write-Host "OK: $($_.Name)"
    }
  }

Three details worth stealing even if you keep a .bat file: capture the console output (it's your only diagnostic when a drawing fails), grep the output for failure keywords because AcCoreConsole's exit codes are not a reliable failure signal, and cap parallelism around your core count. Because each drawing is its own process, one corrupt file kills one process, not the whole batch. That per-process isolation is something full AutoCAD batching can't give you, as covered in our comparison of AutoCAD batch processing options.

For per-file output names (Recipe 1), generate the script inside the loop: build the .scr content as a string with the drawing's own output path substituted in, write it to a temp file, pass that to /s.

When Scripts Aren't Enough

Every recipe above applies the same operation to every drawing. The moment the operation depends on what's in the drawing (this title block layout vs that one, flange drawings plotted differently from pipe drawings, attributes filled from an ERP query), scripts stop being the right tool, and stretching them past that point produces the undocumented, unmaintainable .scr folders that outlive their authors.

The step up is a .NET plugin running inside AcCoreConsole: real conditional logic, error handling, and system integration, loaded with NETLOAD exactly as described in the main guide. That's the kind of automation we build for engineering teams every week. If you have a batch workflow that's outgrown these recipes, tell us what it needs to do and we'll tell you honestly whether it's a script, a plugin, or not worth automating at all.