diff main.scad @ 2:fe29ace8155e

added magnet attachment option
author ark
date 2026-11-03 10:08 +0100
parents b5a96b547b01
children f5ff6f1a5454
line wrap: on
line diff
--- a/main.scad	Tue Nov 03 02:12:35 2026 +0100
+++ b/main.scad	Tue Nov 03 10:08:08 2026 +0100
@@ -1,11 +1,10 @@
 // House number: glyphs of a text, printed face down, screwed to a wall
-// with distance washers. Glyph outlines and hole positions come from
+// with distance washers or held by magnets in the washers. Glyph outlines and hole positions come from
 // glyphs.scad, written by make_glyphs.py.
 
 /* [part selection] */
-// part to show or export; the decal needs two-colour mode; the template is
-// 2D, for SVG export and make_template.py
-part = "all"; // [all, body, decal, washer, template]
+// part to show or export
+part = "all"; // [all, body, decal:"decal, two-colour mode", washer, template:"template, export as SVG for make_template.py"]
 
 /* [layout] */
 // whole text in one print, or one glyph per print
@@ -29,6 +28,12 @@
 // backing thickness in layers
 backing_layers = 4; // [1:1:20]
 
+/* [attachment] */
+// screws through the glyph, or magnets in the washers
+attachment = "screw"; // [screw, magnet]
+// minimum material around the screw head or magnet, in line widths, for the fit check
+fit_wall_lines = 2; // [0:1:10]
+
 /* [screws] */
 // screw diameter
 screw_d = 4; // [2:.5:8]
@@ -36,8 +41,14 @@
 countersink = true;
 // screw head diameter
 head_d = 8; // [3:.5:16]
-// minimum material around the screw head, in line widths, for the fit check
-head_wall_lines = 2; // [0:1:10]
+
+/* [magnets] */
+// magnet pocket diameter, used as given for the press fit, without clearance
+magnet_d = 10; // [1:.05:30]
+// magnet pocket depth, used as given; flush with the washer end when open
+magnet_h = 3; // [.5:.05:20]
+// close the pockets with 2 layers, the magnets are inserted during a print pause
+seal_magnets = false;
 
 /* [two-colour] */
 // split into body and decal, for a filament change on a single-colour printer
@@ -48,9 +59,9 @@
 /* [washer] */
 // print the washers as part of the body, on the back of the glyph
 washers_on_body = false;
-// washer wall around the screw hole, in line widths
+// washer wall around the screw hole or magnet, in line widths
 washer_wall_lines = 8; // [1:1:40]
-// washer height, raised to the countersink part inside the washer plus 4 layers
+// washer height, rounded to whole layers; raised to the countersink part or the magnet pocket inside the washer plus 4 layers
 washer_height = 10; // [0:.5:30]
 
 /* [print settings] */
@@ -75,17 +86,31 @@
 decal_t = 2 * lh;      // 2 layers
 frame_t = lh;          // 1 layer
 
+magnet = attachment == "magnet";
+
 // screw holes: 90 degree countersink, depth is half the diameter difference
 hole_d = screw_d + 2 * clearance;
 cs_d = head_d + 2 * clearance;
-cs_depth = countersink ? (cs_d - hole_d) / 2 : 0;
+cs_depth = !magnet && countersink ? (cs_d - hole_d) / 2 : 0;
 // part of the countersink that reaches beyond the glyph into the washer
 cs_washer = max(0, cs_depth - total_t);
 
+// magnet pockets at the wall end of the washers. A sealed pocket is deepened
+// to whole layers, so the print pause falls on its top
+cover_t = seal_magnets ? 2 * lh : 0;   // 2 layers over the magnet
+pocket_h = seal_magnets ? _layers_up(magnet_h) : magnet_h;
+
 // washer
-washer_od = hole_d + 2 * washer_wall_lines * lw;
-washer_min = cs_washer + 4 * lh;   // 4 layers below the countersink
-washer_h = max(washer_height, washer_min);
+bore_d = magnet ? magnet_d : hole_d;
+washer_od = bore_d + 2 * washer_wall_lines * lw;
+// 4 layers below the countersink or the pocket
+washer_min = _layers_up((magnet ? pocket_h + cover_t : cs_washer) + 4 * lh);
+washer_set = round(washer_height / lh) * lh;
+washer_h = max(washer_set, washer_min);
+// print height of the top of a sealed pocket, on the body or on the bed
+pause_z = (washers_on_body ? total_t : 0) + washer_h - cover_t;
+// magnet pocket for file names: diameter and depth in 1/100 mm, s if sealed
+magnet_str = str("mg", round(100 * magnet_d), "x", round(100 * magnet_h), seal_magnets ? "s" : "");
 
 // layout and size
 n_glyphs = len(g_glyphs);
