Batch Script and dwg utilities

Plans: Free CAD Tools Geo Tools Urban Highways Aero
Command: CAPCAD_BATCH_SCRIPT Updated 2026-11-19 Also in: Español Português
Ask about this page
Answers from this page only. General assistant
Command CAPCAD_BATCH_SCRIPT
Shortcut none
Ribbon CapCad tab › CAD Utilities panel › Tools split button › Batch Script & Dwg Tools
Category NEW
Form BatchScriptForm — CapCad Batch Script, two tabs (Batch Script and Dwg Utils). Modeless: the drawing stays live and the form stays open while a test run goes through
Hosts AutoCAD, BricsCAD, GstarCAD, ZWCAD and ARES Commander
Also opened by the Batch button of the sign-check form (CAPCAD_SIGN_TOOLS › Util › Validar e publicar placa...), which runs this command so you can pick the Valida placa preset by hand

A sequence of commands you repeat every day becomes one button. Instead of typing purge, zoom extents, bind and save into every drawing, you write the routine once, tick the usual tasks, test it here and then run it over a whole folder.

  • Write it or load it. The body of the script can be typed in the box, read from a .scr file you already have, or filled by a preset.
  • The common tasks are already there. Full purge, layer 0 current, zoom extents, bind all xrefs, audit, e-transmit and save are checkboxes, not script lines.
  • CapCad's own commands go into the routine. CapCad's command-line versions, the ones beginning with -, work inside the script like any CAD command.
  • Test it in the open drawing, then run it over many. One button runs the routine in the drawing in front of you; another opens each chosen drawing in turn, runs it, saves and closes, and writes a log with the result of every file.
  • And clean-up utilities. The second tab rebuilds a dwg from its model space, leaving out whatever sits on a frozen layer: as a copy, over the same file, or over a whole folder.

What it does

The command opens a two-tab form.

On the Batch Script tab you assemble a routine: the body of the script in the text box, plus a list of extra parameters ticked in the checkboxes. There are two ways to run it.

Run script in THIS drawing to test it… assembles one single piece of text and hands it to the open drawing's command line, in this fixed order:

  1. the script, exactly as written (if Script: is ticked);
  2. -PURGE of everything, with no confirmation (Purge all);
  3. CLAYER to layer 0 (Layer "0" active);
  4. ZOOM Extents (Zoom extents);
  5. -XREF Bind * (Bind all Xrefs);
  6. AUDIT with error correction (Audit);
  7. TILEMODE 0 or TILEMODE 1 (Paper space active / Model space active);
  8. a save and an e-transmit package of the drawing (E-Transmit, only when the drawing has already been saved once);
  9. QSAVE (Save the drawing).

Because the text is handed to the CAD's command queue, the routine only starts once the current command finishes: the form stays open and you watch the commands run on the command line.

Select files & run runs the routine over a list of drawings, one at a time: see Running over many drawings.

On the Dwg Utils tab there are three buttons that rebuild a drawing from the entities of its model space.

Workflow

  1. Run CAPCAD_BATCH_SCRIPT. The form opens beside the drawing.
  2. Write the routine in the script box (13), load a ready .scr (3), or choose a preset (1).
  3. Tick the extra parameters you want (4 to 12). Note that Save the drawing is ticked already.
  4. Click Run script in THIS drawing to test it… (14) and watch the command line.
  5. Fix whatever needs fixing and run again; the form does not close.
  6. When the routine is right, choose Select a folder (17) to sweep a folder of .dwg files, or Dwg / Dxf (18, 19) to pick the files yourself, and click Select files & run (16).
  7. At the end, read the log in CapCad's Exports folder.

The Batch Script tab

CapCad Batch Script, Batch Script tab

The script box opens empty and the parameter boxes unticked, except Save the drawing.

The script

# Control What it does
1 Presets: Opens on none. Choosing a preset fills the form: Zoom writes a zoom-extents script; to modelspace, zoom extents and .9x writes a script that switches to model space, zooms extents and zooms out to 0.9; E-Transmit unticks every other parameter, ticks E-Transmit and Save the drawing, unticks Script: and locks the parameters until another preset is chosen; Valida placa writes the sign-validation command into the script box and locks the box. Choosing none again unlocks everything without changing the values.
2 Script: On by default. Off, the contents of box 13 are ignored and the run carries only the extra parameters you ticked.
3 Load a script file… Opens a file picker (*.scr, or all files) and drops the file's contents into box 13, replacing whatever is there.
13 script box The body of the routine. Every line is sent exactly as written, with a line break at the end, which the command line reads as Enter. A blank line is worth one Enter, exactly as in a .scr.

The text below the parameter frame reminds you that CapCad's command-line versions, the ones beginning with -, such as -CAPCAD_PROJECT_SET or -CAPCAD_STYLE_SET, can be used here too. They are described in Command-line commands.

Add extra parameters

