Kicad Scripting Table of Contents

This page is an effort to summarize all of the available posts in this blog. Let me know if there’s a particular topic you’d like to see covered. I’ll update this page as I go along.

GITHUB

Many/most of my posts in this blog will have associated sample code in my github. Please let me know if you find a bug.

In particular, I’d like to draw your attention to a UML diagram I’ve put together summarizing the more useful functions available in the python interface. Click for a larger image, or you can find it in the github.

Soapbox

Running a recent version

As of February 2017, the latest Kicad release is missing some important Python capabilities. My second post was about how to compile Kicad in the Ubuntu linux environment. Alternately, it also talks about getting one of the nightlies.

Basics of scripting in pcbnew

I then continue onto some of the basics. Things like iterating over net, modules and pads and getting their attributes. Location, names,…

Simple layout modifications

Now that you know how to gather information about your pcb design, you’ll want start making changes. Add a track or a via. Move a module.

More comprehensive queries

My post on the basics showed how to get some of the layout attributes. As a way to convince myself that I’m able to query a useful amount of information, I put together a script to generate an SVG file displaying the design. A writeup of it can be found here.

Multiple instances of the same sheet

If you have arrays of stuff in your design, pcbnew doesn’t really enable you to take advantage of that regularity. If you have X copies of the same subcircuit, you still have to place every module. My replicate post talks about a way to place one of the copies and then apply that placement and internal routing to the other copies. Maybe it doesn’t yield final layout, but it’s better than having all of the modules sitting on top of each other.

Manipulating more symbolic information

Most of the APIs I’ve covered so far focused on the actual layout. Modules, wires,… My post about zones and boundaries tries to go beyond that. I gather information about everything in the design and then adjust the board boundary to shrink wrap (albeit a rectangle) around it.

Adding additional modules in pcbnew

Usually, modules are introduced via netlist import. Sometimes you want to add more in pcbnew. Here’s a post on how to add mounting holes via a python script.

Zoom, Pan, Refresh

When manipulating your layout from python, you’ll want a way to refresh the display; to trigger a redraw. Additionally, you may want to zoom into the change2. Here’s how.

Copy Sch Placement to Layout

When importing a netlist into pcbnew, the initial placement looks random. I have a script that moves you devices in layout to match the placement in the schematics. Here more

Over time, I expect I’ll start covering some of the C++ code as well. I’ve had to spend a lot of time with it basically reverse engineering it to learn how to get the scripting interface to do what I want.↩