Skip to content

Instantly share code, notes, and snippets.

@haliphax
Last active June 3, 2026 07:32
Show Gist options
  • Select an option

  • Save haliphax/e63eb8efba86406862fc71d06a11cda1 to your computer and use it in GitHub Desktop.

Select an option

Save haliphax/e63eb8efba86406862fc71d06a11cda1 to your computer and use it in GitHub Desktop.
STL generator for breakaway stacks
#!/usr/bin/env -S uv run --script
# /// script
# dependencies = ["numpy-stl"]
# ///
"""
This script is for creating stacks of more-or-less flat meshes that have
symmetrical top and bottom faces (e.g. Multiboard). The gap (default 0.2mm)
should be set to your slicer's layer height. The resulting file should be
printed with 3 walls, 15% infill, with ironing of all top surfaces enabled.
"""
# stdlib
from sys import argv
# 3rd party
from stl import mesh
from numpy import concatenate
args = len(argv) - 1
# get file, count, gap from args
m = mesh.Mesh.from_file(argv[1] if args >= 1 else "mesh.stl")
count = int(argv[2] if args >= 2 else 4)
gap = float(argv[3] if args >= 3 else 0.2)
# get height of mesh
height = m.z.max() - m.z.min()
# clone mesh
meshes = [mesh.Mesh(m.data.copy()) for _ in range(count)]
# apply z-offset for meshes, including separator gap
for i, mesh_copy in enumerate(meshes):
mesh_copy.translate([0, 0, i * (height + gap)])
# output stacked STL
combined = mesh.Mesh(concatenate([m.data for m in meshes]))
combined.save("stacked.stl")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment