Stretch - Seamless Integration with Inkscape, back-and-forth

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’

I did pip install SvgWrite but the error stays the same.

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.

1 Like

Always use os.path.join() to combine any directory and file names into a path.

1 Like

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.

a.Run_Plugin(pcbnew.GetBoard().GetFileName(), r’out.svg’) 

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

.

Appreciate the debugging/testing help :slight_smile:

Pushed a fix for the path joining.

Thanks for you commitment :wink: I’d really would use this tool (RF design, complex shapes due to mechanical integration) but it still doesn’t work for me, same error as before :frowning:

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
File “/home/ekoeck/.kicad_plugins/Stretch/svg_writer.py”, line 7, in
from parser_base import ParserBase
ModuleNotFoundError: No module named ‘parser_base’

You may be interested in kicad StepUp footprint design

1 Like

Yes, I use SketchUp for different tasks but since I need to fine tune the layout after simulations so the more or less seamless integration with Inkscape looks very promising to me.

1 Like

Ok, now I get different messages:

import Stretch
Traceback (most recent call last):
File “/home/ekoeck/.kicad_plugins/Stretch/svg_writer.py”, line 11, in
from .sexpressions_writer import SexpressionWriter
File “/home/ekoeck/.kicad_plugins/Stretch/sexpressions_writer.py”, line 6, in
from parser_base import ParserBase
ModuleNotFoundError: No module named ‘parser_base’

During handling of the above exception, another exception occurred:

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
File “/home/ekoeck/.kicad_plugins/Stretch/svg_writer.py”, line 13, in
from parser_base import ParserBase
ModuleNotFoundError: No module named ‘parser_base’

I gave it a try today on Win10 and KiCAD v5.1.6, the installation worked flawlessly, the exporting to SVG also (I opened the board in Inkscape and modify a track), saved the changes and try to reimport in KiCAD, but that didn’t work, I get the following error.

Any suggestions?

1 Like

Bear in mind what I said, I know zilch about python code but I do some other coding with embedded microprocessors.

Try going through all the *.py files in the Stretch directory, and where there is an import line that references another python module in the Stretch directory, so as an example, in your post above No Module named ‘parser_base’ references the file parser_base.py, change the import line to

from .parser_base import ParserBase
Note the dot in front of parser

You will need to do this for any line that imports from another *.py file in the Stretch directory but only for these imports, not the ones that import python functions.

Rereading the above now looks like total gibberish but try it and see what happens.

I got this working a few days ago but now I can’t get the modified svg file to import back into kicad again and I also have two sets of Stretch icons in the kicad toolbar.

Jarret is working on it (we have a parallel private conversation) and the plugin gets loaded correctly in KiCAD with the latest commit, but export/import is not working with the boards I tested. So still work in progress but we will get there :smiley:

Yep, installation issues seem to be better, now it’s all about finding new edge-cases in PCB files that I haven’t seen yet.

Taking a bit of a break from this, but then I’ll be plugging away at stuff next week. Sending links to PCBs that break it would be appreciated!

EDIT: Figured it out! KiCad won’t display the curve but you can convert the curve into segments in Inkscape: Select a curved path then use “Extensions -> Modify Path -> Flatten Beziers” with a really low value like ~0.3 or ~0.5 (lower = more segments)

Thanks for the plugin, it looks promising!

What version(s) of KiCad render the curved lines in pcbnew?

Steps Taken:
Installed stretch and bs4 python module
Created a PCB
Clicked the “Up Arrow” to export to out.svg
Opened out.svg in inkscape (latest release)
Tried a variety of modifications: Nudged a few things around with the “Edit Paths by Nodes” tool, copied some traces, deleted a couple footprints
Saved out.svg
Clicked the “down arrow”
Closed pcbnew w/out saving
Re-opened pcb.

None of the curves render, they’re just straight lines with the expected endpoint but no curves
Deleted footprints are missing and I can see the extra copied/pasted lines.

Am I doing something wrong? (Edit: See top of post)

I’ve tried it on Windows with the latest nightly as well as the 5.1.6 release build

Thanks!

2 Likes

This works, but for some object types (“lines”, but not “segments”), KiCad will render beziers properly. In the future, this plugin will be able to autodetect when you convert lines to beziers, but in the meantime:

  • In Inkscape, open up the XML Editor (ctrl-shift-X)
  • Click on the desired line in the main window
  • You’ll see that object in the XML window. There will be a type field that says either fp_line or gr_line.
  • Change that to fp_curve or gr_curve

Bit of a hack atm, but does allow you to later go back to SVG without having to deal with tons of straight line segments.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.