An AutoCAD script file (.scr) is a plain text file that contains a sequential list of AutoCAD commands and the exact command-line responses. Scripts let you automate repetitive tasks, enforce consistency across drawings, and run the same sequence of operations on many files.
What an AutoCAD script (.scr) is and when to use it
A script file for AutoCAD is a simple ASCII text file that lists commands and the inputs those commands expect, each separated by new lines or spaces. When you run the script, AutoCAD executes each command exactly as if you had typed it at the command line.
Use scripts when you need to:
- Perform batch processing on many drawings (same commands on multiple files).
- Create custom workflows not easily available through the GUI.
- Do drawing cleanup (purge unused objects, set layers, run audit).
- Standardize settings across a project (units, layers, text heights).
Scripts are lightweight, easy to edit with Notepad, and are ideal when you want a deterministic, repeatable set of actions.
How AutoCAD script syntax works (Explanations)
- Scripts are plain text files with extension .scr. Use ANSI encoding (avoid UTF-8 with BOM).
- Each line is treated as a command or an input to the previous command. You must supply exactly the inputs the command expects.
- Use hyphenated command names (for example,
-LAYERor-PURGE) to avoid dialog boxes and make scripts fully command-line driven. - There is no native comment syntax in script files — any line that isn’t recognized as a valid command or input can cause errors.
- Commands like
SAVEorQSAVEcan be included to save your work at the end of the script.
Example minimal script (explanations follow in the Steps section):
ZOOM
E
-AUDIT
Y
-QSAVE
Step-by-step: Create and run a .scr file
1) Create the script file
- Open Notepad (or any plain text editor).
- Enter the commands exactly as you would type them in AutoCAD, placing command responses on the next lines. Example script to zoom extents, run audit (command-line version), purge all, and save:
ZOOM
E
-AUDIT
Y
-PURGE
ALL
N
QSAVE
- Save the file with the extension .scr (for example, myCleanup.scr). Choose ANSI encoding to avoid issues.
2) Test the script on a copy of your drawing
Always test scripts on a backup copy of a drawing to avoid unintended changes.
3) Run the script from AutoCAD
- Type SCRIPT at the AutoCAD command line, press Enter, then browse to and select your .scr file.
- Or drag-and-drop the .scr file from Explorer directly into an open AutoCAD drawing window — the script will start executing immediately.
- You can also run a script programmatically from LISP or from a batch process (see Alternative methods below).
4) Monitor the command line
Watch the AutoCAD command line while the script runs. If the script hits a dialog box or unexpected prompt, it will pause or fail.
Practical script examples (safe, beginner-friendly)
Example A — Zoom extents, audit and save:
ZOOM
E
-AUDIT
Y
QSAVE
Example B — Purge all zero-length geometry and save:
-PURGE
A
N
QSAVE
Notes:
-AUDITor-PURGE(with the leading hyphen) run the command-line version and avoid GUI dialogs.- Use uppercase for readability; AutoCAD is not case-sensitive.
Alternative methods to automate AutoCAD tasks
- ScriptPro (Autodesk ScriptPro or third-party batch script runners): designed for batch processing multiple drawings with a script.
- AutoLISP (.lsp): far more powerful, supports logic, loops, prompts and error handling. Use LISP when you need conditional behavior or variable manipulation.
- Action Recorder: records GUI actions and plays them back; good for simple UI tasks but less flexible than scripts for batch work.
- Macros/Tool palettes: store commonly used command sequences for manual use.
- Sheet Set Manager and Publisher: automate publishing and sheet management for multi-sheet projects.
When to choose:
- Use .scr for simple, deterministic sequences and straightforward batch runs.
- Use AutoLISP when you need logic, file I/O, or error handling.
- Use ScriptPro or a batch utility to run scripts across folders of drawings automatically.
Common errors and how to fix them
-
Problem: Script stops because a dialog box opens.
- Fix: Use hyphenated commands (e.g.,
-PURGEinstead ofPURGE) to force command-line prompts, and supply the exact responses in the script.
- Fix: Use hyphenated commands (e.g.,
-
Problem: Script fails to find the file or AutoCAD can’t run it from a path.
- Fix: Put the .scr file in AutoCAD’s current working folder, or run SCRIPT and browse to the full path. Avoid special characters in the path.
-
Problem: Unexpected command prompts or different prompts in different AutoCAD versions.
- Fix: Test the script in the exact AutoCAD version you will use and use command-line variants when possible.
-
Problem: Script creates syntax errors or strange inputs.
- Fix: Ensure each command input is on the correct line and you have not included stray text. Remove blank lines that might be interpreted as empty inputs in sensitive sequences.
-
Problem: Encoding issues; characters appear as�? or script behaves oddly.
- Fix: Save the .scr as ANSI (not UTF-8 with BOM). Use a plain text editor that supports encoding selection.
-
Problem: Script runs too slowly or seems to hang on large drawings.
- Fix: Break large operations into smaller steps, avoid commands that trigger heavy regeneration frequently, or run on copies.
Best practices and tips
- Always test scripts on a copy of the drawing first.
- Use hyphenated commands to avoid GUI dialogs and ensure reliable behavior.
- Keep scripts simple and modular — create small scripts for specific tasks and chain them if necessary.
- Keep a versioned library of scripts (with clear names) so others on your team can reuse them.
- Include a short header as part of the file name (e.g., 2025_PurgeAndAudit.scr) for traceability — but do not place comments inside the script file.
- Use QSAVE at the end of the script to automatically save changes, or leave it out if you prefer manual verification before saving.
- When running batch operations across many files, run scripts in a controlled environment (off-peak hours) and monitor logs if available.
- If you need conditional checks or loops, use AutoLISP rather than relying on scripts.
FAQ
What is the difference between a .scr and a .lsp file?
A .scr file is a plain text sequence of command-line commands and responses — no logic or branching. A .lsp (AutoLISP) file is a programming script with variables, loops, and conditional logic, suitable for more complex automation.
Can I include comments inside a .scr file?
No. AutoCAD script files do not support comments — any extra text will be treated as commands or inputs. Keep scripts strictly to the commands and responses required.
How do I run the same script on many drawings at once?
Use Autodesk ScriptPro or other batch tools to run an .scr file across multiple DWG files. Alternatively, write an AutoLISP routine to open each file and call the SCRIPT command programmatically.
Why does my script stop and wait for input?
Your script likely triggered a dialog box or a prompt that wasn’t anticipated. Use the hyphenated command version (for example, -PURGE) and provide the required responses in the script.
What encoding should I use when saving .scr files?
Save as ANSI plain text. Avoid UTF-8 with BOM because the Byte Order Mark can confuse AutoCAD.
Can I call a script from AutoLISP?
Yes. An AutoLISP routine can call the SCRIPT command to run an .scr file, allowing you to combine programmatic logic with a fixed command sequence.
Is there a way to pause or wait inside a script?
No native pause/wait command exists for scripts. If you need pauses, interactive behavior or conditional logic, use AutoLISP or the Action Recorder instead.
How can I avoid damaging my drawings with scripts?
Always test on copies, use version control for scripts, and include save checkpoints (or avoid automatic saves) so you can verify results before overwriting originals.
