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.
Recording one
You do not write a macro from a blank page. You do the job once, with CoPilot, and record it.
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 macroWhile 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.
Do the job. Work normally: chat, ribbon commands, anything that drives the CAD system. It is all captured.
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:
- A call that failed, was refused or was rejected is dropped.
- A read-only call is dropped — a macro does not need the measurements you took to decide what to do next.
- An Undo removes the step it reverted, and itself. A second Undo reaches the step before that.
- Something you created and then deleted again in the same recording goes out with its delete — unless something you kept used it in between.
- A failed attempt followed by the same operation succeeding keeps the successful one only.
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.
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
- An operation starts with a capital letter.
GetFeatures()is a CAD operation;rows(path)is a built-in function;folderis your parameter. The capital is the whole rule — you never have to declare anything. - The only escape is a doubled quote. There is no
\nand no\\, so a Windows path is written exactly as it is:"C:\new\tools"is that path. To put a quote inside a string, double it. - Arguments are
name=value, and a value can be a number, a string, an expression, or a JSON object or array for the operations that take one.
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:
A run is one operation
- One approval card for the whole run, naming the destructive operation kinds it contains — “Run macro 'Enlarge holes in a folder' on SOLIDWORKS: will ModifyFeatureParameter, CloseDocument”. Approve once and the whole run is approved; “always allow this session” behaves exactly as it does for a single operation.
- One progress line in the chat, and one result card at the end with the step count, the iteration count, the duration and any failures with their line numbers.
- The CAD is held for the run. No chat turn on that CAD can interleave with it, so nothing reads a half-finished model.
- Stop cancels between steps — the run ends cleanly and the result says what had already been done.
What it refuses to do
- A script with errors is refused before anything runs. The macro is validated against the operations your connected CAD actually has, and a bad operation or argument name comes back with its line number and nothing was executed.
- An ambiguous CAD is refused, not guessed.
cad anymeans “the one connected session”; with two connected, the run stops and lists them so you can say which. - A step that stops answering ends the run, whatever
on errorsays — its effect on the model is unknown, so the run does not build on it. The result keeps what had already been done. on error stopends the run at the failing line.on error continueabandons the rest of that loop iteration and goes on to the next one, reporting the failure.
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:
- Local — your own macros, on your PC. You create, edit and delete them freely.
- Global — macros an organization admin has published for everyone. They open read-only, with a banner saying so; publishing and editing a global macro is the server's decision, and if you do not have permission you are told, and nothing is written locally.
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 macro repeats. Same steps, different inputs. Reach for it when the job is settled and you will do it again.
- A skill adapts. It changes how CoPilot decides, so it applies to parts it has never seen. Reach for it when the job varies but the rules do not.
- A variation template fills a grid. One master document, a set of named instances, one Generate. Reach for it for a family of sizes.
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
- Variations — a family of sizes from one master.
- Spending fewer tokens — why recording a macro is the biggest single saving.
- Native Macros & Automation — your CAD system's own macros and journals, the Automation Hub and scheduled tasks.
- Skills · Examples · Chat Basics
- Verifying results