Gerber to kicad_mod

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

Right, you have to convert everything to path elements. You can use Inkscape for that.

Use Inkscape’s “Path->Object To Path” and “Path->Stroke To Path”
menu options to convert these elements into paths that will work.

Sometimes there are further challenges in converting to path:

I tried that, but I still get:

Warning: Path segment has only 2 points (not a polygon?)
    Writing polygon with 1 points

The footprint looks bad, with very thin lines and without the pads.

That’s just a warning. But yeah, if the result is no good then you might be out of luck. It could be a lot of work to make this method give good results.

1 Like

I am trying with this perl one liner and seems to be able to convert from kicad_pcb exported from GerbView to kicad_mod:

perl -pe 's/(\s*)\(segment(.*)\s\(net\s0\)/\1(fp_line\2/g; s/(\s)\(via(.*)\(size\s([0-9.]+)\)\s(.*)/\1(pad ~ thru_hole circle\2(size \3 \3 )(drill 0.6) \4/g; s/\s*\((?:kicad_pcb|(?:layers\s\W)|\d).*//g;  s/^\s*(?:\))?\r?\n//g; eof && do{chomp; print "$_)"; exit}; print qq{(module ModuleName\n(layer F.Cu)\n(at 0.000000 0.000000 0.000000)\n(descr "Module Description")\n$_} if $. == 1;' RF.kicad_pcb > RF.kicad_mod
1 Like

Sorry, this message won’t be useful. Just expressing a little frustration that one has to jump through so many hoops to get this working. Implementing import of simple shapes, or shapes designed somewhere else (printed antenna in CST, or transmission line transitions and some sort of RF filters) should not be that painful.
I’m glad the community is able to figure it out in the end!

There’s this now too:

This script is for use from within inkscape and thereby lets inkscape do the conversion of paths for export to line segments, unlike svg2mod, which is standalone and uses its own library.

This script converts 1px to 1 mil.

Summary, it is subtly different in terms of results vs svg2mod, and does not expect to be given polygons. It simply converts paths, and doesn’t try to do anything clever such as allocating distinct layers in the exported footprint.

One of the scripts will export gEDA pcb .fp format, which Kicad can load directly.

Cheers,

Erich.

1 Like