Macro/Scripting: Project-specific Python scripts (local macros)
- Dominant language
- C++
- Stars
- 33.6k
- Forks
- 6k
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 196
Description
### Feature description
In FreeCAD, one can write (or use) Macros, either stored in the User's config or system-wide config.
This is very nice for general-purpose macros that can do heavy lifting, but for specialized scripts, not so much.
I have a simple use case: batch exporting a series of Part's bodies and Parts Containers (the yellow box :)) individually, with a name mapping and a single output folder (e.g. "Exports").
Nowadays it's fairly trivial to write a small python script to have an object/name mapping (e.g: "Shaft1" -> "Gearbox.Shaft1.stl") ; but within FreeCAD there is no easy ways to run such a small script via some automation.
You *could* jump in the console and write the same 2 or 3 lines over and over (load script & run essentially ).
You could also write a global User macro, but this won't be valid outside your project's context.
So, albeit there are ways to work around this feature, I think having a local customizable macro stored within a project (or a parent folder we can point to with relative paths), would be very nice :smile:
### Workbench affected?
None / Macro's support maybe ?
### Steps to reproduce
Not really a bug per-se, rather a feature request so I'm intentionally leaving this section blank.
### Expected behavior
Projects can contain a script file in the tree view (either a real file seating next to the .FCStd file or somewhere else on your computer, usually quite close -> pointer/reference to a location).
We can wire a small macro (or even better, automate the export on "Save" hooks !)
### Actual behavior
I have to work around this missing feature and either do the exports manually every time, or jump into the Python console.
### Development version About Info (in Safe Mode)
```shell
OS: Arch Linux (GNOME/gnome/wayland)
Architecture: x86_64
Version: 1.1.1.20260414 (Git shallow) AppImage
Build date: 2026/04/14 22:09:59
Build type: Release
Branch: (HEAD detached at 0108fd4b4)
Hash: 0108fd4b4850cc46e625b60e53cea7a7bbe69f8d
Python 3.11.14, Qt 6.8.3, Coin 4.0.3, Vtk 9.3.1, boost 1_86, Eigen3 3.4.0, PySide 6.8.3
shiboken 6.8.3, xerces-c 3.3.0, IfcOpenShell 0.8.4, OCC 7.8.1
Locale: French/France (fr_FR)
Navigation Style/Orbit Style/Rotation Mode: CAD/Trackball/Drag at cursor
Stylesheet/Theme/QtStyle: FreeCAD.qss/FreeCAD Dark/
Logical DPI/Physical DPI/Pixel Ratio: 96/92.6123/1
Installed mods:
* A2plus 0.4.64
* freecad.gears 1.3.0
```
## Note
Hi moderators/maintainers !
I could not find any template related to FeatureRequests anymore, I apologize if that's not the right place to upload such a ticket.
Contributor guide
Research direction
No files or tests are named. Start by tracing the existing macro support, Python console, and project tree handling, then examine whether save hooks are already exposed. Done means agreeing on a project-local script representation and a clear way to run it from the project context, with behavior covered by appropriate tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- desktop, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100