Last active
June 3, 2026 07:32
-
-
Save haliphax/e63eb8efba86406862fc71d06a11cda1 to your computer and use it in GitHub Desktop.
STL generator for breakaway stacks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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