DEV Community

Cover image for Six of six: the last printer part that my STL to CAD tool refused now gets an editable script
Emir Mrkaljević
Emir Mrkaljević

Posted on

Six of six: the last printer part that my STL to CAD tool refused now gets 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. Before any script is written, it is rebuilt and compared to the mesh, and it is refused if it misses.

I test on six real Original Prusa i3 MK3S parts. In the last post five of them had a script and one was refused. With 0.15.0 all six do.

Why y-belt-holder was refused

The script exporter builds a solid from outlines of the part seen along X, Y and Z, and intersects them. That works when each feature runs through the whole part. y-belt-holder breaks that in several ways at once:

  • the base is full height for part of the length and then steps down to a thin guide
  • a hexagonal nut pocket and a bore exist for only part of the length
  • five slits are only 0.2 mm thick
  • the belt teeth, including a few small B-spline patches, move along X

A silhouette taken along the full length fills every opening that exists for only part of it. The result was 2.517 mm off with a 1.97% volume error, against a limit of 0.154 mm and 1%. So it got exact STEP and no script.

What changed

When the three earlier approaches (silhouette intersection, partial-depth union, wall-snapped rebuild) have all missed, 0.15.0 tries one more:

  • start from one bounding extrusion along the axis where the part changes
  • split the length into spans where the outer cross-section stays within 0.05 mm of itself
  • on each span, cut the extrusion back to the real section (cut_N, with the kept section as cut_N_cutout_J)
  • a gap between two parallel faces from 0.12 mm to 0.55 mm becomes a polygonal cut, which covers the thin slits
  • an inner loop that keeps its place along the axis, like the hex pocket or the bore, becomes a polygonal cut over its span

A part that already passes with a simpler solid never reaches this step, so the other five results did not move.

The numbers

The gate is the same as before: 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
y-belt-holder 0.1602 mm 0.0943 / 0.0965 mm (was refused at 2.517 mm)

The y-belt-holder scripts have a 0.70% volume error, under the 1% limit but higher than the other parts. The new tests are a small synthetic bar that steps down along X, with a hexagonal tunnel and a 0.3 mm slit, checked in both exporters.

What "editable" means on this part

I want to be honest here. On the simpler parts most of the geometry is named: hole diameters, depths, chamfers, counterbores. On y-belt-holder the overall size, the bore and the spans are clean numbers, but the belt teeth and the slits come out as polygon points inside a cut. You can move them, and the script is far easier to change than a mesh, but you won't get a tooth_pitch parameter. Recognising repeated features like teeth is a separate problem I haven't solved.

Six parts is also a small test set, all from one printer and all fairly boxy. Organic shapes, fillets everywhere and scanned meshes still get STEP at best, and often not even a clean one.

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)