kirberich / gerber_to_scad

Simple python script for converting gerber files into a 3d printable solder stencil scad file
MIT License
89 stars 29 forks source link

Unexpected Primitives - AMCommentPrimitive and AMVectorLinePrimitive #15

Closed brettski74 closed 1 year ago

brettski74 commented 1 year ago

Trying to generate a stencil scad file for gerber output I generated from KiCad 6 using the normal settings I use for JLCPCB. Getting multiple unexpected primitives. First one was AMCommentPrimitive, which I just guessed to be a comment and safely ignorable. For that I added a couple of lines to do a null return for these in conversion.py, but that just got me to the next problem - another unexpected primitive for AMVectorLinePrimitive. I doubt that's something I can just ignore.

The question is, this presumably has already worked for some gerber files that the authors used. Are there particular tools, settings or constraints that I should use when generating my gerber files in order to work with this script? Alternatively, perhaps we need to implement conversions for more primitives. I've attached the edge cuts and front paste layer gerber files in the attached ZIP file.

The changes I made to conversion.py to ignore AMCommentPrimitive primitives are described in the following diff:

diff --git a/gerber_to_scad/conversion.py b/gerber_to_scad/conversion.py index c981563..02b7ec3 100755 --- a/gerber_to_scad/conversion.py +++ b/gerber_to_scad/conversion.py @@ -6,6 +6,7 @@ from gerber import primitives from gerber.am_statements import ( AMOutlinePrimitive, AMCenterLinePrimitive,

LEDModule-stencil.zip

kirberich commented 1 year ago

Hi, thanks for looking into that!

I've applied those changes, though I think the comment case should return an empty list rather than None, let me know if that gives you any trouble!

For the vector line primitive, basically the problem is that the gerber format is huge, and different footprints end up using completely different bits of the standard. Vector line isn't supported because I haven't come across a file before that needs it 😅

I've added some quick support for vector lines, though I'm not 100% convinced I did it right, because in your file they're used within a macro for creating rounded rectangles, and macro support is extremely basic because they are super complex, and they never came up when I built this for myself. It looks like kicad is using them a lot these days, whereas eagle (now fusion360) doesn't seem to ever use macros.

With this done, your file processes now, but it has quite a few issues - some of the rounded rectangles are reproduced too small, none of them are rotated, and a few of the smaller shapes have disappeared completely. I can't make any promises on if or when they might be supported better, but of course I'm very open to pull requests!