Generate gerber files from script


#1

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:

http://ci.kicad-pcb.org/job/kicad-doxygen/ws/build/pcbnew/doxygen-python/html/classpcbnew_1_1GERBER__PLOTTER.html

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


Plot scripting/API - color choice for layers?
#2

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


Plot scripting/API - color choice for layers?
#3

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

http://github.com/blairbonnett-mirrors/kicad/blob/master/demos/python_scripts_examples/plot_board.py


#4

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?


#5

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.


#6

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).


#7

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.

http://www.evilmadscientist.com/2011/improving-open-source-hardware-visual-diffs/


#8

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??


#9

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.


#10

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


#11

No, I honestly don’t get it.


#12

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


#13

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: http://www.evilmadscientist.com/2011/improving-open-source-hardware-visual-diffs/ or this one: https://github.com/hurik/JGeagle .


Creating a diff tool for kicad pcb
#14

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:


#15

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.


Creating a diff tool for kicad pcb
#16

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.