Custom footprints scripting using custom shape primitives

I was wondering if there was a python script to make custom shapes in footprint using custom shape primitives.

To give some context, let’s say I would like to generate a pcb coil and generate a footprint with it. I generally use the bitmap to component and then manually edit the text file to move it to a different layer but this makes them invisible to the DRC and requires keep out zones or additional manual intervention.
The best of the bests would be to have a script converting a gerber or svg to custom shapes in footprint. This would make designing RF pcbs a fun job.
Writing the custom shape primitives by hand is a bit tedious.

When I saw the great plugin made by @maui I wondered if this was possible or already made.

Yes: https://github.com/pointhi/kicad-footprint-generator

Extensively used for generating footprints for the official lib.


Note: this is a standalone library not intended to be used as a kicad internal script.

2 Likes

If your design starts with i.e a dxf, you may also have a look at StepUp for (RF) footprint generation.
It is a manual process, but gives you a DRC safe footprint.

1 Like

@Rene_Poschl Thanks, that can be very useful for scripting.

@maui That’s exactly what I was searching for! Amazing! It is funny that I always use the KicadStepUp but I am still unaware of its full awesomeness…

1 Like

Do you have an example with a conversion of a logo to footprint’s copper zones?
For example when the svg is imported and results in BSplines (filled inside as if the sketch was padded in freecad)
I try to attach a freecad example logo.FCStd (7.2 KB)

you need to convert the Sketch from Bspline to arcs and lines (because kicad doesn’t support bspline for Geometry pads), and then use it as a Pads_Poly pad (you can find an example in the StepUp FC Demo menu).
logo-fp.FCStd (43.1 KB)
fp-logo.kicad_mod (8.8 KB)

There is a specific button in StepUp to do it for you:

1 Like

For logos you can also use https://github.com/badgeek/svg2shenzhen (you can use any vector format as input that is supported by inkscape and it exports your logo as a kicad footprint)

That’s great! Thanks a lot

Yes, I tried it before but it was not properly working into Inkscape and then I decided to do it using the bitmaptocomponent. I don’t know if it would be DRC compliant either.

Unfortunately not … svg2shenzhen is not DRC complaint because it is using poly-lines and not primitive pads.
It is aimed to full artwork freedom.
StepUp is instead aimed to make footprint for pcb routing and will generate DRC complaint footprints.

1 Like

Last question: I tried to look into the demos but I was not able (probably my abilities as a truffle dog are not very good) to find a doc file that defined the keyword and their meaning and characteristics/requirements.
For example, F_Silks_0.16, Pads_Poly_Arc, Pads_Poly, …
Is there any such file?

Last last question: I see there is always a circle inside the Pads_Poly. Is that required?

Thanks again!

Yes. It defines the anchor pad (requirement by the kicad file format)

2 Likes

The only doc on creating footprint ATM is this file inside the demo Menu: Generating-a-KiCAD-footprint-and-Model-from-3D-Step-Data.pdf
This doc was added by an user and that was very welcomed…

Labels have some locked names to get parsed by the script…
The demo file complex-Polyline-footprint.FCStd is one of the most complex to be used as sample…
footprint-labels
F_Fab, FSilks, F_CrtYd have their size embedded in the label… i.e. F_Silks_0.16 means a F.SilkS draw with 0.16 mm in size.

2 Likes

I see you pain, writing docs is always a big effort, sometimes even bigger than writing the tool itself. The only fun is to use LaTeX with tikz! :rofl:

Could you please point me to the part in the python code where those label are defined?
Their name is quite intuitive, but it might useful.

I am trying to substitute the copper areas of a quite complex logo with DRC compliant areas (unfortunately I cannot share it directly). The logo was made with the method I outlined before, changing the poly-lines to the desired layers.
My first idea was to import it using KSU and use it as a stencil to make the copper pads and then re-export it.
The first issue I encountered is that I cannot import poly-lines in freecad.
Therefore I decided to try to re make it from zero.
When I tried to make a shape with an empty area inside (like an O letter with some thickness), if I padded it using freecad, the solid is hollow, but if I export it as a single piece to a footprint, the hole inside was filled.
I saw the demo footprint-complex-arc-pads and also that the areas are split into three.

  • Is this required because hollow areas are not supported?
  • Is poly-lines footprint import not supported?

