Giter Club home page Giter Club logo

gerber_to_scad's Introduction

gerber_to_scad

Simple python script for converting gerber files into a 3d printable solder stencil scad file

Installation

gerber to scad requires python3.9

Note: on M1 macs, scipy doesn't install correctly out of the box. If you're getting installation errors, try this:

brew install openblas
export OPENBLAS="$(brew --prefix openblas)"
poetry install

Usage

  • To activate the poetry virtualenv, run poetry shell.

You should now be able to run the script. You'll get some information on available options if you run it with the -h argument:

(env) $ python main.py -h
usage: main.py [-h] [-t THICKNESS] [-n] [-L LEDGE_HEIGHT] [-g GAP]
                         [-i INCREASE_HOLE_SIZE]
                         outline_file solderpaste_file output_file

Convert gerber files to an scad 3d printable solder stencil.

positional arguments:
  outline_file          Outline file
  solderpaste_file      Solderpaste file
  output_file           Output file

optional arguments:
  -h, --help            show this help message and exit
  -t THICKNESS, --thickness THICKNESS
                        Thickness (in mm) of the stencil. Make sure this is a
                        multiple of the layer height you use for printing
                        (default: 0.2)
  -n, --no-ledge        By default, a ledge around half the outline of the
                        board is included, to allow aligning the stencil
                        easily. Pass this to exclude this ledge.
  -L LEDGE_HEIGHT, --ledge-height LEDGE_HEIGHT
                        Height of the stencil ledge. This should be less than
                        the thickness of the PCB (default: 1.2)
  -g GAP, --gap GAP     Gap (in mm) between board and stencil ledge. Increase
                        this if the fit of the stencil is too tight (default:
                        0.0)
  -i INCREASE_HOLE_SIZE, --increase-hole-size INCREASE_HOLE_SIZE
                        Increase the size of all holes in the stencil by this
                        amount (in mm). Use this if you find holes get printed
                        smaller than they should (default: 0.0)

For basic usage, simply run the script with input files for the gerber outline and solderpaste files and specify an output:

python main.py outline_file.gko toppaste_file.gtp output.scad

gerber_to_scad's People

Contributors

danielkucera avatar kirberich avatar mancausoft avatar shmuelzon avatar stan23 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gerber_to_scad's Issues

Readme instructions are outdated

Hi,

I am trying to run this app standalone (without docker/service) but the instructions in the readme doesn't match current repo status.

It would be really appreciated if you could update the readme with the instructions to make this app work at the current status..

best,
rafa

SCAD file preview is fine -> rendering contains only the ledge

Dear Rob,

thx for this nice project, I would like to test a stencil from the 3D printer :-).

Anyway, there seems to be a problem with the scad file:

  • I tried the online page -> error (cannot create STL file)
  • Python script works like a charm, no problems with pip or the script itself
  • Opening the SCAD file in OpenSCAD (v2015.03-2 on Debian testing) works
    too
  • A preview is rendered correctly, I can see all parts/details of the stencil
  • If a render it (necessary to export as STL file), there is only the ledge left

Do you have any advice how to proceed?

I've attached 2 different board files I tried.
Both of them are exported from KiCAD5.

PS: No gbr files in GitHUB -> renamed them to .txt
ble_power_plug_relais_kicad-F.Paste.txt
ble_power_plug_relais_kicad-Edge.Cuts.txt
MPPT_ARM-Edge.Cuts.txt
MPPT_ARM-F.Paste.txt

Got IndexError: tuple index out of range when run the script

Hi all,

