Skip to content

About

DXF tool for generating custom ventilation meshes by detecting closed or connectable outlines and filling them with a fine grid (bga) pattern suitable for stainless steel laser-cut or (smt) stencil-based fabrication.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Stencilmesh

Stencilmesh is a Python tool that turns DXF outlines into dense square-aperture mesh patterns.

It is designed for workflows where you want to convert custom 2D shapes into fabrication-ready micro-mesh, such as stainless steel ventilation meshes meant to be ordered through SMT stencil services.

What it does

  • reads DXF files
  • detects closed regions from:
    • closed LWPOLYLINE
    • closed POLYLINE
    • CIRCLE
  • can also reconstruct regions from loose sketch geometry such as:
    • LINE
    • ARC
    • SPLINE
    • ELLIPSE
  • fills each region with a square aperture grid (0.3mm squares spaced 0.5mm apart center to center)
  • tries multiple grid offsets and keeps the densest valid result
  • supports multiprocessing across regions
  • can export:
    • filled DXF output
    • stencil-style Gerber bundle output (very basic implementation, still requires a lot of work)

Use cases

  • custom terrarium ventilation mesh
  • stainless vent inserts
  • stencil-based perforated sheet experiments
  • turning Inventor-exported sketches into dense fabrication geometry

Examples

Before

Before: source DXF geometry

After

After: generated filled mesh

Installation

Requires Python 3.10+.

Install dependencies:

pip install ezdxf shapely

Optional:

pip install psutil

psutil is not required, but it improves automatic worker selection when multiprocessing is enabled.

Basic usage

Generate a filled DXF:

py stencilmesh.py --input grate_top_face.dxf --output grate_top_face_filled.dxf --margin 0.2

Only write the generated mesh:

py stencilmesh.py --input grate_top_face.dxf --output grate_top_face_filled.dxf --margin 0.2 --replace

Generate a stencil-style Gerber bundle as well:

py stencilmesh.py --input grate_top_face.dxf --output grate_top_face_filled.dxf --margin 0.2 --gerber-dir gerbers --gerber-name grate_top_face --zip-gerbers

Main options

  • --input
    Input DXF file

  • --output
    Output DXF file

  • --square-size
    Square aperture size
    Default: 0.3

  • --pitch
    Grid pitch, center to center
    Default: 0.5

  • --margin
    Minimum inward border to keep clear
    Default: 0.0

  • --grid-search
    Number of grid offsets tried per axis
    Default: 8

  • --workers
    Number of worker processes
    Default: 0 (auto)

  • --replace
    Write only the generated mesh, without the original DXF entities

  • --gerber-dir
    Also write a stencil-style Gerber bundle to a directory

  • --gerber-name
    Base filename for Gerber output
    Default: stencilmesh

  • --zip-gerbers
    Zip the Gerber bundle after writing it

  • --quiet
    Suppress progress output

How worker auto-selection works

If --workers is omitted, or set to 0, Stencilmesh chooses a worker count automatically.

Auto mode is region-aware and conservative:

  • it never uses more workers than there are regions
  • it prefers physical CPU cores minus 2
  • if physical core detection is unavailable, it falls back to logical CPU cores minus 2
  • it always uses at least 1 worker

In practice, the behavior is:

if region_count <= 1:
    workers = 1
else:
    workers = min(region_count, max(1, detected_cores - 2))

This keeps the system responsive while still speeding up larger multi-region jobs.

How filling works

Stencilmesh shrinks each region by the requested --margin, then tries multiple grid offsets and keeps the densest valid fill.

Apertures are only placed if they fit fully inside the usable region.

If you want a larger clear border, increase --margin.

DXF handling notes

The script prefers real closed DXF entities when they are available.

If the file does not contain closed polylines or circles, it falls back to reconstructing loops from loose sketch-style geometry. This is especially useful for Autodesk Inventor sketch exports, which often come out as separate LINE and ARC entities instead of closed polylines.

Stencil-style Gerber export

Stencilmesh can also write a simple stencil-style Gerber bundle:

  • GTP for the aperture pattern
  • GKO for the outline
  • README.txt with a fabrication note

This export is intentionally minimal and aimed at stencil-style workflows rather than full PCB fabrication output.

Progress output

For larger jobs the script prints timestamped progress updates to stderr, for example:

  • reading DXF
  • extracting fill regions
  • reporting region count
  • fitting regions
  • writing DXF
  • writing Gerbers

Use --quiet to suppress progress output.

Limitations

  • dense outputs can produce very large DXF files
  • some DXF viewers may struggle with very high entity counts
  • loop reconstruction from loose sketch geometry works well for many CAD exports, but not every broken DXF can be repaired automatically
  • Gerber export is intentionally simple and aimed at stencil-style output, not full PCB fabrication
  • very large fills may take time, especially with higher --grid-search values

Motivation

This project started as a practical way to generate custom-shaped fine stainless ventilation mesh from DXF geometry without fighting CAD performance on huge repeated patterns.

License

MIT

About

DXF tool for generating custom ventilation meshes by detecting closed or connectable outlines and filling them with a fine grid (bga) pattern suitable for stainless steel laser-cut or (smt) stencil-based fabrication.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages