Skip to content

INTI-CMNB/KiAuto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

098e84c · May 19, 2020
May 18, 2020
May 19, 2020
May 19, 2020
May 19, 2020
May 18, 2020
May 5, 2020
May 8, 2020
May 3, 2020
May 19, 2020
Mar 10, 2020
Mar 10, 2020
May 13, 2020
May 18, 2020
May 11, 2020

Repository files navigation

KiCad automation scripts

Python application Coverage Status

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.

Installation

Dependencies

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.

No installation

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:

Python style installation

Just run the setup, like with any other Python tool:

sudo python3 setup.py install

Installation on Ubuntu/Debian:

Get the Debian package from the releases section and run:

sudo apt install ./kicad-automation-scripts.inti-cmnb_*_all.deb 

Usage

You can get detailed help using the --help command line option. Here I include some basic usage.

Export a schematic to PDF (or SVG)

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.

Run ERC:

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.

Generate netlist:

To generate or update the netlist, needed by other tools:

eeschema_do netlist YOUR_SCHEMATIC.sch DESTINATION/

You'll get DESTINATION/YOUR_SCHEMATIC.net

Update BoM XML/basic BoM generation:

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.

Run DRC:

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.

Export layout as PDF

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

Common options

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:

  1. Use the -vv option to get debug information
  2. 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.
  3. 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.
  4. Same as 3 but also using -m, in this case you'll get a window manager to move the windows and other stuff.

Useful references

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

About

A bunch of scripts to automate KiCad processes

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PostScript 71.6%
  • Python 23.5%
  • C 3.7%
  • Makefile 1.2%