# Control What it does
4 Purge all Adds a -PURGE of every unused item, with no confirmation prompt. Over many drawings it is run twice.
5 Layer "0" active Makes layer 0 the current layer.
6 Zoom extents A ZOOM Extents.
7 Bind all Xrefs An -XREF Bind *: every external reference becomes part of the drawing. Test runs only.
8 Audit An AUDIT with error correction. Test runs only.
9 E-Transmit Saves the drawing and creates its e-transmit package, a .zip with the drawing's name in the drawing's own folder, as the text below the box says. Ticking it selects the E-Transmit preset. In a test run it is skipped when the drawing has never been saved.
10 Paper space active Sets TILEMODE to 0. Test runs only.
11 Model space active Sets TILEMODE to 1. Test runs only. Neither comes ticked: with both unticked, the active space is not touched.
12 Save the drawing Ticked by default: adds a QSAVE at the end of the routine. The text below warns that, unticked, your script has to save on its own.

In a test run, the extra parameters always go in the order listed under What it does, after the script, whatever order you ticked them in.

Input Files

# Control What it does
15 Individual files Select files & run opens a file picker where you choose the drawings, several at once.
17 Select a folder (all files inside) Select files & run asks for a folder and takes every drawing in it, then asks Ok to process N files? before going on.
20 Include sub-folders With a folder, its sub-folders are swept too.
18, 19 Dwg, Dxf The format of the files to pick in the file picker. Dwg comes selected.
16 Select files & run Runs the routine over the chosen drawings: see below.
# Control What it does
14 Run script in THIS drawing to test it… Assembles the text and sends it to the open drawing's command line.
— video icon Opens the video walk-through. In an interface other than Portuguese the video is not available in this version.

Running over many drawings

Select files & run first checks that the script box is not empty while Script: is ticked (Script selected but not provided.). It then asks for the files or the folder, hides the form and opens a new empty drawing, so the batch never runs inside the drawing you were working on. Then, for each file, with a progress bar that names the file and has Cancel:

  1. it opens the drawing;
  2. makes layer 0 current (Layer "0" active);
  3. runs the script (Script:), with the CAD's file dialogs switched off so the script is never interrupted by one;
  4. purges everything twice (Purge all) and zooms extents (Zoom extents);
  5. saves (Save the drawing). A .dxf is always saved as a .dwg of the same name, in the same folder, replacing a .dwg that is already there;
  6. creates the e-transmit package (E-Transmit);
  7. closes the drawing without saving anything else.

Bind all Xrefs, Audit and the active-space options are not applied in this mode; put those commands in the script if you need them.

A drawing that is already open in the session is skipped and logged as an error, because the batch closes what it opens without saving. A drawing that fails is logged and the batch goes on to the next one. At the end, a log is written to CapCad's Exports folder, named after your Windows user and the start time: one line per file with SUCCESS or ERROR, the size before and after and the space gained, then the start and finish times, the number of files processed and the actions performed.

When the script contains the sign-validation command, the drawings are saved by that command itself and Save the drawing is not applied.

The Dwg Utils tab

CapCad Batch Script, Dwg Utils tab

The three buttons carry no number.

All three copy the entities of the model space into a new drawing, leaving out those on a frozen layer and keeping those on a layer that is merely off, as the notes beside the buttons say. Layouts, viewports and anything in paper space do not go with them.

Button What it does
Copy all dwg content to a new dwg Writes the copy to the file in Path (22). Left empty, the command proposes <drawing name>_copy.dwg in the drawing's own folder and writes that path into the box. When it finishes, a dialog shows the path written. Nothing to copy: "Nothing to copy."
Copy all dwg content to a new dwg, delete original, keep same name Works on the open drawing, which must have been saved (otherwise it warns and stops). After you confirm, it rebuilds the drawing from its model space, saves it over the same file in the AutoCAD 2010 format, closes the drawing without saving and reopens the rebuilt file.
Copy all dwg content to a new dwg, same name, multiple Does the same to every .dwg in the folder typed in Path (22), sub-folders not included, with a progress bar that has Cancel. Drawings open in the session are skipped. Ends with an ok box. With an empty path or a folder that does not exist, nothing happens.
# Control What it does
22 Path The copy's destination file for the first button; the folder for the third.

The two red buttons replace files on disk. Keep a backup of the folder before using them.

Remembered between sessions

Nothing. The form writes no preferences: the script box, the extra parameters and the copy path come back to the factory state on every open, with Save the drawing and Dwg ticked. The form is single per session: running the command again brings back the same window, with whatever you had typed, until you close it.

Notes

  • A test run happens afterwards, not during. The text is handed to the CAD's command queue, so the script starts when the current command ends. Do not expect to see the result the instant you click, and do not close the drawing before the routine finishes.
  • The script goes through raw. No line is validated. A mistyped command leaves the command line waiting for an answer that the script's next line will supply, and from there everything is out of step. Test new routines in a scratch drawing before running them over a folder.
  • With nothing ticked, nothing is sent. With Script: unticked, the box empty and no extra parameter, a test run sends no text at all.
  • The four Input Files options form a single group. Individual files, Select a folder, Dwg and Dxf sit in the same frame and untick each other: choosing Dxf clears the folder choice, and vice versa. So a folder is always swept for .dwg files, and .dxf files are processed by choosing Dxf and picking them in the file picker. With Dwg or Dxf chosen, the files are always picked one by one.
  • The batch closes without asking. Each drawing is closed without saving after the steps above, so whatever the script changes is kept only if Save the drawing is ticked or the script saves on its own.
  • The copy is not a "save as". The Dwg Utils buttons write a new dwg with the model-space entities only.

See also