@@ -110,7 +135,7 @@
 
 // holes of the shown glyphs: [position, largest circle radius at the print size]
 holes = [for (i = sel) for (h = g_glyphs[i][5]) [_tf([h.x + _off(i), h.y]), h[2] * k]];
-head_r_req = head_d / 2 + head_wall_lines * lw;
+fit_r_req = (magnet ? magnet_d : head_d) / 2 + fit_wall_lines * lw;
 
 assert(glyph_index < n_glyphs, str("glyph_index must be below ", n_glyphs));
 assert(part != "decal" || two_colour, "the decal needs two_colour");
@@ -118,20 +143,33 @@
 echo(str("size: ", final_size, " mm, largest that fits ", max_size, " mm at ",
          print_angle, " degrees"));
 echo(str("glyph thickness: ", glyph_t, " mm, with backing ", total_t, " mm"));
-echo(str("hole: ", hole_d, " mm, countersink ", cs_d, " mm, depth ", cs_depth,
-         " mm, of which in the washer ", cs_washer, " mm"));
+if (magnet)
+    echo(str("magnet pocket: ", magnet_d, " mm, depth ", pocket_h, " mm",
+             seal_magnets ? str(", sealed by ", cover_t, " mm") : ", open"));
+else
+    echo(str("hole: ", hole_d, " mm, countersink ", cs_d, " mm, depth ", cs_depth,
+             " mm, of which in the washer ", cs_washer, " mm"));
 echo(str("washer: ", washer_od, " mm outside, ", washer_h, " mm high, wall ",
          washer_wall_lines, " line widths"));
 if (size > max_size + .01)
     echo(str("WARNING: size ", size, " mm does not fit the bed, largest is ", max_size, " mm"));
-if (washer_height < washer_min)
+if (magnet && seal_magnets)
+    echo(str("pause: insert the magnets after the layer ending at ", pause_z, " mm, layer ",
+             round(pause_z / lh), washers_on_body ? " of the body" : " of the washer"));
+if (magnet && seal_magnets && pocket_h > magnet_h + epsilon)
+    echo(str("WARNING: pocket depth raised to ", pocket_h, " mm, whole layers"));
+if (washer_set < washer_min)
     echo(str("WARNING: washer height raised to ", washer_min, " mm"));
-for (h = holes) if (h[1] < head_r_req)
-    echo(str("WARNING: hole at ", h[0], ": largest circle radius ", h[1],
-             " mm, head plus wall needs ", head_r_req, " mm"));
+for (h = holes) if (h[1] < fit_r_req)
+    echo(str("WARNING: hole at ", h[0], ": largest circle radius ", h[1], " mm, ",
+             magnet ? "magnet" : "head", " plus wall needs ", fit_r_req, " mm"));
 if (washers_on_body) for (h = holes) if (h[1] < washer_od / 2)
     echo(str("WARNING: washer at ", h[0], " is cut back to the glyph outline"));
 
+// Length rounded up to whole layers, ignoring rounding errors.
+// x: length in mm.
+function _layers_up(x) = ceil(x / lh - .01) * lh;
+
 // Size of the bounding box of points rotated by a degrees, along its longer side.
 // pts: list of 2D points. a: angle in degrees.
 function _extent(pts, a) =
@@ -184,9 +222,9 @@
 }
 
 // Screw holes and countersinks, opening towards the bed, through washers
