Short version: Is there any way how to export footprint as image from a script?
Long version: I’ve mismatched a footprint and had to do a lot of wiring to fix the PCB. So I was thinking about creating a script, that would export all used footprints in a PCB as images and I would go through them one by one to verify that they are ok.
I was thinking about grouping the same footprints, and maybe some sort of “verified” field in eeschema. For example the footprint and selected eeschema fields would be hashed and you would need to enter the hash into another eeschema field to mark the footprint as verified… But first I would need to export the footprints in a format that would be useful to check it.
And print it probably twice: 1:1 and scaled with some sort of measure alongside it. So I could open the datasheet or take the physical part and confirm that it is a match.
I did look into it however I was not able to find some detailed documentation. It looks great however it seems to export only a footprint from a library:
this is what I would need however I would like to use footprints from PCB. And according to (a very brief) help message there is no way to specify project/PCB file and export a single (or all) footprints. The thing is that someone could edit the footprint in the PCB - which I would discourage but that is one thing that this script should show…
So as far I understand it now I have two ways how to do it:
use python to copy every footprint from PCB to new temporary board file and plot it
use python or some KiCad files parsing to extract footprints into temporary library and export it.
That is why I did ask in the forums to see if I am not missing anything obvious.
but it did not do anything. I also do not understand why it is function of pcbnew class and not of board class.
I will try to look at it more as it seems that this function in combination with kicad-cli fp export svg could be the way…
You are not missing anything. But it’s fairly simple to write a script to export footprints one by one either into a lib or into a pcb.
Probably because it’s implemented as window method and not board method and needs a valid pcbnew window. It probably won’t help you with automating your export if that’s the case.
Try running it from kicad scripting console instead of standalone python script.
Great to hear. Can you point me in the right direction? I was not able to find a python object for a library. I have a code that traverses through all the footprints, prints their details, etc… but I have not found any class for footprint library.
Thanks, they seem to work. They are a little bit cumbersome and the documentation says nothing on how to use them but I managed to get it working by trial and error
Here is the proof-of-conecpt version of the code if someone is interested
board = pcbnew.LoadBoard(project_file)
libname='testlib'
pcbnew.FootprintLibCreate(libname)
for footprint in board.GetFootprints():
ref=footprint.GetReference()
footprint.SetFPIDAsString(ref)
footprint.SetReference("**REF")
pcbnew.FootprintSave(libname,footprint)
And just for reference, the FootprintLibCreate fails with I/O error if the directory testlib already exists…