DEV Community

Emir Mrkaljević
Emir Mrkaljević

Posted on

Adding mounting holes to an editable L-bracket from an STL

I keep building mesh2cad, a small open source tool that takes an STL of a simple mechanical part and gives you back editable CAD: a CadQuery script, an OpenSCAD file, a FreeCAD macro, and a STEP solid.

Version 0.24.0 already turned a filleted L-bracket into a script where the corner radius and the plate sizes were named numbers. Version 0.25.0 adds the missing piece I actually need when I print one: mounting holes.

What you get

Give it an STL of an L-bracket with rounded vertical edges and through-holes in the foot, the upright, or both. The script it writes keeps the earlier sizes (fillet_r, base_x, base_y, base_t, leg_x, leg_y) and adds:

  • base_hole_1_d, base_hole_1_x, base_hole_1_y for a hole through the base
  • leg_hole_1_d, leg_hole_1_x, leg_hole_1_y for a hole through the upright

A second hole in the same member is base_hole_2 or leg_hole_2. Changing a hole is one command:

pip install -U mesh2cad
mesh2cad convert bracket.stl --cadquery bracket.py
mesh2cad params bracket.py
mesh2cad edit bracket.py --set base_hole_1_d=5 --in-place -o bracket.step
Enter fullscreen mode Exit fullscreen mode

--cadquery bracket.py writes the script. Add -o bracket.step on convert if you also want the solid. The same parameter names work with --openscad and --freecad.

How it decides

mesh2cad only writes a script if the rebuilt solid matches the mesh. The deviation has to stay under max(4 x tolerance, 0.1 mm) and the volume error under 1%. A miss writes no file and exits with the reason, so you never get a script that quietly looks wrong. It fillets the L first, then cuts the holes.

Honest numbers

I test a synthetic 40 x 30 x 12 mm bracket with r=3 mm, an Ø4 hole in the foot and an Ø4 hole in the upright, on three random seeds:

  • no noise: passes 3 of 3
  • 0.05 mm noise: passes 2 of 3
  • 0.2 mm noise: refused

Limits, plainly: only through-holes along Z are supported. A hole along X or Y, a blind hole, a counterbore, and a hole that crosses from the exclusive foot into the exclusive upright are not written. FreeCAD output is generated from the same checked model, but I did not run FreeCAD itself in these tests.

It is still a tool for simple prismatic parts. Organic shapes and scans with heavy noise are out of scope, and the README says so.

Try it

If you have a simple mechanical STL where it fails, an issue with the file (or a description of the shape) helps me most.

Top comments (0)