A bunch of scripts to automate KiCad processes using UI automation with xdotool.
This is a fork of Productize SPRL's scripts, based in big parts on Scott Bezek's scripts in his split-flap display project. For more info see his [excellent blog posts][scot's blog].
Currently tested and working:
- Exporting schematics to PDF, SVG, PS, DXF and HPGL
- Exporting layouts to PDF
- Running ERC on schematics
- Running DRC on layouts
- Netlist generation
- Basic BoM generation (mainly the XML needed for KiBoM)
If you are looking for Gerbers, Drill and Position take a look at KiPlot.
If you are looking for STEP files creation take a look at kicad2step, part of KiCad.
If you are installing from a Debian package you don't need to worry about dependencies, otherwise you need to install:
If you want to debug problems you could also need:
- recordmydesktop, to create a video of the KiCad session.
- x11vnc and a client like ssvnc, to see the KiCad live interaction.
- fluxbox and wmctrl if you want to have a window manager when using x11vnc. Othewise windows can't be moved.
You can use the scripts without installing. The scripts are located at the src/ directory.
You can also define a bash aliases:
alias pcbnew_do=PATH_TO_REPO/src/pcbnew_do
alias eeschema_do=PATH_TO_REPO/src/eeschema_do
Note that the following Python 3 packages must be installed:
Just run the setup, like with any other Python tool:
sudo python3 setup.py install
Get the Debian package from the releases section and run:
sudo apt install ./kicad-automation-scripts.inti-cmnb_*_all.deb
You can get detailed help using the --help command line option. Here I include some basic usage.
eeschema_do export -a YOUR_SCHEMATIC.sch DESTINATION/
This will create DESTINATION/YOUR_SCHEMATIC.pdf file containing all the schematic pages. If you want just one page remove the -a option. If you want an SVG file just use -f svg like this:
eeschema_do export -a -f svg YOUR_SCHEMATIC.sch DESTINATION/
In this case you'll get one SVG for each page in your schematic.
To run the Electrical Rules Check:
eeschema_do run_erc YOUR_SCHEMATIC.sch DESTINATION/
If an error is detected you'll get a message and the script will return a negative error level. Additionally you'll get DESTINATION/YOUR_SCHEMATIC.erc containing KiCad's report.
To generate or update the netlist, needed by other tools:
eeschema_do netlist YOUR_SCHEMATIC.sch DESTINATION/
You'll get DESTINATION/YOUR_SCHEMATIC.net
Tools like KiBoM can generate a nice BoM, but in order to run them from the command line you need to be sure that the project's XML BoM is updated. You can do it running:
eeschema_do bom_xml YOUR_SCHEMATIC.sch DESTINATION/
After running it ./YOUR_SCHEMATIC.xml will be updated. You'll also get DESTINATION/YOUR_SCHEMATIC.csv contain a very basic BoM generated using KiCad's bom2grouped_csv.xsl template.
To run the Distance Rules Check:
pcbnew_do run_drc YOUR_PCB.kicad_pcb DESTINATION/
If an error is detected you'll get a message and the script will return a negative error level. Additionally you'll get DESTINATION/drc_result.rpt containing KiCad's report. You can select the name of the report using --output_name and you can ignore unconneted nets using --ignore_unconnected.
This is useful to complement your gerber files including some extra information in the Dwgs.User or Cmts.User layer.
pcbnew_do export YOUR_PCB.kicad_pcb DESTINATION/ LAYER1 LAYER2
Will generate DESTINATION/printed.pdf containing LAYER1 and LAYER2 overlapped. You can list as many layers as you want. I use things like F.Cu Dwgs.User
. The name of the layers is the same you see in the GUI, if your first inner layer is GND you just need to use GND.Cu
.
If you need to get a list of valid layers run:
pcbnew_do export --list YOUR_PCB.kicad_pcb
By default all the scripts run very quiet. If you want to get some information about what's going on use -v.
The nature of these scripts make them very fragile. In particular when you run them in your every day desktop. You must avoid having eeschema and/or pcbnew windows opened while running the scripts. If you need to debug a problem you can:
- Use the -vv option to get debug information
- Use the -r option to record a video (OGV format) containing the GUI session. The file will be stored in the output directory and its name will begin with the name of the requested command.
- Use the -s and -w options to start x11vnc. The execution will stop asking for a keypress. At this time you can start a VNC client like this:
ssvncviewer :0
. You'll be able to see KiCad running and also interact with it. - Same as 3 but also using -m, in this case you'll get a window manager to move the windows and other stuff.
split-flap: https://github.com/scottbez1/splitflap
scot's blog: https://scottbezek.blogspot.be/2016/04/scripting-kicad-pcbnew-exports.html
Dockerhub: https://hub.docker.com/repository/docker/setsoft/kicad_auto