wobblyhead hg > 3dprints > house_number
comparison main.scad @ 2:fe29ace8155e
added magnet attachment option
| author | ark |
|---|---|
| date | 2026-11-03 10:08 +0100 |
| parents | b5a96b547b01 |
| children | f5ff6f1a5454 |
comparison
equal
deleted
inserted
replaced
| 1:aa23650954d6 | 2:fe29ace8155e |
|---|---|
| 1 // House number: glyphs of a text, printed face down, screwed to a wall | 1 // House number: glyphs of a text, printed face down, screwed to a wall |
| 2 // with distance washers. Glyph outlines and hole positions come from | 2 // with distance washers or held by magnets in the washers. Glyph outlines and hole positions come from |
| 3 // glyphs.scad, written by make_glyphs.py. | 3 // glyphs.scad, written by make_glyphs.py. |
| 4 | 4 |
| 5 /* [part selection] */ | 5 /* [part selection] */ |
| 6 // part to show or export; the decal needs two-colour mode; the template is | 6 // part to show or export |
| 7 // 2D, for SVG export and make_template.py | 7 part = "all"; // [all, body, decal:"decal, two-colour mode", washer, template:"template, export as SVG for make_template.py"] |
| 8 part = "all"; // [all, body, decal, washer, template] | |
| 9 | 8 |
| 10 /* [layout] */ | 9 /* [layout] */ |
| 11 // whole text in one print, or one glyph per print | 10 // whole text in one print, or one glyph per print |
| 12 layout = "glyph"; // [text, glyph] | 11 layout = "glyph"; // [text, glyph] |
| 13 // glyph to print in the glyph layout, counted from 0, spaces not counted | 12 // glyph to print in the glyph layout, counted from 0, spaces not counted |
| 27 // backing behind the glyph, covering its outline and connecting separate parts | 26 // backing behind the glyph, covering its outline and connecting separate parts |
| 28 backing = false; | 27 backing = false; |
| 29 // backing thickness in layers | 28 // backing thickness in layers |
| 30 backing_layers = 4; // [1:1:20] | 29 backing_layers = 4; // [1:1:20] |
| 31 | 30 |
| 31 /* [attachment] */ | |
| 32 // screws through the glyph, or magnets in the washers | |
| 33 attachment = "screw"; // [screw, magnet] | |
| 34 // minimum material around the screw head or magnet, in line widths, for the fit check | |
| 35 fit_wall_lines = 2; // [0:1:10] | |
| 36 | |
| 32 /* [screws] */ | 37 /* [screws] */ |
| 33 // screw diameter | 38 // screw diameter |
| 34 screw_d = 4; // [2:.5:8] | 39 screw_d = 4; // [2:.5:8] |
| 35 // countersunk holes, 90 degrees | 40 // countersunk holes, 90 degrees |
| 36 countersink = true; | 41 countersink = true; |
| 37 // screw head diameter | 42 // screw head diameter |
| 38 head_d = 8; // [3:.5:16] | 43 head_d = 8; // [3:.5:16] |
| 39 // minimum material around the screw head, in line widths, for the fit check | 44 |
| 40 head_wall_lines = 2; // [0:1:10] | 45 /* [magnets] */ |
| 46 // magnet pocket diameter, used as given for the press fit, without clearance | |
| 47 magnet_d = 10; // [1:.05:30] | |
| 48 // magnet pocket depth, used as given; flush with the washer end when open | |
| 49 magnet_h = 3; // [.5:.05:20] | |
| 50 // close the pockets with 2 layers, the magnets are inserted during a print pause | |
| 51 seal_magnets = false; | |
| 41 | 52 |
| 42 /* [two-colour] */ | 53 /* [two-colour] */ |
| 43 // split into body and decal, for a filament change on a single-colour printer | 54 // split into body and decal, for a filament change on a single-colour printer |
| 44 two_colour = false; | 55 two_colour = false; |
| 45 // width of the decal band along the outline | 56 // width of the decal band along the outline |
| 46 band_width = 4; // [.5:.1:20] | 57 band_width = 4; // [.5:.1:20] |
| 47 | 58 |
| 48 /* [washer] */ | 59 /* [washer] */ |
| 49 // print the washers as part of the body, on the back of the glyph | 60 // print the washers as part of the body, on the back of the glyph |
| 50 washers_on_body = false; | 61 washers_on_body = false; |
| 51 // washer wall around the screw hole, in line widths | 62 // washer wall around the screw hole or magnet, in line widths |
| 52 washer_wall_lines = 8; // [1:1:40] | 63 washer_wall_lines = 8; // [1:1:40] |
| 53 // washer height, raised to the countersink part inside the washer plus 4 layers | 64 // washer height, rounded to whole layers; raised to the countersink part or the magnet pocket inside the washer plus 4 layers |
| 54 washer_height = 10; // [0:.5:30] | 65 washer_height = 10; // [0:.5:30] |
| 55 | 66 |
| 56 /* [print settings] */ | 67 /* [print settings] */ |
| 57 line_width = .4; // [0:.01:1] | 68 line_width = .4; // [0:.01:1] |
| 58 layer_height = .2; // [0:.01:.5] | 69 layer_height = .2; // [0:.01:.5] |
| 73 backing_t = backing ? backing_layers * lh : 0; | 84 backing_t = backing ? backing_layers * lh : 0; |
| 74 total_t = glyph_t + backing_t; | 85 total_t = glyph_t + backing_t; |
| 75 decal_t = 2 * lh; // 2 layers | 86 decal_t = 2 * lh; // 2 layers |
| 76 frame_t = lh; // 1 layer | 87 frame_t = lh; // 1 layer |
| 77 | 88 |
| 89 magnet = attachment == "magnet"; | |
| 90 | |
| 78 // screw holes: 90 degree countersink, depth is half the diameter difference | 91 // screw holes: 90 degree countersink, depth is half the diameter difference |
| 79 hole_d = screw_d + 2 * clearance; | 92 hole_d = screw_d + 2 * clearance; |
| 80 cs_d = head_d + 2 * clearance; | 93 cs_d = head_d + 2 * clearance; |
| 81 cs_depth = countersink ? (cs_d - hole_d) / 2 : 0; | 94 cs_depth = !magnet && countersink ? (cs_d - hole_d) / 2 : 0; |
| 82 // part of the countersink that reaches beyond the glyph into the washer | 95 // part of the countersink that reaches beyond the glyph into the washer |
| 83 cs_washer = max(0, cs_depth - total_t); | 96 cs_washer = max(0, cs_depth - total_t); |
| 84 | 97 |
| 98 // magnet pockets at the wall end of the washers. A sealed pocket is deepened | |
| 99 // to whole layers, so the print pause falls on its top | |
| 100 cover_t = seal_magnets ? 2 * lh : 0; // 2 layers over the magnet | |
| 101 pocket_h = seal_magnets ? _layers_up(magnet_h) : magnet_h; | |
| 102 | |
| 85 // washer | 103 // washer |
| 86 washer_od = hole_d + 2 * washer_wall_lines * lw; | 104 bore_d = magnet ? magnet_d : hole_d; |
| 87 washer_min = cs_washer + 4 * lh; // 4 layers below the countersink | 105 washer_od = bore_d + 2 * washer_wall_lines * lw; |
| 88 washer_h = max(washer_height, washer_min); | 106 // 4 layers below the countersink or the pocket |
| 107 washer_min = _layers_up((magnet ? pocket_h + cover_t : cs_washer) + 4 * lh); | |
| 108 washer_set = round(washer_height / lh) * lh; | |
| 109 washer_h = max(washer_set, washer_min); | |
| 110 // print height of the top of a sealed pocket, on the body or on the bed | |
| 111 pause_z = (washers_on_body ? total_t : 0) + washer_h - cover_t; | |
| 112 // magnet pocket for file names: diameter and depth in 1/100 mm, s if sealed | |
| 113 magnet_str = str("mg", round(100 * magnet_d), "x", round(100 * magnet_h), seal_magnets ? "s" : ""); | |
| 89 | 114 |
| 90 // layout and size | 115 // layout and size |
| 91 n_glyphs = len(g_glyphs); | 116 n_glyphs = len(g_glyphs); |
| 92 sel = layout == "text" ? [for (i = [0 : n_glyphs - 1]) i] : [glyph_index]; | 117 sel = layout == "text" ? [for (i = [0 : n_glyphs - 1]) i] : [glyph_index]; |
| 93 usable = bed_size - 2 * bed_margin - 4 * lw; // frame and gap, 1 line width each | 118 usable = bed_size - 2 * bed_margin - 4 * lw; // frame and gap, 1 line width each |
| 108 max([for (p = raw_pts) p.x]), max([for (p = raw_pts) p.y])]; | 133 max([for (p = raw_pts) p.x]), max([for (p = raw_pts) p.y])]; |
| 109 centre = [(bb[0] + bb[2]) / 2, (bb[1] + bb[3]) / 2]; | 134 centre = [(bb[0] + bb[2]) / 2, (bb[1] + bb[3]) / 2]; |
| 110 | 135 |
| 111 // holes of the shown glyphs: [position, largest circle radius at the print size] | 136 // holes of the shown glyphs: [position, largest circle radius at the print size] |
| 112 holes = [for (i = sel) for (h = g_glyphs[i][5]) [_tf([h.x + _off(i), h.y]), h[2] * k]]; | 137 holes = [for (i = sel) for (h = g_glyphs[i][5]) [_tf([h.x + _off(i), h.y]), h[2] * k]]; |
| 113 head_r_req = head_d / 2 + head_wall_lines * lw; | 138 fit_r_req = (magnet ? magnet_d : head_d) / 2 + fit_wall_lines * lw; |
| 114 | 139 |
| 115 assert(glyph_index < n_glyphs, str("glyph_index must be below ", n_glyphs)); | 140 assert(glyph_index < n_glyphs, str("glyph_index must be below ", n_glyphs)); |
| 116 assert(part != "decal" || two_colour, "the decal needs two_colour"); | 141 assert(part != "decal" || two_colour, "the decal needs two_colour"); |
| 117 | 142 |
| 118 echo(str("size: ", final_size, " mm, largest that fits ", max_size, " mm at ", | 143 echo(str("size: ", final_size, " mm, largest that fits ", max_size, " mm at ", |
| 119 print_angle, " degrees")); | 144 print_angle, " degrees")); |
| 120 echo(str("glyph thickness: ", glyph_t, " mm, with backing ", total_t, " mm")); | 145 echo(str("glyph thickness: ", glyph_t, " mm, with backing ", total_t, " mm")); |
| 121 echo(str("hole: ", hole_d, " mm, countersink ", cs_d, " mm, depth ", cs_depth, | 146 if (magnet) |
| 122 " mm, of which in the washer ", cs_washer, " mm")); | 147 echo(str("magnet pocket: ", magnet_d, " mm, depth ", pocket_h, " mm", |
| 148 seal_magnets ? str(", sealed by ", cover_t, " mm") : ", open")); | |
| 149 else | |
| 150 echo(str("hole: ", hole_d, " mm, countersink ", cs_d, " mm, depth ", cs_depth, | |
| 151 " mm, of which in the washer ", cs_washer, " mm")); | |
| 123 echo(str("washer: ", washer_od, " mm outside, ", washer_h, " mm high, wall ", | 152 echo(str("washer: ", washer_od, " mm outside, ", washer_h, " mm high, wall ", |
| 124 washer_wall_lines, " line widths")); | 153 washer_wall_lines, " line widths")); |
| 125 if (size > max_size + .01) | 154 if (size > max_size + .01) |
| 126 echo(str("WARNING: size ", size, " mm does not fit the bed, largest is ", max_size, " mm")); | 155 echo(str("WARNING: size ", size, " mm does not fit the bed, largest is ", max_size, " mm")); |
| 127 if (washer_height < washer_min) | 156 if (magnet && seal_magnets) |
| 157 echo(str("pause: insert the magnets after the layer ending at ", pause_z, " mm, layer ", | |
| 158 round(pause_z / lh), washers_on_body ? " of the body" : " of the washer")); | |
| 159 if (magnet && seal_magnets && pocket_h > magnet_h + epsilon) | |
| 160 echo(str("WARNING: pocket depth raised to ", pocket_h, " mm, whole layers")); | |
| 161 if (washer_set < washer_min) | |
| 128 echo(str("WARNING: washer height raised to ", washer_min, " mm")); | 162 echo(str("WARNING: washer height raised to ", washer_min, " mm")); |
| 129 for (h = holes) if (h[1] < head_r_req) | 163 for (h = holes) if (h[1] < fit_r_req) |
| 130 echo(str("WARNING: hole at ", h[0], ": largest circle radius ", h[1], | 164 echo(str("WARNING: hole at ", h[0], ": largest circle radius ", h[1], " mm, ", |
| 131 " mm, head plus wall needs ", head_r_req, " mm")); | 165 magnet ? "magnet" : "head", " plus wall needs ", fit_r_req, " mm")); |
| 132 if (washers_on_body) for (h = holes) if (h[1] < washer_od / 2) | 166 if (washers_on_body) for (h = holes) if (h[1] < washer_od / 2) |
| 133 echo(str("WARNING: washer at ", h[0], " is cut back to the glyph outline")); | 167 echo(str("WARNING: washer at ", h[0], " is cut back to the glyph outline")); |
| 168 | |
| 169 // Length rounded up to whole layers, ignoring rounding errors. | |
| 170 // x: length in mm. | |
| 171 function _layers_up(x) = ceil(x / lh - .01) * lh; | |
| 134 | 172 |
| 135 // Size of the bounding box of points rotated by a degrees, along its longer side. | 173 // Size of the bounding box of points rotated by a degrees, along its longer side. |
| 136 // pts: list of 2D points. a: angle in degrees. | 174 // pts: list of 2D points. a: angle in degrees. |
| 137 function _extent(pts, a) = | 175 function _extent(pts, a) = |
| 138 let (r = [for (p = pts) [p.x * cos(a) - p.y * sin(a), p.x * sin(a) + p.y * cos(a)]]) | 176 let (r = [for (p = pts) [p.x * cos(a) - p.y * sin(a), p.x * sin(a) + p.y * cos(a)]]) |
| 182 offset(r = -band_width) _placed2d(); | 220 offset(r = -band_width) _placed2d(); |
| 183 } | 221 } |
| 184 } | 222 } |
| 185 | 223 |
| 186 // Screw holes and countersinks, opening towards the bed, through washers | 224 // Screw holes and countersinks, opening towards the bed, through washers |
| 187 // printed on the body. | 225 // printed on the body. Nothing for magnets. |
| 188 module _holes() { | 226 module _holes() { |
| 189 for (h = holes) translate(h[0]) { | 227 if (!magnet) for (h = holes) translate(h[0]) { |
| 190 translate([0, 0, -1]) | 228 translate([0, 0, -1]) |
| 191 cylinder(d = hole_d, h = total_t + (washers_on_body ? washer_h : 0) + 2); | 229 cylinder(d = hole_d, h = total_t + (washers_on_body ? washer_h : 0) + 2); |
| 192 if (countersink) | 230 if (countersink) |
| 193 translate([0, 0, -epsilon]) | 231 translate([0, 0, -epsilon]) |
| 194 cylinder(d1 = cs_d + 2 * epsilon, d2 = hole_d, h = cs_depth + epsilon); | 232 cylinder(d1 = cs_d + 2 * epsilon, d2 = hole_d, h = cs_depth + epsilon); |
| 195 } | 233 } |
| 234 } | |
| 235 | |
| 236 // Magnet pocket below z = 0, the wall end of a washer: open, or closed by | |
| 237 // the cover layers. | |
| 238 module _pocket() { | |
| 239 translate([0, 0, -cover_t - pocket_h]) | |
| 240 cylinder(d = magnet_d, h = pocket_h + (seal_magnets ? 0 : 1)); | |
| 196 } | 241 } |
| 197 | 242 |
| 198 // Frame of one layer and one line width, one line width around the shown | 243 // Frame of one layer and one line width, one line width around the shown |
| 199 // glyphs. Decal and body both contain it, so the slicer places them alike. | 244 // glyphs. Decal and body both contain it, so the slicer places them alike. |
| 200 module _frame() { | 245 module _frame() { |
| 214 } | 259 } |
| 215 | 260 |
| 216 // Glyph body in print orientation, face on the bed. In two-colour mode the | 261 // Glyph body in print orientation, face on the bed. In two-colour mode the |
| 217 // decal band plus one line width is left out of the decal layers. Washers | 262 // decal band plus one line width is left out of the decal layers. Washers |
| 218 // printed on the body stand on its back, cut back to the outline of the back | 263 // printed on the body stand on its back, cut back to the outline of the back |
| 219 // so they do not overhang. | 264 // so they do not overhang, with the magnet pockets at their top. |
| 220 // frame: include the frame (two-colour mode only). | 265 // frame: include the frame (two-colour mode only). |
| 221 module body(frame = true) { | 266 module body(frame = true) { |
| 222 difference() { | 267 difference() { |
| 223 union() { | 268 union() { |
| 224 linear_extrude(glyph_t) _placed2d(); | 269 linear_extrude(glyph_t) _placed2d(); |
| 229 translate([0, 0, total_t - epsilon]) intersection() { | 274 translate([0, 0, total_t - epsilon]) intersection() { |
| 230 for (h = holes) translate(h[0]) cylinder(d = washer_od, h = washer_h + epsilon); | 275 for (h = holes) translate(h[0]) cylinder(d = washer_od, h = washer_h + epsilon); |
| 231 linear_extrude(washer_h + epsilon) _back2d(); | 276 linear_extrude(washer_h + epsilon) _back2d(); |
| 232 } | 277 } |
| 233 } | 278 } |
| 279 if (washers_on_body && magnet) | |
| 280 for (h = holes) translate([h[0].x, h[0].y, total_t + washer_h]) _pocket(); | |
| 234 _holes(); | 281 _holes(); |
| 235 if (two_colour) | 282 if (two_colour) |
| 236 translate([0, 0, -epsilon]) linear_extrude(decal_t + epsilon) | 283 translate([0, 0, -epsilon]) linear_extrude(decal_t + epsilon) |
| 237 offset(delta = lw) _band2d(); | 284 offset(delta = lw) _band2d(); |
| 238 } | 285 } |
| 247 _holes(); | 294 _holes(); |
| 248 } | 295 } |
| 249 if (frame) _frame(); | 296 if (frame) _frame(); |
| 250 } | 297 } |
| 251 | 298 |
| 252 // Distance washer, printed with the glyph side up. With countersinks deeper | 299 // Distance washer. For screws it prints with the glyph side up; with |
| 253 // than the glyph, the cone continues in the top of the washer. | 300 // countersinks deeper than the glyph, the cone continues in its top. For |
| 301 // magnets it prints with the wall side up, the pocket in its top. | |
| 254 module washer() { | 302 module washer() { |
| 255 difference() { | 303 difference() { |
| 256 cylinder(d = washer_od, h = washer_h); | 304 cylinder(d = washer_od, h = washer_h); |
| 257 translate([0, 0, -1]) cylinder(d = hole_d, h = washer_h + 2); | 305 if (magnet) translate([0, 0, washer_h]) _pocket(); |
| 306 else translate([0, 0, -1]) cylinder(d = hole_d, h = washer_h + 2); | |
| 258 if (cs_washer > 0) | 307 if (cs_washer > 0) |
| 259 translate([0, 0, washer_h - cs_washer]) | 308 translate([0, 0, washer_h - cs_washer]) |
| 260 cylinder(d1 = hole_d, d2 = hole_d + 2 * cs_washer + 2 * epsilon, | 309 cylinder(d1 = hole_d, d2 = hole_d + 2 * cs_washer + 2 * epsilon, |
| 261 h = cs_washer + epsilon); | 310 h = cs_washer + epsilon); |
| 262 } | 311 } |
| 263 } | 312 } |
| 264 | 313 |
| 265 // Drilling template in 2D, as seen on the wall: all glyphs of the text at | 314 // Drilling template in 2D, as seen on the wall: all glyphs of the text at |
| 266 // their place, a circle and cross at each hole, a level line along the | 315 // their place, a circle of the hole or magnet diameter and a cross at each |
| 316 // hole, a level line along the | |
| 267 // baseline and a 100 mm scale bar with 10 mm ticks. Everything is made of | 317 // baseline and a 100 mm scale bar with 10 mm ticks. Everything is made of |
| 268 // thin strips, so the outlines of the SVG export show each line. | 318 // thin strips, so the outlines of the SVG export show each line. |
| 269 module template() { | 319 module template() { |
| 270 t = .2; // strip width | 320 t = .2; // strip width |
| 271 // wall layout: text positions, no rotation, no mirroring | 321 // wall layout: text positions, no rotation, no mirroring |
| 280 import(g[1]); | 330 import(g[1]); |
| 281 offset(delta = -t / k) import(g[1]); | 331 offset(delta = -t / k) import(g[1]); |
| 282 } | 332 } |
| 283 for (h = g[5]) translate(pos(g, h)) { | 333 for (h = g[5]) translate(pos(g, h)) { |
| 284 difference() { | 334 difference() { |
| 285 circle(d = hole_d); | 335 circle(d = bore_d); |
| 286 circle(d = hole_d - 2 * t); | 336 circle(d = bore_d - 2 * t); |
| 287 } | 337 } |
| 288 square([2 * arm, t], center = true); | 338 square([2 * arm, t], center = true); |
| 289 square([t, 2 * arm], center = true); | 339 square([t, 2 * arm], center = true); |
| 290 } | 340 } |
| 291 } | 341 } |
| 304 rotate([0, 180, 0]) { | 354 rotate([0, 180, 0]) { |
| 305 color("lightgray") body(frame = false); | 355 color("lightgray") body(frame = false); |
| 306 if (two_colour) color("firebrick") decal(frame = false); | 356 if (two_colour) color("firebrick") decal(frame = false); |
| 307 if (!washers_on_body) | 357 if (!washers_on_body) |
| 308 color("steelblue") for (h = holes) | 358 color("steelblue") for (h = holes) |
| 309 translate([h[0].x, h[0].y, total_t + washer_h]) mirror([0, 0, 1]) washer(); | 359 if (magnet) translate([h[0].x, h[0].y, total_t]) washer(); |
| 360 else translate([h[0].x, h[0].y, total_t + washer_h]) mirror([0, 0, 1]) washer(); | |
| 310 } | 361 } |
| 311 } | 362 } |
| 312 | 363 |
| 313 // Output the selected part. | 364 // Output the selected part. |
| 314 module main() { | 365 module main() { |
| 326 function paramstring(prefix = "", suffix = "") = str( | 377 function paramstring(prefix = "", suffix = "") = str( |
| 327 prefix, | 378 prefix, |
| 328 part == "all" ? "" : str(part, "_"), | 379 part == "all" ? "" : str(part, "_"), |
| 329 part == "template" ? str(g_name, "_s", round(10 * final_size)) | 380 part == "template" ? str(g_name, "_s", round(10 * final_size)) |
| 330 : part == "washer" | 381 : part == "washer" |
| 331 ? str(countersink ? "cs_" : "", "d", round(10 * screw_d), "w", washer_wall_lines, | 382 ? magnet |
| 332 "h", round(10 * washer_h), countersink ? str("c", round(10 * cs_washer)) : "") | 383 ? str(magnet_str, "_w", washer_wall_lines, "h", round(10 * washer_h)) |
| 384 : str(countersink ? "cs_" : "", "d", round(10 * screw_d), "w", washer_wall_lines, | |
| 385 "h", round(10 * washer_h), countersink ? str("c", round(10 * cs_washer)) : "") | |
| 333 : str(g_name, "_", layout == "glyph" ? str("g", glyph_index, "_") : "", | 386 : str(g_name, "_", layout == "glyph" ? str("g", glyph_index, "_") : "", |
| 334 two_colour ? "2c_" : "", backing ? "bk_" : "", countersink ? "cs_" : "", | 387 two_colour ? "2c_" : "", backing ? "bk_" : "", |
| 388 magnet ? (washers_on_body ? str(magnet_str, "_") : "mg_") | |
| 389 : countersink ? "cs_" : "", | |
| 335 washers_on_body ? str("wh", round(10 * washer_h), "_") : "", | 390 washers_on_body ? str("wh", round(10 * washer_h), "_") : "", |
| 336 "s", round(10 * final_size), "a", round(print_angle), "t", glyph_layers), | 391 "s", round(10 * final_size), "a", round(print_angle), "t", glyph_layers), |
| 337 "_lw", round(100 * line_width), "lh", round(100 * layer_height), | 392 "_lw", round(100 * line_width), "lh", round(100 * layer_height), |
| 338 suffix); | 393 suffix); |
| 339 | 394 |
