Help to improve plot/export svg of Kicad layers using python bindings

Hi guys, this is the Kicad-Diff plotpcb.py script. Right now it works on Kicad v5. But it does not work quite the same in the new Kicad v6 (>5.99). The generated image looks off-center (towards the top-left corner), sometimes it is kind of cropped. And also a circle/dot, appears on the top-left portion of the design.

This is a Kicad v5 project

This is a version of the project that was converted to Kicad v6.

I appreciate any idea on how to center the layout, scale, and change the parameters of the plotter on the new Kicad v6.

The scale difference is because your code explicitly sets different scale for different kicad versions.

The offset has probably something to do with aux origin. Either it’s in different places in 2 boards or maybe it was not correctly processed in v5.

Ah, sure. This was an attempt to fix something that was not working. Here is using the same code that I had on Kicad v5 for both designs.

So if I keep the same code for both versions. This is what I get with v6 version of the project

An empty file.

Using this for both.

    popt.SetLineWidth(pn.FromMM(0.15))
    popt.SetAutoScale(False)
    popt.SetScale(1)

Maybe the issue is the Autoscale here. Setting it to True and removing the SetScale, it still gives me an empty file

Now this popt.SetLineWidth(pn.FromMM(0.15)) helps nothing, but it was giving warning/errors some versions before, I think. Then I tried to replace it with popt.SetWidthAdjust(pn.FromMM(0.15)) but now this produces this dot

Do you know a standard way to export the whole layout sheet without the page decorations? The goal is to export the layout in the same place, always. So I can compare different versions of the layout but overlapping images.

Image is not empty, it’s tiny to the point that it’s invisible. SVG is vector format, if you give a tiny image a big line width you will see a dot, which is what second image is, I think.

Play around with the aux origin (you glanced over that part of my comment) and different scale values.

I am playing around, and on v6, only scale 1 works. having it with 1.2 moves the design out of the view.

As you can see here.

Do you know a way that I can fit it to the screen?

Autoscale does not work too.

And this was my code. Everything was removed already.

How do I change the plot regarding the (Aux) origin?

For instance, I cannot change it in the board. I have to change it while exporting since user may not have set this value.

Do you know how can I print these settings pctl.GetPlotOptions() I would like to check the current parameters/values.

This is the issue I mentioned with SetLineWidth. It was removed. Not sure if it was replaced with anything else.

Board version: 20211014
<pcbnew.PCB_PLOT_PARAMS; proxy of <Swig Object of type 'PCB_PLOT_PARAMS *' at 0x7fad2a258b40> >
Traceback (most recent call last):
  File "/home/lheck/Dropbox/Documents/kiri/submodules/KiCad-Diff/plotPCB.py", line 212, in <module>
    processBoard(board_path, plot_dir, args.quiet, args.verbose)
  File "/home/lheck/Dropbox/Documents/kiri/submodules/KiCad-Diff/plotPCB.py", line 103, in processBoard
    popt.SetLineWidth(FromMM(0.35))
  File "/usr/lib/kicad-nightly/lib/python3/dist-packages/pcbnew.py", line 7354, in <lambda>
    __getattr__ = lambda self, name: _swig_getattr(self, PCB_PLOT_PARAMS, name)
  File "/usr/lib/kicad-nightly/lib/python3/dist-packages/pcbnew.py", line 80, in _swig_getattr
    raise AttributeError("'%s' object has no attribute '%s'" % (class_type.__name__, name))
AttributeError: 'PCB_PLOT_PARAMS' object has no attribute 'SetLineWidth'

If I enable the SetPlotFrameRef, this is what I see. Something is pretty off here. There is no way to make 2 similar plots on v5 and v6. Everything I try on v6 is pretty bad. The best thing I can do is to use the scale=1 everything else gives results of the canvas

How do I find some description about what properties mean and functions do? For instance, what is this
SetPlotValue
?

And this, SetPlotReference. What it does?

Read comments here

To set aux origin
https://docs.kicad.org/doxygen-python/classpcbnew_1_1BOARD__DESIGN__SETTINGS.html#ad4ca15b7a8aaebd56a193fd252a4541d

Also try opening svg files in browser, I would trust them rendering correctly more than a random linux viewer. SVGs have a viewport header and it’s possible that either kicad or your viewer is messing it up.

1 Like

Firefox does not show the content of the SVG file when using scaling=2 on v6.
This is what Inkscape shows. the board is complete of the canvas.

And because of that it does not appear on any software that just presents the image.

When I change the scale=1.1 then this is what I have on inkscape

The same is shown on the browser. but since it does not worry about anything outside of the canvas, it just crops the image.

when the scale is 1, then everything works because it is now centered again on canvas.

Yeah, looks like kicad bugs. Both scaling and viewport are not handled correctly.
You still should be able to work around it, reset the viewport of the svg to the bounding box of the board or something like that.

Please also report these bugs if not already reported.

Hi, may I have a question here:

What’s the usage of svg ploting file?

I was always used to export PCB as PDF, and I’m confused why we need to export the PCB as svg?

SVG is a vector picture format.
It can easily be post processed, for example with Inkscape.

SVG files are also directly understood by any decent web browser (that had taken a long time) and because of this, you can use .SVG files directly on web sites, which is nice if you want to show a schematic on a website you create.

You can also use the .SVG files as a part of other documentation you want to create.

3 Likes