A Python-based parametric tray generator for the LayerSafe project—a modular storage system created by Newman (electrumbeaulo) on Discord.
This tool generates customizable 3D storage trays with hinged flaps using the build123d CAD library.
LayerSafe generates parametric 3D tray designs featuring:
- Adjustable dimensions (width and depth)
- Hinged flap mechanisms for opening/closing
- Customizable rails and base structure
- Built-in cutouts for organization
- Support for single or double tray configurations
- Export capabilities in STEP and STL formats
- Python 3.8+
- build123d - CAD library for 3D modeling
- OCP VSCode - VS Code integration for viewing 3D models
-
Clone the repository:
git clone https://github.com/seedback/LayerSafe cd LayerSafe -
Install dependencies:
pip install build123d ocp-vscode
-
Verify installation:
python -c "import build123d; print('build123d installed successfully')"
The tray generator is designed to be run from the command line, making it easy for anyone to use without setting up an IDE.
python Trays/tray_generator.py <diameter1> <diameter2> ... [options]
⚠️ Important: Base diameters should be measured as accurately as possible. Precision down to 0.1mm is recommended for proper fit. Use quality calipers with good accuracy (±0.1mm or better) to measure your bases before generating the tray.
Generate a tray with 6 circles of 31.6mm diameter:
python Trays/tray_generator.py 31.6 31.6 31.6 31.6 31.6 31.6Generate a tray with mixed diameters (2× 25.4mm and 1× 31.6mm):
python Trays/tray_generator.py 25.4 25.4 31.6| Option | Type | Default | Description |
|---|---|---|---|
--width |
float | 189.5 | Total tray width in mm |
--depth |
float | 66.0 | Total tray depth in mm |
--safety-margin-x |
float | 6.5 | Horizontal margin from edges (mm) |
--safety-margin-y |
float | 0.8 | Vertical margin from edges (mm) |
--tolerance |
float | 0.55 | Tolerance for circle fit (mm) |
--edge-offsets |
space-separated floats | None | Edge offsets for each base (e.g., 0.5 0.5 0.5) will reduce the depth of the base with the given amount without affecting the width. Useful for fine-tuning fit, especially on larger bases (mm) |
--edge-adjusts |
space-separated floats | None | Edge adjustments for each base (e.g., 0.2 0.2 0.2), independent of edge-offsets for additional fine-tuning, a larger value will give a larger flat-spot below the curved section (mm) |
--single-sided |
flag | False | Generate a single-sided tray (default: double-sided) |
--force-linear-positions |
flag | False | Forces linear positioning (default: automatically selects linear or alternating positioning) |
--output |
string | auto | Output filename (without extension) |
Adjust safety margins for a tight fit:
python Trays/tray_generator.py 31.6 31.6 31.6 31.6 31.6 31.6 --safety-margin-y 0.4Custom dimensions with tolerance adjustment:
python Trays/tray_generator.py 25.4 25.4 25.4 --width 200 --depth 80 --tolerance 0.6Generate a single-sided tray (not double-sided):
python Trays/tray_generator.py 31.6 31.6 31.6 --single-sidedApply edge offsets to customize base positioning:
python Trays/tray_generator.py 25.4 25.4 25.4 --edge-offsets 0.5 0.5 0.5Apply edge adjustments for additional fine-tuning:
python Trays/tray_generator.py 25.4 25.4 25.4 --edge-adjusts 0.2 0.2 0.2Specify a custom output filename:
python Trays/tray_generator.py 31.6 31.6 31.6 --output my_custom_trayCombine multiple options:
python Trays/tray_generator.py 31.6 31.6 31.6 31.6 31.6 31.6 --safety-margin-y 0.4 --tolerance 0.6 --width 190 --single-sided --edge-offsets 0.2 0.2 0.2 0.2 0.2 0.2 --edge-adjusts 0.1 0.1 0.1 0.1 0.1 0.1 --output special_trayView all available options:
python Trays/tray_generator.py --helpGenerated files are automatically saved to Trays/output/:
- STL format (
.stl) — Suitable for 3D printing - STEP format (
.step) — Suitable for CAD software and CNC machines
Filenames are auto-generated based on your diameter input (e.g., tray_6x31.6mm.stl), or you can specify a custom name with --output.
If you prefer an interactive notebook environment:
- Open
Trays/tray_generator.ipynbin Jupyter - Modify the default parameters in the notebook and run cells
- View the 3D model preview in the notebook output
To use in VS Code or another IDE:
- Open
Trays/tray_generator.py - Modify the default parameters in the "User-Adjustable Parameters" section
- Run the script (VS Code: F5 or Run button)
For more detailed customization, you can edit the User-Adjustable Parameters section in tray_generator.py:
total_width = 189.5 # Overall tray width (mm)
total_depth = 66.0 # Overall tray depth (mm)
floor_thickness = 0.4 # Bottom thickness (mm)
base_height = 4.2 # Height of base section (mm)
rail_height = 8.4 # Height of side rails (mm)
rail_width = 4.8 # Width of side rails (mm)
flap_depth = 11.8 # Depth of hinged flap (mm)
flap_center_gap = 0.2 # Gap between flap and base (mm)
hinge_width = 2.8 # Width of hinge mechanism (mm)
hinge_height = 3.6 # Height of hinge mechanism (mm)
is_double_tray = True # Set to True for stacked tray configurationThis project is licensed under the MIT License - see the LICENSE file for details.
Alexander Bøhler (Seedback)
For issues or suggestions, please refer to the project repository.