Making a good assembly drawing for hand soldering out of the KiCAD PCBNew

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

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

1 Like

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!

Here is a little more info:

head /usr/lib/python2.7/dist-packages/pcbnew.py

This file was automatically generated by SWIG (http://www.swig.org).

Version 3.0.8

First question, is the correct version of pcbnew.py?

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

1 Like

I have the same problem like Richard.

AttributeError: type object ‘object’ has no attribute ‘getattr’

I’m using LinuxMint 18 (16.04 Ubuntu) 64bit.
with the nightlybuild KiCad-Version.
deb http://ppa.launchpad.net/js-reynaud/ppa-kicad/ubuntu xenial main

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.

Ping: @ado, @kammutierspule, @Richard_Howlett

2 Likes

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

Wow this looks awesome considering it’s automated by the software.
realy why not integrate it to kicad?

And yeah sore for bringing this dead cat from the grave.

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.

seems more documentation tools would benefit from a modified SVG-Export :slight_smile:
at group-g-elements-by-netlist-in-plotted-svg
and also at proof-of-concept-web-based-svg-design-viewer
this was discussed…

Is someone here that has time to look into this :wink: :wink:
or i have to find the time to have a look at how hard it is to get into kicad modifications myself :astonished:
but this will take time… :wink:

sunny greetings stefan

For installing NumPy has anyone tried something like https://www.scipy.org/install.html ?

I took the presence of NumPy for granted, but if this gives Windows users too much of a headache we could just remove this dependency. I didn’t use it for technical reasons (like computation time or storage), I just like using NumPy for more convenient linear algebra coding.

I’m kind of astonished though that nobody talked about the elephant in the room, the dependency on matplotlib for doing the drawing :D.

The idea of putting everything in the browser is interesting of course. Instead of emitting complete graphics, just export a baseline SVG of the layout plus some overlay SVGs or even the JSONified data for creating the part highlighting via JS within the browser directly.

I personally preferred my PDF solution though because in that specific situation I wanted printed pages in front of me for assembly.

2 Likes

hi @pwuertz
I just tried your script with the nightly kicad and got the dreaded gettattr error on line 69. Would this be difficult to fix for the latest builds?

I currently don’t have a running Kicad installation, from what I read Kicad is incompatible with Ubuntu 18.04. Also I switched away from Python 2 and Kicad is still in the transition to Python 3.

But if someone is able to point out which API attribute changed I’d be happy to patch the script.

Just tried this on Ubuntu 18.04.1 with rc2 with python2 and it works perfectly
I will try with the latest nightly and see what happens

Application: kicad
Version: 5.0.0-rc2-be01b52~65~ubuntu18.04.1, release build
Libraries:
wxWidgets 3.0.4
libcurl/7.58.0 OpenSSL/1.1.0g zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Platform: Linux 4.15.0-23-generic x86_64, 64 bit, Little endian, wxGTK
Build Info:
wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 2.24
Boost: 1.65.1
OpenCASCADE Community Edition: 6.9.1
Curl: 7.58.0
Compiler: GCC 7.3.0 with C++ ABI 1011

Build settings:
USE_WX_GRAPHICS_CONTEXT=OFF
USE_WX_OVERLAY=OFF
KICAD_SCRIPTING=ON
KICAD_SCRIPTING_MODULES=ON
KICAD_SCRIPTING_WXPYTHON=OFF
KICAD_SCRIPTING_ACTION_MENU=ON
BUILD_GITHUB_PLUGIN=ON
KICAD_USE_OCE=ON
KICAD_USE_OCC=OFF
KICAD_SPICE=ON

Edit:
Latest nightly works fine

Application: kicad
Version: 5.0.0-rc3-6a2723a~65~ubuntu18.04.1, release build
Libraries:
wxWidgets 3.0.4
libcurl/7.58.0 OpenSSL/1.1.0g zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Platform: Linux 4.15.0-23-generic x86_64, 64 bit, Little endian, wxGTK
Build Info:
wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 2.24
Boost: 1.65.1
OpenCASCADE Community Edition: 6.9.1
Curl: 7.58.0
Compiler: GCC 7.3.0 with C++ ABI 1011

Build settings:
USE_WX_GRAPHICS_CONTEXT=OFF
USE_WX_OVERLAY=OFF
KICAD_SCRIPTING=ON
KICAD_SCRIPTING_MODULES=ON
KICAD_SCRIPTING_WXPYTHON=OFF
KICAD_SCRIPTING_ACTION_MENU=ON
BUILD_GITHUB_PLUGIN=ON
KICAD_USE_OCE=ON
KICAD_USE_OCC=OFF
KICAD_SPICE=ON

Indeed. I also just tried Kicad 5 from https://launchpad.net/~js-reynaud/+archive/ubuntu/kicad-5. Everything seems to be fine.

(Be aware, Matplotlib is dropping Python2 support soon)

I’ve seen the future :wink: :
https://forum.kicad.info/t/interactive-html-bom-plugin-for-kicad-5-0

1 Like

Nice.
I have this feature request https://bugs.launchpad.net/kicad/+bug/1729060
and your script appear to cover this.

Haha, I just saw this and I’m impressed :slight_smile:
That said, I already had this plugin for months before your prediction, just didn’t publish it.

1 Like