Generate gerber files from script

I’m trying to write a script that will take a board file and generate a gerber file from it.

Being new to kicad, I find myself in over my head. The only documentation I can find on scripting against kicad is here:

Are there any examples of how to generate a gerber file using python/scripts?

Can’t help, but eager to see what you come up with.

After a lot of searching, found this script which does most of what I’m looking for.

Kicad has always been able to output Gerbers; doing so is a primary required feature of a PCB layout tool. Why do you wish to reinvent the wheel, especially when this wheel is not at all trivial?

To automate creating a diff using travis-ci. A script will be run to generate two .png files, and then those png files will be compared to show differences. This must be automatic (without clicking a button in the gui) as to make it easier to project colaborators to see what changes each other is making for every commit.


OK, now I REALLY don’t get it. Consider the Gerbers to be the binaries that are spit out by a compiler. Why are they even being committed to the repo?

Comparing the schematics makes perfect sense, as they are the source code. Comparing the pcbnew files also makes sense, if it is necessary to track how routing was changed, etc.

But comparing gerbers? If you have the pcbnew file, you have more information than what’s in the gerbers, anyway (like the netlist).

Not generating gerbers, generating pdf’s and then converting to .png files. Generating a visual diff of a .png is very easy.

I found this blog post that explains exactly what I’m trying to do.

I think it is a good idea, I’ve tried comparing the schematic or pcb files as text, but even small changes can lead to a whole cascade, and it is rather worthless.

The thing that matters is the actual gerber output, so it makes sense to compare that.

Kicad team have gone to great lengths to provide scripting capability - so why the heck not use it? Or are there only certain “approved” uses??

I think you need to compare the schematics, first, for an idea whether the netlist – by which I mean the design – has changed.

If you are then concerned about changes made to the layout, you’re better off comparing the PCBnew file. Why? Because it has netlist information. You can “visually” compare two versions of the kicad_pcb file, and the output can be useful: “net Data0 changed from … to …” instead of just having a picture without knowing which nets you’re talking about.

Ok, you don’t get it. That’s fine. I’ll do it my way and you can do it your way. :slight_smile:

No, I honestly don’t get it.

I was planning to work on something similar. Do you plan to release your work open source?

When you are at the routing stage, only changes are visual. And looking at the text comparison of two different version of a .kicad_pcb file isn’t really helpful for this.

It would be great if there was tool that can correctly display/highlight changed parts of two different version of a pcb file. But easiest method is the image comparison method as this guy did: or this one: .

Yes, once I get the .png diff files generated, they will be added to a script.
You can follow the progress of the automation here:

That reminds me somewhat of the “blink comparator,” a tool used by astronomers (before the days of computers and CCD cameras) to look for differences in images. One was used to find Pluto, for instance.

I am not at all saying that a graphical comparator tool is useless. Far from it!

What I am saying is: wouldn’t it be great if you could select a trace and have the graphical-compare tool tell you the net name and display its changes? This would make the tool much more useful. “Hey, how did you re-route that LVDS pair xyz_p and xyz_n?” Click on the trace in either the new or the old image, then the same net is highlighted in the other.

To do this, you can start with the kicad_pcb file, which has all of that netlist information, plus it’s in a relatively-straightforward text format which can be parsed by any number of tools.

I have finished my solution to this problem and incorporated it in this git repo.

It is a python script that takes the current kicad file, plots it as a pdf. It then takes another git commit, and plots that version as a pdf. Both pdf files are then converted to .png files and a compare command generates a diff between them.

Here is what a final product looks like. Blue is before, red is after.

9 Likes can generate gerbers and much more from KiCad files, all fully automated (once the config file is setup).

I did not read this 5 year old thread, instead did a little search for “skidl” and it was not mentioned. If you’re interested in scripted PCB’s then I suggest you reasearch this further.