# HG changeset patch # User ark # Date 1794916413 -3600 # Node ID a7a1b12fd6bfc13bd381988a18d7ec211e5f33ad # Parent 4b89f95689a8d30265c57b98e1abadde6a392e84 latch: latches on any side, back latch for a removable lid Add back_side to put the hinge or a latch on the back, and latch_front, latch_left and latch_right checkboxes. The latch hardware is modelled in a face frame and placed on each latched side. All latches share one width, clamped to the narrowest latched face; the console lists the latched sides and the number of latches to print. A layout other than front latch with back hinge adds an l token with the side letters to the file name. Replace preview_lid_angle with preview_lid_open in percent: with the hinge 100 turns the lid by 180 degrees, without it lifts the lid by one body height. Presets converted. README updated. diff -r 4b89f95689a8 -r a7a1b12fd6bf README.md --- a/README.md Tue Nov 17 12:37:14 2026 +0100 +++ b/README.md Tue Nov 17 12:53:33 2026 +0100 @@ -1,24 +1,29 @@ # Hinged box A parametric OpenSCAD box with a filament hinge at the back and a hinged -latch at the front. The box is sized by its inner dimensions. The default -of 92 x 92 x 92 mm holds a stack of 90 mm notepad paper standing on edge. +latch at the front. Further latches can go on the left and right sides, +and a latch can replace the hinge for a removable lid. The box is sized +by its inner dimensions. The default of 92 x 92 x 92 mm holds a stack of +90 mm notepad paper standing on edge. See also https://www.wobblyhead.net/projects/hinged_box.html ## Design -The box has three printed parts: body, lid and latch. Three pieces of -filament serve as pins. +The box has three printed parts: body, lid and latch, plus one more +latch for each further latched side. Pieces of filament serve as pins: +one for the hinge and two for each latch. The body is the lower part. The inner part of its wall rises above the seam as a lip, which fits into a recess in the lid and keeps the lid in place when closed. Body and lid share a row of hinge knuckles at the back, with the outer -ones on the body. One filament pin runs through all of them. +ones on the body. One filament pin runs through all of them. With a +latch at the back instead, the lid has no hinge and comes off once all +latches are open. -The latch hangs from two lid knuckles on a second pin. Two body knuckles +Each latch hangs from two lid knuckles on a pin of its own. Two body knuckles below it hold the third piece of filament as a bar. The latch itself sits in the slot between these knuckles. The hook at the bottom of the latch wraps around this bar, and its tip reaches slightly past it, so @@ -30,7 +35,7 @@ and prints flat, or is only as wide as the middle slot and prints standing on its side. The block style is a solid piece with the same rounded and sloped profile as the body knuckles. It reaches from the -latch knuckle down past the hook, and its back lies along the box front. +latch knuckle down past the hook, and its back lies along the box face. Between knuckle and hook, only the knuckle ring and the front wall remain. Below the bar, the cut-out on the wall side runs from the hook tip straight down to the back face, so the bar can leave when the latch @@ -63,11 +68,14 @@ cell adds the column and row count, as in `hinged_box_c3r2_w92d92h92b85_lw40lh20`. A latch middle share other than .33 adds `lm` and the share in percent after the body ratio, as in -`hinged_box_w92d92h92b85lm50_lw40lh20`. +`hinged_box_w92d92h92b85lm50_lw40lh20`. A latch layout other than a +front latch with the back hinge adds `l` and the latched sides, from +front, back, left and right, as in `hinged_box_lfblr_w92d92h92b85_lw40lh20` +for a removable lid latched on all four sides. -After printing, push filament through the hinge knuckles, the latch -knuckles and the bar knuckles. The pin holes are the filament diameter -plus clearance on each side. +After printing, push filament through the hinge knuckles, and the latch +and bar knuckles of each latched side. The pin holes are the filament +diameter plus clearance on each side. ## Main parameters @@ -104,13 +112,19 @@ For the hinge, set `filament_diameter` to the filament used for pins and bar. `hinge_knuckles` is the number of hinge knuckles, an odd number. +`back_side` puts the hinge or a latch on the back. `latch_front`, +`latch_left` and `latch_right` add latches on the other sides, left and +right as seen from the front. Without the hinge, the lid sweep check is +left out. With the hinge, open the side latches before opening the lid. + `latch_style` selects the plate or the block latch. `latch_width` is the -width of the latch in mm. If it is wider than the hinge span, the latch -is narrowed to the span and the console prints a warning with the width -actually used. `latch_middle_ratio` is the share of that width taken by -the middle slot with the latch knuckle; the two outer slots share the -rest. A ratio that leaves any slot narrower than two extrusions is -clamped, with a warning. +width of the latches in mm, the same for all of them. If it is wider +than the narrowest latched face, all latches are narrowed to fit and the +console prints a warning with the width actually used. The console also +gives the number of latches to print. `latch_middle_ratio` is the share +of that width taken by the middle slot with the latch knuckle; the two +outer slots share the rest. A ratio that leaves any slot narrower than +two extrusions is clamped, with a warning. For the plate style, `latch_plate_full` makes the plate span the full latch width, printed flat. Without it, the plate is as wide as the diff -r 4b89f95689a8 -r a7a1b12fd6bf main.json --- a/main.json Tue Nov 17 12:37:14 2026 +0100 +++ b/main.json Tue Nov 17 12:53:33 2026 +0100 @@ -30,7 +30,7 @@ "preview_cut": "false", "preview_hardware": "false", "preview_latch_angle": "0", - "preview_lid_angle": "0", + "preview_lid_open": "0", "wall_lines": "4" }, "calling cards box": { @@ -62,7 +62,7 @@ "preview_cut": "false", "preview_hardware": "true", "preview_latch_angle": "55", - "preview_lid_angle": "8", + "preview_lid_open": "4", "wall_lines": "3" }, "contract bridge cards": { @@ -94,7 +94,7 @@ "preview_cut": "false", "preview_hardware": "true", "preview_latch_angle": "45", - "preview_lid_angle": "30", + "preview_lid_open": "17", "wall_lines": "3" }, "uno cards": { @@ -126,7 +126,7 @@ "preview_cut": "false", "preview_hardware": "true", "preview_latch_angle": "45", - "preview_lid_angle": "30", + "preview_lid_open": "17", "wall_lines": "3" }, "18650x10 battery box": { @@ -160,7 +160,7 @@ "preview_cut": "false", "preview_hardware": "true", "preview_latch_angle": "45", - "preview_lid_angle": "45", + "preview_lid_open": "25", "rows": "2", "wall_lines": "4" } diff -r 4b89f95689a8 -r a7a1b12fd6bf main.scad --- a/main.scad Tue Nov 17 12:37:14 2026 +0100 +++ b/main.scad Tue Nov 17 12:53:33 2026 +0100 @@ -1,6 +1,8 @@ -// hinged box with filament hinge at the back and a hinged latch in front. -// sized by its inner dimensions, e.g. for standing notepad paper. -// x runs front (-x) to back (+x), y left to right, z up. +// hinged box with a filament hinge or a latch at the back and hinged +// latches on any of the other sides. sized by its inner dimensions, e.g. +// for standing notepad paper. +// x runs front (-x) to back (+x), y right (-y) to left (+y) seen from the +// front, z up. // the preview turns the model 90 degrees so the front faces -y. /* [part selection] */ @@ -12,9 +14,9 @@ preview_content = false; // show the filament pins and latch bar in the assembly view preview_hardware = false; -// lid opening angle in the assembly view -preview_lid_angle = 0; // [0:1:180] -// latch opening angle in the assembly view +// lid opening in percent in the assembly view +preview_lid_open = 0; // [0:1:100] +// opening angle of all latches in the assembly view preview_latch_angle = 0; // [0:1:75] /* [box] */ @@ -66,9 +68,17 @@ hinge_lines = 3; // [2:1:8] /* [latch] */ +// back of the box: the hinge, or a latch for a removable lid +back_side = "hinge"; // [hinge, latch] +// latch on the front +latch_front = true; +// latch on the left side, seen from the front +latch_left = false; +// latch on the right side, seen from the front +latch_right = false; // latch shape: a plate in front of the knuckles joining knuckle and hook, or a solid block between the bar knuckles latch_style = "plate"; // [plate, block] -// latch width +// latch width, the same for all latches latch_width = 20; // [8:1:100] // share of the latch width taken by the middle knuckle that carries the latch. the outer knuckles share the rest latch_middle_ratio = .33; // [.1:.01:.9] @@ -134,16 +144,27 @@ lid_h = top_z - seam_z; // hinge +back_hinge = back_side == "hinge"; hinge_x = out_x/2 + knuckle_u; hinge_span = out_y - 2*edge_r; knuckle_l = (hinge_span - (hinge_knuckles - 1)*knuckle_gap)/hinge_knuckles; +// sides that can take a latch: front, back, left, right. side_a turns the +// front to that side, side_d is the distance of its face from the centre, +// side_span the length of the face between the edge roundings +side_name = ["front", "back", "left", "right"]; +side_a = [0, 180, -90, 90]; +side_d = [out_x/2, out_x/2, out_y/2, out_y/2]; +side_span = [out_y - 2*edge_r, out_y - 2*edge_r, out_x - 2*edge_r, out_x - 2*edge_r]; +side_on = [latch_front, !back_hinge, latch_left, latch_right]; +latch_sides = [for (i = [0:3]) if (side_on[i]) i]; + // latch. the latch hangs from lid knuckles and its hook wraps around a -// filament bar held by body knuckles straight below the latch axis. -// in the front frame u runs outward from the front face, z up. -// a latch wider than the hinge span is narrowed to it -latch_w = min(latch_width, hinge_span); -latch_x = -out_x/2 - knuckle_u; +// filament bar held by body knuckles straight below the latch axis. the +// latch hardware is modelled in a face frame: u runs outward from the +// face, y along it, z up. all latches have the same width; one wider than +// the narrowest latched face is narrowed to it +latch_w = min(concat([latch_width], [for (i = latch_sides) side_span[i]])); latch_z = seam_z + knuckle_r + cl; bar_z = seam_z - cl - knuckle_r; bar_r = filament_diameter/2; @@ -162,6 +183,10 @@ _detent(m) < latch_detent ? _hook_angle(m, hi, n - 1) : _hook_angle(lo, m, n - 1); hook_a = _hook_angle(0, 90); +// strings in v joined with sep between them +function _join(v, sep="", i=0) = + i >= len(v) ? "" : str(i > 0 ? sep : "", v[i], _join(v, sep, i + 1)); + // knuckle slots across the latch width: the middle one carries the latch, // the outer ones have a lid knuckle above and a body knuckle below. a // ratio that leaves a slot narrower than 2 extrusions is clamped @@ -199,11 +224,11 @@ nail_d = 3*lw; nail_h = min(8*lw, bar_z - hook_ro - 2*lw - blk_bz); -// how far the latch reaches out from the front face +// how far the latch reaches out from the face latch_front_u = latch_block ? knuckle_u + blk_r : plate_u + plate_t; assert(_detent(90) > latch_detent, "latch_detent too large for the filament bar"); -assert(knuckle_l > 2*lw, "hinge knuckles too short, reduce hinge_knuckles"); +assert(!back_hinge || knuckle_l > 2*lw, "hinge knuckles too short, reduce hinge_knuckles"); assert(body_ih > 0, "inner height too low for the lid"); assert(chamfer_h <= floor_t, "chamfer higher than the floor"); @@ -234,14 +259,18 @@ echo(str("WARNING: body_ratio ", body_ratio, " leaves the lid too low, using ", body_ih/inner_height)); echo("body height", seam_z, "mm, lid height", lid_h, "mm, body ratio", body_ih/inner_height); +echo(str("back: ", back_side, ", latches: ", + len(latch_sides) == 0 ? "none" : _join([for (i = latch_sides) side_name[i]], ", "), + ", print ", len(latch_sides), len(latch_sides) == 1 ? " latch" : " latches")); if (latch_w < latch_width) - echo(str("WARNING: latch_width ", latch_width, " is wider than the hinge span, using ", + echo(str("WARNING: latch_width ", latch_width, " is wider than the narrowest latched face, using ", latch_w)); if (latch_ratio != latch_middle_ratio) echo(str("WARNING: latch_middle_ratio ", latch_middle_ratio, " leaves a latch knuckle narrower than 2 extrusions, using ", latch_ratio)); echo("pin hole", pin_d, "mm, knuckle diameter", 2*knuckle_r, "mm"); -echo("hinge knuckle length", knuckle_l, "mm"); +if (back_hinge) + echo("hinge knuckle length", knuckle_l, "mm"); echo("latch knuckle length: middle", latch_mid, "mm, outer", latch_outer, "mm"); echo(str("latch style ", latch_style, ", printed ", latch_on_side ? "on its side" : "flat")); if (latch_block) { @@ -254,7 +283,7 @@ echo("latch plate thickness", plate_t, "mm", plate_lines, "extrusions, width", plate_w, "mm"); else echo("latch plate thickness", plate_t, "mm", latch_layers, "layers, width", plate_w, "mm"); -echo("latch outer face", latch_front_u, "mm from the front"); +echo("latch outer face", latch_front_u, "mm from the box face"); echo("latch hook reaches", hook_a, "degrees past the bar bottom, detent", _detent(hook_a), "mm"); if (cont_x < content_depth) echo(str("WARNING: content_depth ", content_depth, " is larger than the cell, using ", cont_x)); @@ -263,7 +292,8 @@ if (cont_z < content_height) echo(str("WARNING: content_height ", content_height, " is larger than the inner height, using ", cont_z)); -echo("lid sweep clearance over the content in the front row", sweep_margin, "mm"); +if (back_hinge) + echo("lid sweep clearance over the content in the front row", sweep_margin, "mm"); // rounded box outline, inset by d module _outline(d) { @@ -289,9 +319,9 @@ translate([out_x/2, 0, 0]) children(); } -// frame with u outward from the front face -module _front() { - translate([-out_x/2, 0, 0]) mirror([1, 0, 0]) children(); +// face frame of side i: u outward from the face, y along it +module _side(i) { + rotate([0, 0, side_a[i]]) translate([-side_d[i], 0, 0]) mirror([1, 0, 0]) children(); } function _knuckle_y0(i) = -hinge_span/2 + i*(knuckle_l + knuckle_gap); @@ -301,13 +331,15 @@ cylinder(d=pin_d, h=out_y + 2, center=true); } +// latch pin hole in the face frame module _latch_pin() { - translate([latch_x, 0, latch_z]) rotate([90, 0, 0]) + translate([knuckle_u, 0, latch_z]) rotate([90, 0, 0]) cylinder(d=pin_d, h=latch_w + 2, center=true); } +// bar hole in the face frame module _bar_pin() { - translate([latch_x, 0, bar_z]) rotate([90, 0, 0]) + translate([knuckle_u, 0, bar_z]) rotate([90, 0, 0]) cylinder(d=pin_d, h=latch_w + 2, center=true); } @@ -341,15 +373,16 @@ _outline(skirt_t + cl); _outline(wall_t); } - for (i = [0:2:hinge_knuckles - 1]) - _back() _yslab(_knuckle_y0(i), _knuckle_y0(i) + knuckle_l) - _knuckle(seam_z, seam_z - cl); - for (y0 = latch_outer_y0) - _front() _yslab(y0, y0 + latch_outer) _knuckle(bar_z, bar_z + knuckle_r); + if (back_hinge) + for (i = [0:2:hinge_knuckles - 1]) + _back() _yslab(_knuckle_y0(i), _knuckle_y0(i) + knuckle_l) + _knuckle(seam_z, seam_z - cl); + for (i = latch_sides, y0 = latch_outer_y0) + _side(i) _yslab(y0, y0 + latch_outer) _knuckle(bar_z, bar_z + knuckle_r); } translate([0, 0, floor_t]) linear_extrude(top_z) _outline(wall_t); - _hinge_pin(); - _bar_pin(); + if (back_hinge) _hinge_pin(); + for (i = latch_sides) _side(i) _bar_pin(); } // dividers from the floor to the top of the lip translate([0, 0, floor_t - epsilon]) @@ -386,23 +419,24 @@ difference() { union() { translate([0, 0, top_z]) mirror([0, 0, 1]) _block(lid_h); - for (i = [1:2:hinge_knuckles - 1]) - _back() _yslab(_knuckle_y0(i), _knuckle_y0(i) + knuckle_l) - _knuckle(seam_z, seam_z + cl); - for (y0 = latch_outer_y0) - _front() _yslab(y0, y0 + latch_outer) _knuckle(latch_z, seam_z + cl); + if (back_hinge) + for (i = [1:2:hinge_knuckles - 1]) + _back() _yslab(_knuckle_y0(i), _knuckle_y0(i) + knuckle_l) + _knuckle(seam_z, seam_z + cl); + for (i = latch_sides, y0 = latch_outer_y0) + _side(i) _yslab(y0, y0 + latch_outer) _knuckle(latch_z, seam_z + cl); } translate([0, 0, seam_z - epsilon]) linear_extrude(lid_h - floor_t + epsilon) _outline(wall_t); // recess over the lip, one layer higher than the lip translate([0, 0, seam_z - epsilon]) linear_extrude(lip_h + lh + epsilon) _outline(skirt_t); - _hinge_pin(); - _latch_pin(); + if (back_hinge) _hinge_pin(); + for (i = latch_sides) _side(i) _latch_pin(); } } -// in assembly position, closed. the plate style has a knuckle and a hook +// in the face frame, closed. the plate style has a knuckle and a hook // in the middle slot, joined by a plate in front of the outer knuckles. the // block style is one solid profile across the middle slot module latch() { @@ -485,9 +519,8 @@ } difference() { - _front() - if (latch_block) _yslab(-latch_mid/2, latch_mid/2) _block(); - else _plate(); + if (latch_block) _yslab(-latch_mid/2, latch_mid/2) _block(); + else _plate(); _latch_pin(); } } @@ -506,18 +539,25 @@ cylinder(d=filament_diameter, h=l, center=true); } +// the lid turns about the hinge axis with the back hinge, otherwise it +// lifts straight up. in the face frame, a latch opens with its bottom +// swinging outward module _assembly() { + lid_a = back_hinge ? 1.8*preview_lid_open : 0; + lid_lift = back_hinge ? 0 : preview_lid_open/100*seam_z; color("steelblue") body(); if (preview_hardware && $preview) { - _filament(hinge_x, seam_z, hinge_span); - _filament(latch_x, bar_z, latch_w); + if (back_hinge) _filament(hinge_x, seam_z, hinge_span); + for (i = latch_sides) _side(i) _filament(knuckle_u, bar_z, latch_w); } - translate([hinge_x, 0, seam_z]) rotate([0, preview_lid_angle, 0]) + translate([hinge_x, 0, seam_z + lid_lift]) rotate([0, lid_a, 0]) translate([-hinge_x, 0, -seam_z]) { color("lightsteelblue") lid(); - if (preview_hardware && $preview) _filament(latch_x, latch_z, latch_w); - translate([latch_x, 0, latch_z]) rotate([0, preview_latch_angle, 0]) - translate([-latch_x, 0, -latch_z]) color("orange") latch(); + for (i = latch_sides) _side(i) { + if (preview_hardware && $preview) _filament(knuckle_u, latch_z, latch_w); + translate([knuckle_u, 0, latch_z]) rotate([0, -preview_latch_angle, 0]) + translate([-knuckle_u, 0, -latch_z]) color("orange") latch(); + } } if (preview_content && $preview) _content(); } @@ -526,8 +566,8 @@ // and with preview_cut remove the +x half, the right half seen from the // front. exports stay unturned module part_view() { - cut_s = max(out_x/2 + latch_front_u, top_z) - + (preview_lid_angle > 0 ? out_x : 0) + 1; + cut_s = max(max(out_x, out_y)/2 + latch_front_u, hinge_x + knuckle_r, top_z) + + (preview_lid_open > 0 ? (back_hinge ? out_x : seam_z) : 0) + 1; if ($preview) difference() { rotate([0, 0, 90]) children(); @@ -552,10 +592,10 @@ // on its side: the width along z, standing on the print bed else if (latch_on_side) translate([0, 0, latch_mid/2]) rotate([90, 0, 0]) - translate([-latch_x, 0, -latch_z]) latch(); + translate([-knuckle_u, 0, -latch_z]) latch(); // flat: the plate face on the print bed - else translate([latch_z, 0, out_x/2 + latch_front_u]) - rotate([0, -90, 0]) latch(); + else translate([-latch_z, 0, latch_front_u]) + rotate([0, 90, 0]) latch(); } main(); @@ -566,6 +606,9 @@ part == "latch" ? str(latch_block ? "block" : latch_plate_full ? "plate" : "plate-middle", "_") : "", columns > 1 || rows > 1 ? str("c", columns, "r", rows, "_") : "", + // latched sides, only when they differ from the front latch and back hinge + side_on == [true, false, false, false] ? "" : + str("l", _join([for (i = latch_sides) "fblr"[i]]), "_"), "w", inner_width, "d", inner_depth, "h", inner_height, "b", round(100*body_ih/inner_height), // latch middle share, only when it differs from the default