I’m working on a project that requires multiple versions of the same board with different outlines. I would like to automate board generation with KiCad.
My understanding:
The old SWIG API is deprecated in current KiCad 9 and should not be used any more.
Instead, the new IPC API should be used.
However I am unsure which steps of my project are actually possible to implement with the new API.
Open existing/create new board → New API seems to only support working on already opened board preventing any full-auto workflow.
Build a donut shaped outline from two given radiuses → Should be possible but cannot figure out how from docs/code.
Draw a polygon on top and bottom connected to ground net → Example exists for drawing polygon but unclear how to set net for this polygon.
Insert two footprints at given location/rotation → Example exists.
Export the PCB as .dsn file → No hint in API docs how to achieve this.
(Autoroute the file with freerouting)
Import a .ses file → No hint in API docs how to achieve this.
I would appreciate feedback on how to implement the steps that are currently unclear and any general info on the plan with the new API which seems to currently only support a very limited subset of the functionality of the legacy API.
Select it, expand selection (with u) to select it all.
Edit the selection and give it a name.
Move it to one of the User.1 through User.9 layers.
Repeat for the other outlines.
Just make sure you never have more then one outline on the Edge.Cuts layer.
Similarly, you can create a .SVG or .DXF file for each outline, put all those files in a directory, and then import the one you need for a specific set of gerbers.
Both of these methods can probably be automated a bit with Python, but drawing the whole Edge.Cuts in Python seems a bit cumbersome.
This snippet in the documentation made me believe it is not possible:
There is no support for running KiCad in a headless mode, and unlike the SWIG-based Python bindings, the IPC API does not provide an independent way to load and process KiCad PCB files outside of the KiCad editor.
If you know how to create/load a board via the new API I would greatly appreciate any hint
Thanks, but I would really like to draw the outlines automatically. One reason is that the outlines are determined by mechanical constraints that exist also in our mechanical model. If we change the mechanical constraints I would need to redraw all boards manually, hence I’m looking for an automated solution that just does everything in a CI/CD workflow.
The intention is quite the opposite. If you’ve already got a mechanical enclosure, you can extract the PCB outline from it, export it, and import it in KiCad. You can do this with any mechanical CAD program that can export to one of the file formats KiCad can read (SVG & DXF), or a more direct approach with for example the KiCad-Stepup workbench in FreeCAD.
Drawing a complex outline in KiCad itself is quite cumbersome, and then doing it only with Python from within KiCad sounds like a horror story to me.
On a sidenote. If you want to take the scripted approach, you may want to have a look at the footprint wizards in KiCad. Those are python scripts that generate pads, silkscreen, courtyard and other graphical items.