A long time ago I wrote a script for making color-coded hand assembly drawings (see attached PDFfreewatch_assy.pdf (205.3 KB) ) from Gerber/BOM files produced by Kicad.
Hi, Tom!
The drawing that goes out of your script is wonderful!
But I didn’t get the idea how to implement it. Is is definitely written in Python (as it has .py extension). But I don’t know this language and don’t know how to execute one.
Is there any additional recommendations?
@Roman_Matveev Kicad can export to lots of formats types the gerbers. I did something similar I exported to SVG and then I edit it with Inkscape and draw the things as I want.
Tom! I downloaded and installed Python for Windows from its official website, version 3.5.
So now I can run you script (BTW: which script will do the job - assygen.py or gerber2pdf.py?) but the window opened for a second or so and then disappeared. But it was pretty expected as I did not feed the gerbers to it.
Could you explain how to use your scripts?
What we usually do is plot the silkscreen and the board edge as SVG, resize it, and save it as PDF.
Certainly not as good as the script above, but decent enough if your footprints have the reference and the component orientation in the silkscreen.
Just came up with this version to get greyscale board overviews for hand-assembly.
What I really miss now is the option to have a Top and Bottom user layer, where I could put the REF** value on. Currently it resides on Eco1, but this doesn’t work as Top/Bottom and I get both layers REF values on the printout…
Or the footprints would need to allow me to set the layer assignment for REF/VAL to more than one layer… that would work too…
Hmm, I haven’t run the scripts, but looking at it I would guess you need to do the following:
Generate a pick and place file from kicad. Make sure its filename is exactly the same as the KiCad gerbers you made (so if the gerbers are ProjectBunny.GBO, ProjectBunny.GTL, etc the pick and place data should be ProjectBunny.csv)
Open a terminal and run the program and as the argument give it the project name (e.g. ProjectName) and it should spit out a pdf with that same project name. e.g. python assygen.py ProjectBunny
from gerber2pdf import *
File “/home/jean/Télechargements/assygen-master/kicad-test/gerber2pdf.py”, line 304, in
class GerberScanner(Scanner):
NameError: name ‘Scanner’ is not defined
I read the code/documentation to determine: the name ‘Scanner’ probably should be defined by the ‘plex’ python module, which is imported earlier in gerber2pdf.py. So maybe there is a problem with your plex module, which you probably downloaded. The import of plex apparently succeeded, so maybe it is a name clash, where another module named plex exists? You could hack the code near the ‘import plex’ statement to determine more information.
Hi!
Recently I was looking for that kind of tool as well. Joan_Sparky also pointed me at this post and in the end started writing a small python script for plotting assembly drawings. It uses the KiCad API to read the pcb file and draws pick and place maps with matplotlib.
The python code for the Pick and Place Assistant is uploaded as GitHub Gist if anyone is still interested. Some plotting capabilities and optimizations are missing but it does the job for now. Feel free to pick it up for own use, extend/modify it, etc.
Impressive screenshot results. Could you just write some guidelines how to use your script?
I am a linux user and install KiCAD from sources.
Lets assume I don’t know what python is, how can I make it work magically?
It has a command line interface, so just run it with python or make it executable and call it directly. The first argument should be the kicad pcb file. pyhton script.py board.kicad_pcb or ./script.py board.kicad_pcb
It requires the matplotlib and kicad libraries for python. If your KiCad from source installation took care of putting the python modules at the right place you should be good to go (if matplotlib is installed too).
Nice tool, I wrote one based on the old BRD file format and found this in my quest to do less code writing and more designing. First, Python is not my forte. I’ve written some things in it, but cant say I’m very good at it. That being said, I’m running this in Linux (Ubuntu 16.04), I think all the libs are installed but I get the following errors when I run the code on a simple board a made last week.
kicad_picknplace_assistant.py PiCAN360.kicad_pcb
Loading PiCAN360.kicad_pcb
Traceback (most recent call last):
File “/home/rhowlett/Dropbox/bin/kicad_scripts/kicad_picknplace_assistant.py”, line 158, in
bom_table = generate_bom(pcb, filter_layer=pcbnew.F_Cu)
File “/home/rhowlett/Dropbox/bin/kicad_scripts/kicad_picknplace_assistant.py”, line 127, in generate_bom
group_key = (m.GetValue(), str(m.GetFPID().GetFootprintName()))
File “/usr/lib/python2.7/dist-packages/pcbnew.py”, line 4023, in getattr = lambda self, name: _swig_getattr(self, LIB_ID, name)
File “/usr/lib/python2.7/dist-packages/pcbnew.py”, line 74, in _swig_getattr
return _swig_getattr_nondynamic(self, class_type, name, 0)
File “/usr/lib/python2.7/dist-packages/pcbnew.py”, line 69, in _swig_getattr_nondynamic
return object.getattr(self, name)
AttributeError: type object ‘object’ has no attribute ‘getattr’
I’m a little lost on what its barffing on sinceAny help would be great!
The version number from the pcbnew.py header belongs to SWIG, I can’t find the real KiCad version number in this file. My guess is that you are using different/older KiCad bindings. I wrote/tested this script using Ubuntu and the KiCad PPA (KiCad 4.0.4).
Is there a soluton for using this great tool ?
The pcbnew.py file in usr/lib/python2.7/dist-packages/ is replaced by every nightly build.
And it’s the only file with this name on my system.
Loading board.kicad_pcb
Traceback (most recent call last):
File “kicad_picknplace_assistant.py”, line 166, in
bom_table = generate_bom(pcb, filter_layer=pcbnew.F_Cu)
File “kicad_picknplace_assistant.py”, line 135, in generate_bom
group_key = (m.GetValue(), str(m.GetFPID().GetFootprintName()))
File “/usr/lib/python2.7/dist-packages/pcbnew.py”, line 4357, in getattr = lambda self, name: _swig_getattr(self, LIB_ID, name)
File “/usr/lib/python2.7/dist-packages/pcbnew.py”, line 74, in _swig_getattr
return _swig_getattr_nondynamic(self, class_type, name, 0)
File “/usr/lib/python2.7/dist-packages/pcbnew.py”, line 69, in _swig_getattr_nondynamic
return object.getattr(self, name)
AttributeError: type object ‘object’ has no attribute ‘getattr’
The problem you are seeing is caused by an API change in the KiCad development branch, while the script was developed using the latest KiCad stable release.
I just switched to the nightly PPA release too and adapted the Pick and Place script. It should work with KiCad 4 and the current development branch alike. If you want you can give it another try, just go to the linked github gist from above and fetch the updated revision.
It’s working with the nightly build.
I get messages of “Unsupported pad shape” because i use some rounded pads.
Shape 3 and 4 are not implemented in the python script, I saw,
but the areas of the parts are marked good enough to be happy.
It would be great if in the far, far future rounded pads are supported too.
And none rectagle pcb-outline-forms are displayed with roundings and so on.
Thank you so much for this great useful script.
It should be inbuild in next stable Kicad release.
I’ve been playing with the script so I can use it as part of my documentation flow. I’ve added a few extras like location of pin 1 on footprints and putting an outline on each part. However, the outline is using the GetSize and that doesn’t work very well for 45 degree rotated parts and mounting holes with other parts within that envelope. I can’t find a simple way to draw one of the layers like T_SilkS. I’ve been using the http://docs.kicad.org/doxygen-python for documentation. Is there better documentation to describe some of the functions? Also, navigation in doxygen is killing me. Trying to hunt down what variables are valid with most of the functions it painful. (ok, I’m just venting a little). Anyway, I was thinking about taking a slightly different approach. I think I could generate and SVG or PDF in a separate file using the PLOT functions, then overlay the pads and info on that SVG or PDF image at the end of each page generation. Unfortunately, I don’t use python that much so there is a steep learning curve, but I’m sure it would work. Has anyone looked at doing it this way? I’m sure I’m not realizing a reason it will not work:)
Installing NumPy is problematic in KiCad python because a “normal” install of NumPy requires compilation. Users would have to set up the ability to compile C++ I.e. using mingw). There are pre -compiled versions of NumPy that are supposed to work, but I have been unable to get them installed on Windows.
I’d love for NumPy to be installed with KiCad python by default for DRC purposes (see KiPadCheck).
This tool might be able to be refactored for use with hand-written SVG overlay output so that additional python libraries are not needed.