-// printed on the body.
+// printed on the body. Nothing for magnets.
 module _holes() {
-    for (h = holes) translate(h[0]) {
+    if (!magnet) for (h = holes) translate(h[0]) {
         translate([0, 0, -1])
             cylinder(d = hole_d, h = total_t + (washers_on_body ? washer_h : 0) + 2);
         if (countersink)
@@ -195,6 +233,13 @@
     }
 }
 
+// Magnet pocket below z = 0, the wall end of a washer: open, or closed by
+// the cover layers.
+module _pocket() {
+    translate([0, 0, -cover_t - pocket_h])
+        cylinder(d = magnet_d, h = pocket_h + (seal_magnets ? 0 : 1));
+}
+
 // Frame of one layer and one line width, one line width around the shown
 // glyphs. Decal and body both contain it, so the slicer places them alike.
 module _frame() {
@@ -216,7 +261,7 @@
 // Glyph body in print orientation, face on the bed. In two-colour mode the
 // decal band plus one line width is left out of the decal layers. Washers
 // printed on the body stand on its back, cut back to the outline of the back
-// so they do not overhang.
+// so they do not overhang, with the magnet pockets at their top.
 // frame: include the frame (two-colour mode only).
 module body(frame = true) {
     difference() {
@@ -231,6 +276,8 @@
                     linear_extrude(washer_h + epsilon) _back2d();
                 }
         }
+        if (washers_on_body && magnet)
+            for (h = holes) translate([h[0].x, h[0].y, total_t + washer_h]) _pocket();
         _holes();
         if (two_colour)
             translate([0, 0, -epsilon]) linear_extrude(decal_t + epsilon)
@@ -249,12 +296,14 @@
     if (frame) _frame();
 }
 
-// Distance washer, printed with the glyph side up. With countersinks deeper
-// than the glyph, the cone continues in the top of the washer.
+// Distance washer. For screws it prints with the glyph side up; with
+// countersinks deeper than the glyph, the cone continues in its top. For
+// magnets it prints with the wall side up, the pocket in its top.
 module washer() {
     difference() {
         cylinder(d = washer_od, h = washer_h);
-        translate([0, 0, -1]) cylinder(d = hole_d, h = washer_h + 2);
+        if (magnet) translate([0, 0, washer_h]) _pocket();
+        else translate([0, 0, -1]) cylinder(d = hole_d, h = washer_h + 2);
         if (cs_washer > 0)
             translate([0, 0, washer_h - cs_washer])
                 cylinder(d1 = hole_d, d2 = hole_d + 2 * cs_washer + 2 * epsilon,
@@ -263,7 +312,8 @@
 }
 
 // Drilling template in 2D, as seen on the wall: all glyphs of the text at
-// their place, a circle and cross at each hole, a level line along the
+// their place, a circle of the hole or magnet diameter and a cross at each
+// hole, a level line along the
 // baseline and a 100 mm scale bar with 10 mm ticks. Everything is made of
 // thin strips, so the outlines of the SVG export show each line.
 module template() {
@@ -282,8 +332,8 @@
         }
         for (h = g[5]) translate(pos(g, h)) {
             difference() {
-                circle(d = hole_d);
-                circle(d = hole_d - 2 * t);
+                circle(d = bore_d);
+                circle(d = bore_d - 2 * t);
             }
             square([2 * arm, t], center = true);
             square([t, 2 * arm], center = true);
@@ -306,7 +356,8 @@
         if (two_colour) color("firebrick") decal(frame = false);
         if (!washers_on_body)
             color("steelblue") for (h = holes)
-                translate([h[0].x, h[0].y, total_t + washer_h]) mirror([0, 0, 1]) washer();
+                if (magnet) translate([h[0].x, h[0].y, total_t]) washer();
+                else translate([h[0].x, h[0].y, total_t + washer_h]) mirror([0, 0, 1]) washer();
     }
 }
 
@@ -328,10 +379,14 @@
     part == "all" ? "" : str(part, "_"),
     part == "template" ? str(g_name, "_s", round(10 * final_size))
     : part == "washer"
-        ? str(countersink ? "cs_" : "", "d", round(10 * screw_d), "w", washer_wall_lines,
-              "h", round(10 * washer_h), countersink ? str("c", round(10 * cs_washer)) : "")
+        ? magnet
+            ? str(magnet_str, "_w", washer_wall_lines, "h", round(10 * washer_h))
+            : str(countersink ? "cs_" : "", "d", round(10 * screw_d), "w", washer_wall_lines,
+                  "h", round(10 * washer_h), countersink ? str("c", round(10 * cs_washer)) : "")
         : str(g_name, "_", layout == "glyph" ? str("g", glyph_index, "_") : "",
-              two_colour ? "2c_" : "", backing ? "bk_" : "", countersink ? "cs_" : "",
+              two_colour ? "2c_" : "", backing ? "bk_" : "",
+              magnet ? (washers_on_body ? str(magnet_str, "_") : "mg_")
+                     : countersink ? "cs_" : "",
               washers_on_body ? str("wh", round(10 * washer_h), "_") : "",
               "s", round(10 * final_size), "a", round(print_angle), "t", glyph_layers),
     "_lw", round(100 * line_width), "lh", round(100 * layer_height),