This was written to address some frustrations with other “artistic” PCB workflows. KiCad and other traditional ECAD software has poor support for curved lines, importing and processing of images/drawings, and many other features that can be expected in proper vector software.
Tools intended to bridge the gap are also lacking. PCBmodE is the probably the best tool out there from a pure PCB art standpoint, but there is no schematic tool, and with that, no ability to handle extremely complex, functional PCBs.
KiCad has a tool to export to SVG. SVG-To-Shenzen is a tool to convert SVG files into KiCad files. Both of these are single-direction tools.
Stretch goes both ways. Much as the ideal schematic->PCB capture workflow does not exist, the PCB layout aspect must go hand-in-hand with the art aspect.
Users can start by laying out a PCB, then bring it into Inkscape to arrange a thousand LEDs into a flower arrangement, then bring it back into KiCad to lay out traces, back into Inkscape to curve the traces, back into KiCad to change their microcontroller and few pin assignments, back into Inkscape to draw out some silkscreem patterns, back into KiCad to run DRC, and so on. The workflow is intended to be seamless and painless to go back and forth.
Give it a shot, submit issues / PRs, and do cool stuff with it. The world is your oyster.
I’ve been slowly chipping away at this for the past few months. It’s functional!
There are a few nagging issues, but (hopefully) none that are dealbreakers.
Specifically text rotations are weird, fonts are unsupported and not quite right, and traces / line segments need to automatically merge (while going to SVG) and then to automatically detect lines/curves/arcs (when going back to PCB). I even wrote a parser to convert bezier curves to their Pcbnew equivalent!
PCB->SVG->PCB conversion(and then resaving to clear up irrelevant formatting issues) results in a diff that consists only of lines being shifted around. That’s a success, no data being lost! At least with my mildly complicated test PCBs. I’m sure there are edge-cases I haven’t seen.
Due to popular demand, I’ve also changed the name.
Nice! I cloned it to my plugin directory (~/.kicad_plugins/Stretch) and installed bs4 but it won’t show up in PCBnew even after restart. Any ideas? Other plugins (RFTools, Interactive BOM, …) are working.
That is awesome! And I know the feeling of finally getting something working. Great job!
If you want some reference work on converting converting SVG paths PCBnew DRAWSEGMENTs and TRACKs, have a look at the KiCommand source code. There are functions to convert all SVG elements to an intermediate format (I call “geoms” and then to convert to either Bézier curves, circles, arcs, polygons, and (line) segments. It handles the transformation of cubic and quadratic Bézier curves to either curves or to line segments with a parameter that guides how accurate the conversion is. It handles everything but elliptical arcs. Bézier curves are super useful for fonts, which are super useful for font conversions, which KiCommand can also convert. It converts those to polygons (that was a recent multi-month effort!). There are a few shortcomings and untested parts of the code, but it is a decent framework. Some of the code is rather new, but let me know if you want any guidance around what’s in the source code now.
import Stretch
Traceback (most recent call last):
File “/usr/lib/python3.6/code.py”, line 91, in runcode
exec(code, self.locals)
File “”, line 1, in
File “/home/ekoeck/.kicad_plugins/Stretch/init.py”, line 1, in
from .stretch_plugin_action import StretchPluginAction # Note the relative import!
File “/home/ekoeck/.kicad_plugins/Stretch/stretch_plugin_action.py”, line 4, in
from svg_writer import SvgWrite
ModuleNotFoundError: No module named ‘svg_writer’
Try once more! All of my machines are Windows, unfortunately, so I’m not running into the same issues. KiCad’s scripting stuff is a little bit strange with paths.
If that doesn’t work, I’ll try to hunt down a linux/mac box and do more research.
The code is a problem for Linux which I think needs python relative imports https://realpython.com/absolute-vs-relative-python-imports/
and a problem with the hard coded file paths with back slashes such as ‘self.filename_in = currentdir + “example\complex.kicad_pcb”’
I am not enough of a programmer to offer advice about what to do but I did manage to get it working on Xubuntu 20.04 by sorting both of these problems, but probably also killed any chance of the code working on Windows.
Any chance to get your fixed version? I replaced all occurrences of the escaped backslash in (obvious) path strings. All but this one a.Run_Plugin('D:\\Projects\\git\\test\\what.kicad_pcb', 'out.svg')
in stretch_plugin_action.py since I have no idea what to do with it.
And what about this relative import issue? Since I’m not proficient in Python I have no idea what to do about that and you linked resource is not much help for me.
Unfortunately I have wiped the code now, but hopefully somebody around here with knowledge of using Python on Win & Linux will chime in and do a proper job of modifying it.
It is best to avoid direct hard-coded paths when possible. If you’re doing something temporarily, use Python’s “r” before a literal string to remove the need to escape backslashes. (It’s not needed where I put it in the line above, but I’m in the habit of using “r” for paths).