Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 38 ยท Automation and Plotting

AutoCAD Scripts (.scr), Action Recorder and Aliases

Automate repetitive AutoCAD work: write .scr script files, run them with SCRIPT, record macros with the Action Recorder, create command aliases in acad.pgp and set up palettes and tool buttons.

Automation in AutoCAD starts small. If you type the same ten commands every Monday (set layers, purge, audit, save) you can put them in a text file and run it with one command. This lesson covers the simplest automation tools: script files, the Action Recorder, command aliases and tool palettes. AutoLISP, covered next, goes further with variables and logic.

AutoCAD cannot run on this site. File formats and menus are described as they are in the program, and the runnable examples are clearly labelled JavaScript stand-ins that generate and "run" scripts without touching AutoCAD.

Script files

A script is a plain text file with the extension .scr. Each line is typed into the command line exactly as you would type it yourself, and a space or a new line equals pressing Enter. Run it with SCRIPT (choose the file) or by dragging the file onto the drawing, or from acad.exe with /b.

Important rules:

  • Write exactly what the prompts expect, in order. Every character counts, including blanks that press Enter at the end of a command.
  • Use the hyphen form of dialog-based commands (-LAYER, -PURGE, -HATCH, -INSERT, -PLOT, -EXPORT) so they prompt at the command line instead of opening a dialog.
  • A semicolon at the start of a line begins a comment.
  • Use a leading underscore (_LINE, _ZOOM) for the international command names in any language version, and a period (._LINE) to avoid redefined commands.
  • RSCRIPT repeats the script, DELAY 1000 pauses (in milliseconds), RESUME continues a paused script, and Esc stops it.
  • End with a blank line when the last command expects Enter.

A small example setup.scr:

TEXT
; Create standard layers
-LAYER N A-WALL,A-DOOR,A-ANNO
C 1 A-WALL
C 4 A-DOOR
LW 0.50 A-WALL

_ZOOM E
_QSAVE

Within -LAYER: N = New, names separated by commas, C = Color then number then layer name, LW = Lineweight. A trailing space (or blank line) finishes the command. If an option is not available in your release, run -LAYER interactively and copy the prompts.

JS Stand-in: generate a layer-creation script

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Running a script on many drawings

  • Use the Script Pro type tools or the SCRIPT command inside a batch from the Windows command line: accoreconsole.exe /i drawing.dwg /s setup.scr (the AutoCAD Core Console runs scripts without opening the window). This is the foundation for batch processing hundreds of drawings: purge, change the title, export PDFs.
  • Create a .bat file that loops over drawings and runs the same script on each.
  • Keep scripts simple, because they cannot make decisions. If you need "if this layer exists, do that", use AutoLISP.

Action Recorder

The Action Recorder (Manage > Action Recorder) records what you do as a macro, without writing code:

  1. Click Record, name the macro (CleanUp), and run commands as usual.
  2. Click Stop. Steps appear in a tree in the panel.
  3. Insert user message or Insert base point to pause for input, so the macro asks you to pick things when played.
  4. Click Play to run it; the macro is saved as an .actm file in the Actions folder.

Pause/Play and edit the values of a recorded step in the panel. The recorder only captures commands that accept the Action Recorder (some complex dialogs are skipped). Macros are linear and cannot loop or test conditions; they are best for a sequence like "set layer, draw a polyline, fillet, offset". You can convert them to scripts through the export option, though the output is limited.

Command aliases

An alias shortens a command: L for LINE, CO for COPY. They are stored in acad.pgp, an ASCII file. Open it with Manage > Customization > Edit Aliases > Edit Aliases (ALIASEDIT), and add a line such as:

TEXT
LL,   *LAYER
LI,   *LAYISO
LU,   *LAYUNISO

The part before the comma is what you type; the text after the asterisk is the command. Save, then run REINIT (and tick the PGP File box) so changes work without restarting. Plan aliases around two or three letters on the left of the keyboard. Avoid reusing ones that already exist.

JS Stand-in: resolve aliases like acad.pgp does

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Other quick automation

  • Tool palettes (Ctrl+3) hold commands, blocks and hatches; right-click > Customize Commands to add a button that runs a macro string like ^C^C_-LAYER;S;A-WALL;;.
  • In macros, ^C^C cancels any running command, ; is Enter, and the underscore _ handles translated commands.
  • The CUI (CUI) edits ribbons, menus and keyboard shortcuts. Customization files are .cuix.
  • Quick Properties and Quick Select (QSELECT) reduce clicks on repeated selections.
  • -PURGE in a script: -PURGE A * N purges everything without confirmation.
  • AUDIT and RECOVER appear often in cleanup scripts.

Common mistakes

  • Forgetting the blank line or space that ends a command, so the next line is taken as an answer.
  • Using dialog commands in a script (they open a window and stop).
  • Writing paths with backslashes in a script: use forward slashes.
  • Running scripts on a drawing with a different layer set and not testing first.
  • Adding aliases that clash with built-ins or do not match the command's real name.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In a script file, what does a space or a new line stand for?

    Both act like pressing Enter in the command line.
  2. 2. Why use -LAYER instead of LAYER in a script?

    The hyphen form is the command-line version, which scripts can answer.
  3. 3. Which file stores command aliases?

    acad.pgp holds the alias definitions, and ALIASEDIT edits it.
  4. 4. Which tool records your command sequence without writing code?

    The Action Recorder saves what you do as an .actm macro that you can play back.

Summary

  • A .scr file is a plain-text list of commands, where spaces and line ends act as Enter.
  • Use hyphen commands, comments with ;, and accoreconsole.exe for batch jobs.
  • The Action Recorder builds simple macros; aliases in acad.pgp shorten commands.
  • Tool palettes and CUI macros attach sequences to buttons.
  • For logic and loops, move to AutoLISP.

Next: AutoLISP basics