I try to run the script with my *.gm1 and *.gtp gerber files to generate *.stl file for 3D printing.
However, I could not get it runs successfully.
Here is the log:
[Admins-MacBook-Pro:gerber_to_scad-master macOS$ python gerber_to_scad.py lora_dev_usb_poured.GM1 lora_dev_usb_poured.GTP output.stl
Traceback (most recent call last):
File "gerber_to_scad.py", line 392, in
args.increase_hole_size
File "gerber_to_scad.py", line 308, in process
outline_shape = create_outline_shape(outline_file)
File "gerber_to_scad.py", line 183, in create_outline_shape
return convex_hull(outline_vertices)
File "gerber_to_scad.py", line 23, in convex_hull
hull = ConvexHull(points)
File "scipy/spatial/qhull.pyx", line 2379, in scipy.spatial.qhull.ConvexHull.init (scipy/spatial/qhull.c:24005)
IndexError: tuple index out of range

Can anyone tell me how to fix the problem?

Thanks,
HuyK

gerbers.zip

does this support gerber from KiCAD? I don't see any .gko file

Hi, neat project, wondering if I can use it with KiCAD though. I exported my project and get :

kicad-like-a-pro-3rd-LED-torch-B_Cu.gbl
kicad-like-a-pro-3rd-LED-torch-B_Mask.gbs
kicad-like-a-pro-3rd-LED-torch-B_Paste.gbp
kicad-like-a-pro-3rd-LED-torch-B_Silkscreen.gbo
kicad-like-a-pro-3rd-LED-torch-Edge_Cuts.gm1
kicad-like-a-pro-3rd-LED-torch-F_Cu.gtl
kicad-like-a-pro-3rd-LED-torch-F_Mask.gts
kicad-like-a-pro-3rd-LED-torch-F_Paste.gtp
kicad-like-a-pro-3rd-LED-torch-F_Silkscreen.gto
kicad-like-a-pro-3rd-LED-torch-job.gbrjob
kicad-like-a-pro-3rd-LED-torch-NPTH.drl
kicad-like-a-pro-3rd-LED-torch-PTH.drl

so wondering if something could replace the .gko file in the example.

How to specify source file

I would ike to make use of your software to be able to print solder stencil's for some of my projects. I'm kind of new to using PYTHON on the PC and can't tell from you files, how to specify the source files.

I was able to generate the output files from my Eagle CAD layout using the .cam file you provided; however, once I have the files, I'm not sure how to tell the Python program to use them.

I tried using the online version, but get redirected to an APACHE2 error page.

Thanks for creating this, if I can get it to work, it will be a big help with building my boards.

Robert

Option for bottom layer

Hey there! Awesome work here.

Is there any possibility to do it with the bottom layer also?

Regards.

Unexpected Primitives - AMCommentPrimitive and AMVectorLinePrimitive

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,

  • AMCommentPrimitive,
    AMCirclePrimitive,
    AMPrimitive,
    )
    @@ -200,6 +201,8 @@ def primitive_to_shape(p, in_region=False, simplify_regions=False) -> List[V]:
    )
    elif isinstance(p, AMOutlinePrimitive):
    return [make_v(point) for point in p.points]
  • elif isinstance(p, AMCommentPrimitive):
  •    return
    
    else:
    raise NotImplementedError("Unexpected primitive type {}".format(type(p)))
    return vertices

LEDModule-stencil.zip

TypeError: offset_points() got an unexpected keyword argument 'inside'

got this error while running

/home/matt/Projects/Code/gerber_to_scad/./gerber_to_scad.py:442: DeprecationWarning: 'U' mode is deprecated
outline_file = open(args.outline_file, 'rU')
/home/matt/Projects/Code/gerber_to_scad/./gerber_to_scad.py:443: DeprecationWarning: 'U' mode is deprecated
solderpaste_file = open(args.solderpaste_file, 'rU')
Traceback (most recent call last):
File "/home/matt/Projects/Code/gerber_to_scad/./gerber_to_scad.py", line 449, in
process(
File "/home/matt/Projects/Code/gerber_to_scad/./gerber_to_scad.py", line 383, in process
ledge_shape = offset_shape(outline_shape, 1.2)
File "/home/matt/Projects/Code/gerber_to_scad/./gerber_to_scad.py", line 211, in offset_shape
offset_3d_points = utils.offset_points(
TypeError: offset_points() got an unexpected keyword argument 'inside'

ModuleNotFoundError: No module named 'gerber'

Running Poetry via Python 3.10.9 from PowerShell on Win10, every time I run python main.py (regardless of any flags or input files), I get:

python main.py
Traceback (most recent call last):
File "C:\gerber_to_scad\main.py", line 2, in from gerber_to_scad import process_gerber
File "C:\gerber_to_scad\gerber_to_scad_init_.py", line 1, in from .conversion import process_gerber
File "C:\gerber_to_scad\gerber_to_scad\conversion.py", line 5, in from gerber import primitives
ModuleNotFoundError: No module named 'gerber'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.