@MitjaN yes,the replicate script does work with hierarchical schematics. The trick is whether to look for replication on the lower levels of hierarchy or the upper ones. I wish pcbnew supported properties. After I did my placement by sch script, I think I might be able to fake the properties thing by just parsing the schematics. Among other things, that would be a good place to store the desired spacings from one copy to the next. It would further make things clearer because it would also say which level is replicated. Send me a link to a testcase and I can take a look if it’s still relevant.
@hermit It appears I can’t edit my earlier posts. I don’t see the pencil icon on posts older than 40 days.
New post on zones with holes from svg
In other news, I have a new blog post. It’s about a script (and the hows behind it) that takes an svg file (only inkscape tested) and converts it to zones like this:
I tried to using the replicatelayout.py on the latest KiCad version on ubuntu (4.0.7) but it fails due to missing functions in the pcbnew.py. is there any chance to get it running on a stable release or does I have to wait for 5.0.0?
Due to work regulations it is not possible for me to work with the nightly build I’m afraid.
the error code is:
Traceback (most recent call last):
File “”, line 1, in
File “/home/tojan/workspace/github/kicad_mmccoo/replicatelayout/replicatelayout.py”, line 151, in
File “/home/tojan/workspace/github/kicad_mmccoo/replicatelayout/replicatelayout.py”, line 97, in RegisterModulesAndNets
for net in board.GetNetsByNetcode().values():
File “/usr/lib/python2.7/dist-packages/pcbnew.py”, line 4806, in getattr = lambda self, name: _swig_getattr(self, BOARD, name)
File “/usr/lib/python2.7/dist-packages/pcbnew.py”, line 83, in _swig_getattr
raise AttributeError("’%s’ object has no attribute ‘%s’" % (class_type.name, name))
AttributeError: ‘BOARD’ object has no attribute ‘GetNetsByNetcode’
As said I took a look into the pcbnew.py of the stable build and it seems like some functions and attributes you are using are missing there.
I have a new post on my kicad scripting blog. This one showcases some of the things you can do in scripting (If I were god, most of the editing functionality of pcbnew… most tools actually, would be writting in scripting languages. It would be much easier for folks to customize)
The post and the video don’t explain much about how the scripts work, but I do want to recommend a couple existing python libraries out there:
When playing around with the libraries below, remember that while they may return some cryptic data structure, you can often wrap that structure into a list(blah) call. Those structures are often/usually just a list and passing it to the list function gives you the kinds of lists you’ll fine more familiar.
The SciPy library is fantastic for graph algorithms like minimum spanning tree and delanay triangulation
The shapely library is very nice for polygon manipulation. Merging polygons, bloating and shrinking them… Designing layout is mostly geometric, so this is a nice tool to have in your pocket.
The dxf_grabber library is how I parse dxf files. Together with shapely, you can do a lot of import stuff.
This post isn’t directly about scripting in pcbnew but is likely of interest to those running linux. In recent months, it’s been difficult/impossible for some to run pcbnew scripting at all due to seg faults.
I recommend running ubuntu 16.04 with the kicad nightly build
Ubuntu 18 and Linux Mint (based on ubuntu) expose some incompatibilities between Kicad and the libraries it depends on. Notably wxPython, but also wxWidgets and gtk. it’s a version mismatch thing.
As far as I understand it, the version mismatches have always been there, but we’ve gotten away with it. Recent distros have cleaned up which versions are installed to be more correct and it’s exposed our sins.
In my experience, the kicad team does a fantastic job in keeping the nightlies functional. In fact, because the official releases as so far between, it’s quite possible that the python scripts you find for pcbnew will not work on any official release. This is often the case with my own plugins. As I develop them, I discover that something is missing from the pcbnew API. So I implement it and submit a patch.
I have a new video and some new code. This time it’s about a way to record the actions of a pcbnew plugin. It generates a file listing all of the pcbnew calls made and sourcing that file should produce the same output.
There are two use cases I had in mind.
creating regression tests. The kicad team doesn’t want your plugin code (I assume they don’t) but plugins are a great way to test whether something in pcbnew’s python has changed. So Instead of running the plugin, run a journal of a run.
Learning how someone did something. Maybe I want to do something similar to someone else’s plugin. Maybe that plugin has some sections that I just don’t understand. Perhaps the math is not relevant to what I want, maybe I’m a new programmer, a zillion reasons. I just want to know how they got pcbnew to do a thing.
The code can be found here on github:
Here’s a video demonstrating the code and how it works.
I’m not 100% sure this post will be of interest to everyone, but…
I’ve been doing a fair bit with Boost’s c++ polygon and geometry libraries. These are libraries that enable one to manipulate polygons. merge, inflate, subtract. This can be useful for things like generating copper pours, design rule checking and more.
Since they’re c++ libraries (though the shapely is a wrapper around boost::geometry), they’re not directly python scripting. But since this thread is a clearing house of my writings, I’m adding it here.
iam creating a small plugin for pcbnew…i just want to get the path of the file currently opened in pcb new.since iam using os module of python to exectute some command, i need to change the directory to that particular path of file which is opened now in kicad.