DEV Community

Cover image for A slanted wall and a slot into a hole: getting one more printer part to an editable script
Emir Mrkaljević
Emir Mrkaljević

Posted on

A slanted wall and a slot into a hole: getting one more printer part to an editable script

mesh2cad turns an STL into CAD. Every part gets a STEP file with real planes, cylinders and cones. When the part is simple enough it also gets a CadQuery or OpenSCAD script with named parameters, so you can change hole_3_d instead of editing triangles.

I test on six real Original Prusa i3 MK3S parts. All six already come out as exact STEP. In the last post four of them had a script. 0.14.0 adds a fifth: y-rod-holder.

Why it was refused

Last time I said y-rod-holder had two problems: a Ø6.3 opening stored as a partial ring of small planes, and a body that isn't a uniform extrusion. 0.13.x fixed the first one and the part went from 1.503 mm to 0.745 mm max deviation. The limit for this part is 0.138 mm, so it was still refused.

The remaining error came from the outline. mesh2cad builds a script solid from outlines of the part, and it traced those outlines from the mesh. On this part that went wrong in two places:

  • there is a slot that breaks into the Ø8 rod bore, and the traced outline followed the bore round through the slot instead of stopping at the two edges where the slot meets the hole
  • the -Y wall is slanted, and the traced outline cut straight across its corner instead of following it

Neither looks like much on a picture, but each one adds or removes a thin wedge of material along the whole part, and that is what the self-check measured.

What changed

When both earlier approaches miss the gate, 0.14.0 tries a third rebuild:

  • each outline is rebuilt from a raster that is snapped to the vertical wall planes already found in the mesh, so a slanted wall stays slanted
  • where a slot breaks into a hole, the outline is closed at the two mouths, and a flare that sits outside the cylinder is kept
  • a planar 45 degree bevel with axis-aligned walls becomes a triangular cut (cut_N) along the wide part of the face
  • a leftover 45 degree cone becomes cone_N_r0, cone_N_r1, cone_N_h
  • shallow floors are scored again on that solid and only kept if they bring it closer to the mesh

A part that already passes with a simpler solid never takes this path, so the other four parts are unchanged.

The numbers

Every script is rebuilt and compared to the mesh before it is written. The gate hasn't changed: max deviation at most max(4 x tolerance, 0.1 mm), volume error at most 1%.

part exact STEP script (CadQuery / OpenSCAD)
plug-aligner 0.0000 mm 0.0000 / 0.0000 mm
endstop-block 0.0168 mm 0.0421 / 0.0421 mm
y-belt-idler 0.0082 mm 0.1534 / 0.1639 mm
y-motor-holder 0.1001 mm 0.1843 / 0.1843 mm
y-rod-holder 0.2178 mm 0.1300 / 0.1300 mm (was refused at 0.745 mm)
y-belt-holder 0.1602 mm refused (2.517 mm)

For y-rod-holder the volume error is 0.096% (CadQuery) and 0.089% (OpenSCAD). The Ø3.3 hole along Y keeps its Ø6.3 counterbore as named parameters.

The new tests are small synthetic parts: a block with a 2 mm chamfer on the middle of one edge (it has to come out as cut_1 in both exporters), and a plate with a slanted wall and a slot into a hole (the outline has to keep the slanted corner and meet the hole at two mouths).

Still refused

y-belt-holder is the last one. Its belt pocket is a B-spline profile and its cross-section changes along X. Wall-snapped outlines and bevel cuts can't follow a curve like that, and I'd rather it get no script than a script that is 2.5 mm off. It still gets exact STEP.

Try it

pip install -U mesh2cad
mesh2cad convert part.stl -o part.step
mesh2cad convert part.stl --openscad part.scad
Enter fullscreen mode Exit fullscreen mode

It also runs as an MCP server (mesh2cad mcp), so an assistant can convert a part and change a parameter for you. If you have an STL of a simple mechanical part that fails, an issue with the file attached helps most: github.com/emirmrkaljevic/mesh2cad.

Top comments (0)