Macros

A macro is a job you have already proved, written down so it can be run again without a conversation. Record what you did, give it parameters, and run it over a folder of parts or a spreadsheet of sizes — as one operation, with one approval, and with no AI model involved in the run at all.

What a macro is

A macro is one UTF-8 text file with the extension .cadmacro. That file is the macro — the picker, the editor and the chat all show you the same text, and there is nothing else stored behind it. You can read it, diff it, e-mail it to a colleague and put it in version control.

Here is a complete one:

macro "Enlarge holes in a folder"
description "Adds delta to every hole diameter of every part in a folder"
cad any
tags holes, batch
on error stop
param folder  : folder     = "C:\Parts"
param pattern : text       = "*.sldprt"
param delta   : number(mm) = 2

for file in files(folder, pattern)
    OpenDocument path=file
    let feats = GetFeatures()
    for f in feats.features where f.type == "Hole"
        let p = GetFeatureParameters featureName=f.name
        ModifyFeatureParameter featureName=f.name parameterName="Diameter" value=(p.Diameter + delta)
    end
    SaveDocument
    CloseDocument
end

Run that once and every part in C:\Parts comes back with every hole 2 mm larger. Change the three parameters at the prompt and the same file does a different folder, a different file type and a different increment.

A macro run calls no AI model. Every step goes straight to the CAD system through the same direct dispatch a single operation uses. That is what makes a macro fast, repeatable and — if you are paying per token — effectively free to re-run. See Spending fewer tokens.

Recording one

You do not write a macro from a blank page. You do the job once, with CoPilot, and record it.

  1. Start recording. Press Record Macro in the chat card, or Record in the macro library — which you open from the macro glyph on the balloon, the balloon's Macros… menu entry, the chat card's header, or the Macros button on your CAD's CoPilot ribbon. Or simply ask:

    Start recording a macro

    While a recording is running the macro glyph on the balloon turns red and the chat shows a REC chip, so you can always see that it is on.

  2. Do the job. Work normally: chat, ribbon commands, anything that drives the CAD system. It is all captured.

  3. Stop. Press Record again, or say stop recording. You are given a draft script to review, name and save.

The recorder keeps only what finally worked

A recording is not a keystroke log. When you stop, the draft is cleaned up, and every rule only ever removes steps:

So you can fumble your way through the job, undo a wrong move, retry a step that failed, and still get a clean script at the end.

A recording belongs to one CAD session. If you have two CAD systems connected, the recording binds to the one you started it on; work done in the other is ignored, counted, and reported to you in the draft (“ignored: 7 call(s) from another CAD session”). Nothing is dropped silently, and a Solid Edge recording can never end up holding SOLIDWORKS steps.

Parameters are offered, never assumed

The draft comes with suggested parameters: a repeated number, a folder path, a value the recording could not re-run with (an entity id that came back from an earlier call, or a name that a second run would find already taken). Each suggestion says how often it occurred, which operations used it, and why it is being offered. Nothing is parameterised until you agree to it.

Parameters and the prompt

Every param line becomes a field in the dialog that appears when you press Run:

param folder    : folder        = "C:\Parts"
param pattern   : text          = "*.sldprt"
param delta     : number(mm)    = 2
param dryRun    : bool          = true
param finish    : choice(Zinc, Anodised, Raw) = "Zinc"
param sizeList  : file          = "C:\input\sizes.xlsx"

The type picks the editor: a number box with its unit, a text box, a checkbox, a drop-down, or a file/folder picker. Your last values are remembered per macro, so running the same macro on the same folder tomorrow is two clicks.

Looping over files and spreadsheet rows

Two built-in functions cover most batch work.

A folder of files:

for file in files(folder, "*.ipt")
    OpenDocument path=file
    SetCustomProperties propertiesJson={"Revision":"B"}
    SaveDocument
    CloseDocument
end

Rows of a spreadsheet. rows() reads .xlsx, .xlsm, .csv and .tsv; the first row is the header, and each column becomes a field you address by name:

for r in rows("C:\input\parts.xlsx")
    InsertComponent path=r.File x=r.X y=r.Y z=r.Z
end

Any other text file is read a line at a time. Use lines(path) when you want the bare line, and rows(path) when you want an object with a .line field — mixing the two up is the one easy mistake here, and the error message says so.

You can filter as you loop, and branch:

for f in feats.features where f.type == "Hole"
    ...
end

if props.Finish == "Zinc"
    ...
else
    stop "not a zinc part"
end

Three things about the syntax worth knowing

There are no other statements: param, let, for … end, if … else … end, stop "message", an operation call, and # comment. There is deliberately no way to run arbitrary code and no file access beyond the files the script names — a macro has to be reviewable by reading it.

Running a macro

Open the library (the Macros button on the CoPilot ribbon, the macro glyph on the balloon, or the chat card's header), find the macro, press Run, fill in the parameters, and confirm.

You can also ask for it by name, and CoPilot runs it the same way the button does — as one call, never by replaying the steps itself:

Run the "Enlarge holes in a folder" macro on C:\Projects\Frame with delta 1.5

A run is one operation

What it refuses to do

Runs are capped at 5,000 steps and 20,000 iterations, and the limits are stated in the result so you can see how close you came.

The library

One searchable list, with a tab for macros and a tab for variations. Type to filter by name, description or tag; arrow keys and Enter to choose. Each row carries a badge and three actions:

A local macro and a global one may share a name — both are listed with their badge, and yours wins on your own PC.

Row actions: Run opens the parameter dialog. Edit opens a monospace editor that validates as you type and keeps Save disabled while the script is invalid, with the errors listed by line. Explain asks CoPilot to describe what the macro does in prose — that one is a chat turn, by definition.

Above the list: New macro, Record, and Refresh global.

Macro, skill or variation?

A skill can also name a macro as one of its steps — the macro is then run as one operation, not re-played step by step.

See also