Gerber to kicad_mod

Hi there,

I am trying to design a pcb which includes an RF part designed with an external software (CST for the antenna and ADS for the distributed part).
What I would like to do is to import different parts using a gerber into different footprints, p.e. a footprint for the antenna, a footprint for the matching network and so on.
I did not find any good way to make this systematically, hence that could be integrated into a workflow.
I will try to list the possible ways that I found.

  1. Gerber [or whatever] to pdf or svg -> open that with Inkscape -> Change alpha channel to 255 (File -> Document Properties -> Background Color)-> export as bmp -> open it with bitmap2component -> export as kicad_mod -> substitute layer F.SilkS with F.Cu or B.Cu -> Open it with PCB footprint editor -> …
    But I don’t find this workflow good enough, because the conversion from vectorial -> raster -> vectorial loses some resolution.

  2. Gerber -> open that with GerbView -> export to PcbNew -> ???
    The problem is that I don’t know how to convert the kicad_pcb to kicad_mod.
    I tried by copying the segments by opening it as text, but I get a parsing error.
    The questions are:

    • Is the S expressions for kicad_mod different from kicad_pcb?
    • Where can I find a resource for both syntax?
    • Is there a tool for the conversion between both, even in python, or python module, or as a script?

As a quite separate question, is there a resource on python scripting in kicad and/on by using some dedicated module in a (standalone) python interpreter?

Thanks

1 Like

I think that gerbview can only view files in gerber format, it does not allow any conversion.

Converting gerber to a kicad_mod via an external script is a possibility though. The best guide I have found for kicad_mod files is https://www.compuphase.com/electronics/LibraryFileFormats.pdf

Do you have some sample gerber files of the RF parts that you could post?

Also, can you export as DXF? That might be easier to import.

You can generate PCB from loaded Gerber layers via GerbView, but the result might be useless.

Actually, GerbView can export to kicad_pcb, but not to kicad_mod.
My issue is converting from kicad_pcb to kicad_mod.

Any Gerber would be fine for the purpose, but if you need one random gerber I can upload it (not the RF one, which is still not ready, but the process should be the same).

The workflow I am using in based on 1. [in my question] and using a 2400dpi png, but this is not optimal.

Oh I didn’t realise that was possible, it is quite neat!

To convert the kicad_pcb file to a kicad_mod, the segment lines can be converted to fp_line

  • change the keyword segment to fp_line
  • remove “(net x)”
  • adjust the coords for desired offset?

You then just need to insert the fp_lines into a module template e.g.

(module Antenna
(layer F.Cu)
(at 0.000000 0.000000 0.000000)
(descr “my antenna”)
(fp_line
(start -4.150000 5.781700)
(end -4.150000 5.018300)
(layer Dwgs.User)
(width 0.000000)
)
<<< etc >>>
)

Most of that can be done with a text editor, you could perhaps adjust coords if necessary using pcbnew.

2 Likes

Great!
The fp_line part is working, but i have issues with vias:

 (via (at 72.39 78.73999999999999) (size 1.3) (layers F.Cu B.Cu))

Then I can try to setup a regex for some substitutions…

I guess that a via translates to a through_hole pad ?

(pad 1 thru_hole circle
(at -11.430000 1.270000 0.000000)
(size 1.524000 1.524000)
(drill 1.016000)
(layers *.Cu B.Mask F.Mask)
)

You’ll need to add the drill size, and add width field to the size parameter. I would number the pads according to the net.

1 Like

Uhm, ok.
Some manual refinement is needed, it is difficult to get everything creating a script.
The vias are quite used when designing microstrip lines, in order to get shorted stubs and so on, but these does not need to be numbered pads, so maybe some "fp_circle"s on all copper layers are ok.
The discrete smd components needs square pads, so maybe some “fp_lines” with the right size are ok.
Then the ports can be directly inserted from the footprint editor or by adding “pad” (as you did) in the right place, but this second method is an overkill for me, I can add them manually in the editor.

Hence some manual editing is not easy to be avoided, but it would be easier with official complete documentations.
I guess you don’t have the kicad_pcb S-expression specification, but only for the kicad_mod (unofficial, in the link you provided and that I downloaded). I tried to search for the first, but I can not find it anywhere.

Maybe the procedure using bitmap is still easier and probably with the same final result.

There is some more detail on s-expressions in this doc http://bazaar.launchpad.net/~stambaughw/kicad/doc-read-only/download/head:/1115%4016bec504-3128-0410-b3e8-8e38c2123bca:trunk%2Fkicad-doc%2Fdoc%2Fhelp%2Ffile_formats%2Ffile_formats.pdf/file_formats.pdf

Thank for your help!

The vias should be numbered pads (all the same number if necessary) and ideally should connected to a net somehow.

Don’t you need a plated through hole? if you only have circles you don’t get that.
You could use “~” as pad number. This is used for pads that should not be connected to anything. (mounting holes, …)
Because your connections are done with lines this could work.

1 Like

Don’t you need a plated through hole? if you only have circles you don’t get that.

Well, yes, of course. The via is used for electrical connections between layers. The fp_circles is missing that point. Good spot!

You could use “~” as pad number. This is used for pads that should not be connected to anything. (mounting holes, …)

Great, i did not know about using “~” as pad number.
Where is this documented?

Because your connections are done with lines this could work.

I am wondering why the allowed expression in the footprint is a subset of the one in the schematic.

First of all, you can add or subtract features from the gerber within the gEDA project gerbv viewer.

Once you have the features you want in a gerber file, you can try running it through

which can create a gEDA PCB/pcb-rnd compatible footprint from a gerber, i.e. as shown here

which you can then import into kicad.

IIRC, the converter doesn’t deal with arcs, but kicad doesn’t routinely support arcs on copper anyway. Flashed apertures like pads may not be converted either due to the lack of detail in a gerber file as to the function or purpose of a specific feature.

Gerbers with painted features, i.e. from Eagle, are quite bulky and less useful once converted.

If you must have a .mod file, another way to go about it is to convert the entire gerber to a gEDA PCB/pcb-rnd footprint, and load it into a new layout in pcb-rnd (available at http://repo.hu/projects/pcb-rnd/ or as a debian/ubuntu package). In there, the footprint element can be broken up into constituents, and the useful bits retained. These can then be cut into the paste buffer, converted to an element, and pasted back onto the layout. The layout can then be exported in kicad format, and the bespoke footprint you have just created will be exported in the kicad layout as a module,

May the g-code be with you!

1 Like

Does the CST software have a DXF option?

One possibility might be gerber-to-svg and then svg2mod but there is a lot of potential for things to go wrong with multiple steps. I know that gerber-to-svg generates a lot of <use> tags and I am not sure svg2mod even supports those.

Yes, can you create a footprint using that DXF?
I have some issue with the DXF import.

The svg2mod gives me some issues because it uses a strange svg module, which I can not find inside the anaconda distribution of python.

The svg module is included in the source of svg2mod. Are you experiencing this issue?

No, I was supposing it was included in python, hence I did not clone the repo but just download the svg2mod script.
Now, after cloning the repo and with python 3.6, I get some errors:

Warning: Path segment has only 2 points (not a polygon?)
    Writing polygon with 3 points
Unsupported SVG element: Circle