So I tried also a different method, but without KSU. I converted it as I was doing before with the poly lines, I added a pad into the copper poly-lines and in the right-click menu I found the option “Create pad from the selected shapes”. I was not expecting that, but it converted that shape to a proper pad!
This procedure is more of a workaround than solution, though, but it could also work with svg2shenzen I think.

Using KSU with freecad would still probably produce the best footprints, as it would use only the minimum number of required primitives.

Thanks again for your patience!

inside the file ‘https://github.com/easyw/kicadStepUpMod/blob/master/kicadStepUptools.py’ search for:

def PushFootprint():

Why don’t you place a keepout area around your logo?

Which version of FreeCAD are you using… FreeCAD can import DXF and SVG containing poly-lines…
And StepUp can handle fp poly-lines import, but only if the poly-line will lead to a pad…

This is a requirement to create a kicad pad… only connected area can make a pad.

Anyway, for a logo design, definitely svg2shenzen is your best option. Still you will have to rework the footprint to get a DRC compliant fp.

Can I place a keepout area directly inside the footprint? I will not be the only user of that footprint and I would like to avoid adding extra steps to place keep out areas on the pcb.

KSU is at commit c25f75b (Your branch is up-to-date with ‘origin/master’.).
Freecad is 0.18.3.
I see, it is not leading to a pad as it is a graphic for the silkscreen here and therefore not imported.

If I have a custom shape with a hole inside this should still be topologically connected. Let’s say you take the example before and close the two feet into one, creating a non-copper region inside a closed region. When converted to kicad_mod it will end in a footprint without the hole inside.
fp-Logo.kicad_mod (4.8 KB) logo-fp.fcstd (21.8 KB)
So, if I understand well this is not supported by kicad.

I struggled to get it working properly and I am in favour of the approach using a proper cad.
I am trying now using a complex logo to understand the limits of each approach, but the idea is to use it for complex coil shapes, antennas and meta-material RF elements.
Their shapes are sometimes quite exotic and they resemble more of a complex logo, but I can assure you there is a rationale behind their shapes and those might be scripted.
The final goal is to automatically create footprints for automatic inclusion in kicad, with full DRC support.

For example, as a test, I tried this (svg) shape:
customshapekicad
using svg2shenzen but I was not able to export it:
I am using Inkscape 0.92.4 (5da689c313, 2019-01-14) on Linux Kubuntu 19.10

Traceback (most recent call last):
  File "export.py", line 752, in <module>
    _main()
  File "export.py", line 748, in _main
    e.affect()
  File "/usr/share/inkscape/extensions/inkex.py", line 283, in affect
    self.effect()
  File "export.py", line 324, in effect
    self.processExportLayer()
  File "export.py", line 490, in processExportLayer
    with open(kicad_file, 'r') as f:
IOError: [Errno 2] No such file or directory: '/tmp/.svg2shenzhen-cache/customshapekicad.pretty/F.Cu_g824.kicad_mod'

I checked the folder and it is there, but the file is missing, but I suppose it should be created by the extension and not manually. I am not sure how to fix this error.

So then I tried the same shape again with the approach using freecad (custom.FCStd (9.3 KB) ) but the result is an oval without the inner hole, as discussed before.
Anyway, i tried again using the bitmap to component and I was able to make a single pad with a single primitive (custom_b2c.kicad_mod (9.9 KB) ), so it should be somewhat possible to have custom pads with custom shaped holes inside.
How would you convert this latest one using KSU? Should I always split it into two shapes and then combine them into two primitives for the same custom pad?

I manged to get svg2shenzen to work. The executable in ~/.config/inkscape/extensions/svg2shenzhen/bitmap2component_linux64 needs to be executable.
chmod +x ~/.config/inkscape/extensions/svg2shenzhen/bitmap2component_linux64

Just for reference, this is done using svg2shenzen and converted into a pad using the method described before inside the kicad footprint editor customshapekicad.kicad_mod (8.8 KB)

I’m glad you find your way… luckily kicad offers a human readable text for its formats, so many tools are implementing different and user oriented solutions.

1 Like

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