wobblyhead hg > 3dprints > hinged_box
annotate main.scad @ 7:1933892bab51
adjusted default
| author | ark |
|---|---|
| date | 2026-11-17 08:50 +0100 |
| parents | f2694e49cec1 |
| children | ac8f2ecb6c18 |
| rev | line source |
|---|---|
| 0 | 1 // hinged box with filament hinge at the back and a hinged latch in front. |
| 2 // sized by its inner dimensions, e.g. for standing notepad paper. | |
| 3 // x runs front (-x) to back (+x), y left to right, z up. | |
| 4 | |
| 5 /* [part selection] */ | |
| 6 // part to show or export | |
| 7 part = "all"; // [all, body, lid, latch] | |
| 8 // cut away the -y half in preview | |
| 1 | 9 preview_cut = false; |
| 6 | 10 // show a content mockup in each cell in the assembly view |
| 11 preview_content = false; | |
| 0 | 12 // show the filament pins and latch bar in the assembly view |
| 13 preview_hardware = false; | |
| 14 // lid opening angle in the assembly view | |
| 15 preview_lid_angle = 0; // [0:1:180] | |
| 16 // latch opening angle in the assembly view | |
| 17 preview_latch_angle = 0; // [0:1:75] | |
| 18 | |
| 19 /* [box] */ | |
| 6 | 20 // inner size front to back, of one cell |
| 21 inner_depth = 92; // [10:.1:300] | |
| 22 // inner size left to right of one cell | |
| 23 inner_width = 92; // [10:.1:300] | |
| 0 | 24 // inner height, floor to lid ceiling |
| 6 | 25 inner_height = 92; // [10:.1:300] |
| 0 | 26 // share of the inner height taken by the body |
| 2 | 27 body_ratio = .85; // [.1:.01:.99] |
| 0 | 28 // radius of the vertical outer edges |
| 29 edge_radius = 2; // [0:.1:10] | |
| 6 | 30 |
| 31 /* [dividers] */ | |
| 32 // number of cells left to right. inner_width is the width of one cell | |
| 33 columns = 1; // [1:1:10] | |
| 34 // number of cells front to back. inner_depth is the depth of one cell | |
| 35 rows = 1; // [1:1:10] | |
| 36 // divider wall thickness in extrusions | |
| 37 divider_lines = 2; // [1:1:10] | |
| 38 | |
| 39 /* [content] */ | |
| 40 // content size front to back, for the preview mockup and the lid sweep check. at most the cell depth | |
| 41 content_depth = 90; // [1:.1:300] | |
| 42 // content size left to right, for the preview mockup. at most the cell width | |
| 43 content_width = 90; // [1:.1:300] | |
| 44 // content height, for the preview mockup and the lid sweep check. at most the inner height | |
| 45 content_height = 90; // [1:.1:300] | |
| 0 | 46 |
| 47 /* [walls] */ | |
| 48 // wall thickness in extrusions | |
| 49 wall_lines = 4; // [2:1:10] | |
| 50 // lip thickness in extrusions: the inner part of the body wall, raised into the lid | |
| 51 lip_lines = 2; // [1:1:8] | |
| 52 // lip height in layers | |
| 53 lip_layers = 4; // [1:1:20] | |
| 54 // floor and lid top thickness in layers | |
| 55 floor_layers = 6; // [2:1:20] | |
| 1 | 56 // chamfer height in layers at the build plate edges of body and lid. each layer steps in by one layer height |
| 57 chamfer_layers = 3; // [0:1:10] | |
| 0 | 58 |
| 59 /* [hinge] */ | |
| 60 // diameter of the filament used as hinge pin | |
| 7 | 61 filament_diameter = 1.85; // [1:.05:3] |
| 0 | 62 // number of hinge knuckles. the body gets the outer ones |
| 63 hinge_knuckles = 5; // [3:2:15] | |
| 64 // knuckle wall around the pin hole, in extrusions | |
| 65 hinge_lines = 3; // [2:1:8] | |
| 66 | |
| 67 /* [latch] */ | |
| 68 // latch width | |
| 69 latch_width = 20; // [8:1:100] | |
| 70 // latch plate thickness in layers, printed flat | |
| 71 latch_layers = 8; // [4:1:20] | |
| 72 // radial overlap the hook tip has to pass at the filament bar. 0 for a free swinging latch | |
| 73 latch_detent = .3; // [0:.05:.7] | |
| 74 // grip tab length below the hook | |
| 75 latch_grip = 5; // [0:.5:20] | |
|
5
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
76 // hook wall around the filament bar, in extrusions |
|
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
77 latch_hook_lines = 3; // [2:1:8] |
| 0 | 78 |
| 79 /* [print settings] */ | |
| 80 line_width = .4; // [0:.01:1] | |
| 81 layer_height = .2; // [0:.01:.5] | |
| 82 clearance = .1; // [0:.01:.5] | |
| 83 | |
| 84 module dummy() {} | |
| 85 | |
| 86 epsilon = .001; | |
| 87 $fn = $preview ? 60 : 180; | |
| 88 | |
| 89 lw = line_width; | |
| 90 lh = layer_height; | |
| 91 cl = clearance; | |
| 92 | |
| 93 // walls | |
| 94 wall_t = wall_lines*lw; | |
| 95 // lid wall part that overlaps the lip from outside | |
| 96 skirt_t = (wall_lines - lip_lines)*lw; | |
| 97 lip_h = lip_layers*lh; | |
| 98 floor_t = floor_layers*lh; | |
| 1 | 99 chamfer_h = chamfer_layers*lh; |
| 6 | 100 // dividers and the total inner size over all cells |
| 101 div_t = divider_lines*lw; | |
| 102 in_x = rows*inner_depth + (rows - 1)*div_t; | |
| 103 in_y = columns*inner_width + (columns - 1)*div_t; | |
| 104 out_x = in_x + 2*wall_t; | |
| 105 out_y = in_y + 2*wall_t; | |
| 0 | 106 edge_r = min(edge_radius, min(out_x, out_y)/2 - epsilon); |
| 107 | |
| 108 // knuckles, shared by hinge and latch | |
| 109 pin_d = filament_diameter + 2*cl; | |
| 110 knuckle_r = pin_d/2 + hinge_lines*lw; | |
| 111 // axis distance from the outer wall face | |
| 112 knuckle_u = knuckle_r + 2*cl; | |
| 113 // axial gap between knuckles | |
| 114 knuckle_gap = 2*cl; | |
| 115 | |
| 2 | 116 // heights. the seam between body and lid sits on a layer boundary. |
| 117 // the lid needs room for the wall around the latch pin hole, which sits | |
| 118 // one knuckle radius plus clearance above the seam, and for one layer of | |
| 119 // skirt wall above the recess over the lip. a body ratio that leaves less | |
| 120 // is lowered to the highest layer that fits | |
| 121 lid_min_h = max(2*knuckle_r + cl, floor_t + lip_h + 2*lh); | |
| 122 body_ih_max = floor((inner_height + floor_t - lid_min_h)/lh)*lh; | |
| 123 body_ih_req = round(body_ratio*inner_height/lh)*lh; | |
| 124 body_ih = min(body_ih_req, body_ih_max); | |
| 125 seam_z = floor_t + body_ih; | |
| 126 top_z = floor_t + inner_height + floor_t; | |
| 127 lid_h = top_z - seam_z; | |
| 128 | |
| 0 | 129 // hinge |
| 130 hinge_x = out_x/2 + knuckle_u; | |
| 131 hinge_span = out_y - 2*edge_r; | |
| 132 knuckle_l = (hinge_span - (hinge_knuckles - 1)*knuckle_gap)/hinge_knuckles; | |
| 133 | |
| 134 // latch. the flap hangs from lid knuckles and its hook wraps around a | |
| 135 // filament bar held by body knuckles straight below the flap axis. | |
|
5
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
136 // in the front frame u runs outward from the front face, z up. |
|
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
137 // a latch wider than the hinge span is narrowed to it |
|
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
138 latch_w = min(latch_width, hinge_span); |
| 0 | 139 latch_x = -out_x/2 - knuckle_u; |
| 140 latch_z = seam_z + knuckle_r + cl; | |
| 141 bar_z = seam_z - cl - knuckle_r; | |
| 142 bar_r = filament_diameter/2; | |
| 143 // distance between flap axis and bar axis | |
| 144 bar_h = latch_z - bar_z; | |
| 145 hook_ri = bar_r + cl; | |
|
5
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
146 hook_ro = hook_ri + latch_hook_lines*lw; |
| 0 | 147 // outer radius of the bar minus radius of the hook tip, both around the |
| 148 // flap axis, for a hook reaching angle b past the bottom of the bar | |
| 149 function _detent(b) = | |
| 150 bar_h + bar_r - norm([hook_ri*sin(b), bar_h + hook_ri*cos(b)]); | |
| 151 // bisection for the angle that gives latch_detent | |
| 152 function _hook_angle(lo, hi, n=40) = | |
| 153 n == 0 ? (lo + hi)/2 : | |
| 154 let(m = (lo + hi)/2) | |
| 155 _detent(m) < latch_detent ? _hook_angle(m, hi, n - 1) : _hook_angle(lo, m, n - 1); | |
| 156 hook_a = _hook_angle(0, 90); | |
| 157 plate_t = latch_layers*lh; | |
| 158 plate_u = knuckle_u + knuckle_r + 2*cl; | |
| 159 plate_bz = bar_z - hook_ro - latch_grip; | |
| 4 | 160 latch_slot = (latch_w - 2*knuckle_gap)/3; |
| 0 | 161 // y start of the two outer latch slots |
| 4 | 162 latch_outer_y0 = [-latch_w/2, latch_slot/2 + knuckle_gap]; |
| 0 | 163 |
| 164 assert(_detent(90) > latch_detent, "latch_detent too large for the filament bar"); | |
| 165 assert(knuckle_l > 2*lw, "hinge knuckles too short, reduce hinge_knuckles"); | |
| 2 | 166 assert(body_ih > 0, "inner height too low for the lid"); |
| 1 | 167 assert(chamfer_h <= floor_t, "chamfer higher than the floor"); |
| 0 | 168 |
| 6 | 169 // cell centres: x for row i from the front, y for column j from the left |
| 170 function _cell_x(i) = -in_x/2 + inner_depth/2 + i*(inner_depth + div_t); | |
| 171 function _cell_y(j) = -in_y/2 + inner_width/2 + j*(inner_width + div_t); | |
| 172 | |
| 173 // content, clamped to one cell | |
| 174 cont_x = min(content_depth, inner_depth); | |
| 175 cont_y = min(content_width, inner_width); | |
| 176 cont_z = min(content_height, inner_height); | |
| 177 | |
| 178 // lid sweep over the content centred in the front row, the one furthest | |
| 179 // from the hinge: radius of the lowest lid ceiling point over the content | |
| 180 // minus radius of the content's front top corner | |
| 0 | 181 sweep_margin = |
| 6 | 182 norm([hinge_x + in_x/2, lip_h + lh]) |
| 183 - norm([hinge_x - _cell_x(0) + cont_x/2, floor_t + cont_z - seam_z]); | |
| 0 | 184 |
| 185 echo("wall thickness", wall_t, "mm", wall_lines, "extrusions"); | |
| 186 echo("lip thickness", wall_t - skirt_t - cl, "mm, height", lip_h, "mm"); | |
| 6 | 187 if (columns > 1 || rows > 1) |
| 188 echo("divider thickness", div_t, "mm", divider_lines, "extrusions"); | |
| 189 echo("inner size", in_x, in_y, inner_height, "mm"); | |
| 0 | 190 echo("outer size", out_x, out_y, top_z, "mm"); |
| 1 | 191 echo("chamfer", chamfer_h, "mm", chamfer_layers, "layers"); |
| 2 | 192 if (body_ih < body_ih_req) |
| 193 echo(str("WARNING: body_ratio ", body_ratio, " leaves the lid too low, using ", | |
| 194 body_ih/inner_height)); | |
| 195 echo("body height", seam_z, "mm, lid height", lid_h, "mm, body ratio", body_ih/inner_height); | |
|
5
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
196 if (latch_w < latch_width) |
|
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
197 echo(str("WARNING: latch_width ", latch_width, " is wider than the hinge span, using ", |
|
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
198 latch_w)); |
| 0 | 199 echo("pin hole", pin_d, "mm, knuckle diameter", 2*knuckle_r, "mm"); |
| 200 echo("hinge knuckle length", knuckle_l, "mm"); | |
| 201 echo("latch plate outer face", plate_u + plate_t, "mm from the front"); | |
| 202 echo("latch hook reaches", hook_a, "degrees past the bar bottom, detent", _detent(hook_a), "mm"); | |
| 6 | 203 if (cont_x < content_depth) |
| 204 echo(str("WARNING: content_depth ", content_depth, " is larger than the cell, using ", cont_x)); | |
| 205 if (cont_y < content_width) | |
| 206 echo(str("WARNING: content_width ", content_width, " is larger than the cell, using ", cont_y)); | |
| 207 if (cont_z < content_height) | |
| 208 echo(str("WARNING: content_height ", content_height, " is larger than the inner height, using ", | |
| 209 cont_z)); | |
| 210 echo("lid sweep clearance over the content in the front row", sweep_margin, "mm"); | |
| 0 | 211 |
| 212 // rounded box outline, inset by d | |
| 213 module _outline(d) { | |
| 214 r = max(edge_r - d, 0); | |
| 215 offset(r=r) square([out_x - 2*d - 2*r, out_y - 2*d - 2*r], center=true); | |
| 216 } | |
| 217 | |
| 1 | 218 // outer box shape of height h, the bottom edge chamfered in steps of one |
| 219 // layer, each step inset by one layer height | |
| 220 module _block(h) { | |
| 221 for (i = [0:1:chamfer_layers - 1]) | |
| 222 translate([0, 0, i*lh]) linear_extrude(lh + epsilon) _outline((chamfer_layers - i)*lh); | |
| 223 translate([0, 0, chamfer_h]) linear_extrude(h - chamfer_h) _outline(0); | |
| 224 } | |
| 225 | |
| 0 | 226 // extrude a 2d profile drawn in x/z between y0 and y1 |
| 227 module _yslab(y0, y1) { | |
| 228 translate([0, y1, 0]) rotate([90, 0, 0]) linear_extrude(y1 - y0) children(); | |
| 229 } | |
| 230 | |
| 231 // frame with u outward from the back face | |
| 232 module _back() { | |
| 233 translate([out_x/2, 0, 0]) children(); | |
| 234 } | |
| 235 | |
| 236 // frame with u outward from the front face | |
| 237 module _front() { | |
| 238 translate([-out_x/2, 0, 0]) mirror([1, 0, 0]) children(); | |
| 239 } | |
| 240 | |
| 241 function _knuckle_y0(i) = -hinge_span/2 + i*(knuckle_l + knuckle_gap); | |
| 242 | |
| 243 module _hinge_pin() { | |
| 244 translate([hinge_x, 0, seam_z]) rotate([90, 0, 0]) | |
| 245 cylinder(d=pin_d, h=out_y + 2, center=true); | |
| 246 } | |
| 247 | |
| 248 module _latch_pin() { | |
| 249 translate([latch_x, 0, latch_z]) rotate([90, 0, 0]) | |
| 4 | 250 cylinder(d=pin_d, h=latch_w + 2, center=true); |
| 0 | 251 } |
| 252 | |
| 253 module _bar_pin() { | |
| 254 translate([latch_x, 0, bar_z]) rotate([90, 0, 0]) | |
| 4 | 255 cylinder(d=pin_d, h=latch_w + 2, center=true); |
| 0 | 256 } |
| 257 | |
| 258 module body() { | |
| 6 | 259 // divider walls between the cells, reaching into the outer wall |
| 260 module _dividers() { | |
| 261 for (j = [1:1:columns - 1]) | |
| 262 translate([-in_x/2 - epsilon, _cell_y(j) - inner_width/2 - div_t]) | |
| 263 square([in_x + 2*epsilon, div_t]); | |
| 264 for (i = [1:1:rows - 1]) | |
| 265 translate([_cell_x(i) - inner_depth/2 - div_t, -in_y/2 - epsilon]) | |
| 266 square([div_t, in_y + 2*epsilon]); | |
| 267 } | |
| 268 | |
| 0 | 269 // knuckle at height z with a web down to the wall up to z1, chamfered |
| 270 // below for printing | |
| 271 module _knuckle(z, z1) { | |
| 272 hull() { | |
| 273 translate([knuckle_u, z]) circle(r=knuckle_r); | |
| 274 translate([-epsilon, z - knuckle_r - knuckle_u]) | |
| 275 square([epsilon, z1 - (z - knuckle_r - knuckle_u)]); | |
| 276 } | |
| 277 } | |
| 278 | |
| 279 difference() { | |
| 280 union() { | |
| 1 | 281 _block(seam_z); |
| 0 | 282 translate([0, 0, seam_z - epsilon]) |
| 283 linear_extrude(lip_h + epsilon) | |
| 284 difference() { | |
| 285 _outline(skirt_t + cl); | |
| 286 _outline(wall_t); | |
| 287 } | |
| 288 for (i = [0:2:hinge_knuckles - 1]) | |
| 289 _back() _yslab(_knuckle_y0(i), _knuckle_y0(i) + knuckle_l) | |
| 290 _knuckle(seam_z, seam_z - cl); | |
| 291 for (y0 = latch_outer_y0) | |
| 292 _front() _yslab(y0, y0 + latch_slot) _knuckle(bar_z, bar_z + knuckle_r); | |
| 293 } | |
| 294 translate([0, 0, floor_t]) linear_extrude(top_z) _outline(wall_t); | |
| 295 _hinge_pin(); | |
| 296 _bar_pin(); | |
| 297 } | |
| 6 | 298 // dividers from the floor to the top of the lip |
| 299 translate([0, 0, floor_t - epsilon]) | |
| 300 linear_extrude(seam_z + lip_h - floor_t + epsilon) _dividers(); | |
| 0 | 301 } |
| 302 | |
| 303 // in assembly position, closed | |
| 304 module lid() { | |
| 305 // knuckle at height z with a web up to the wall from z0, chamfered | |
| 6 | 306 // towards the lid top for printing upside down. the web joins the wall |
| 307 // through a strip one epsilon thick just inside the outer face, so it | |
| 308 // stays out of the body wall below the seam. where the web reaches the | |
| 309 // edge chamfer at the lid top, a block fills the chamfer. a knuckle that | |
| 310 // would reach past the lid top is cut off there and stands on the print | |
| 311 // bed | |
| 0 | 312 module _knuckle(z, z0) { |
| 6 | 313 web_z1 = z + knuckle_r + knuckle_u; |
| 314 fill_z0 = max(z0, top_z - chamfer_h); | |
| 2 | 315 intersection() { |
| 6 | 316 union() { |
| 317 hull() { | |
| 318 translate([knuckle_u, z]) circle(r=knuckle_r); | |
| 319 translate([-epsilon, z0]) square([epsilon, web_z1 - z0]); | |
| 320 } | |
| 321 if (web_z1 > fill_z0) | |
| 322 translate([-chamfer_h - epsilon, fill_z0]) | |
| 323 square([chamfer_h + epsilon, web_z1 - fill_z0]); | |
| 2 | 324 } |
| 6 | 325 translate([-epsilon - 1, z - knuckle_r - 1]) |
| 326 square([epsilon + knuckle_u + knuckle_r + 2, top_z - (z - knuckle_r - 1)]); | |
| 0 | 327 } |
| 328 } | |
| 329 | |
| 330 difference() { | |
| 331 union() { | |
| 1 | 332 translate([0, 0, top_z]) mirror([0, 0, 1]) _block(lid_h); |
| 0 | 333 for (i = [1:2:hinge_knuckles - 1]) |
| 334 _back() _yslab(_knuckle_y0(i), _knuckle_y0(i) + knuckle_l) | |
| 335 _knuckle(seam_z, seam_z + cl); | |
| 336 for (y0 = latch_outer_y0) | |
| 337 _front() _yslab(y0, y0 + latch_slot) _knuckle(latch_z, seam_z + cl); | |
| 338 } | |
| 339 translate([0, 0, seam_z - epsilon]) | |
| 340 linear_extrude(lid_h - floor_t + epsilon) _outline(wall_t); | |
| 341 // recess over the lip, one layer higher than the lip | |
| 342 translate([0, 0, seam_z - epsilon]) | |
| 343 linear_extrude(lip_h + lh + epsilon) _outline(skirt_t); | |
| 344 _hinge_pin(); | |
| 345 _latch_pin(); | |
| 346 } | |
| 347 } | |
| 348 | |
| 349 // in assembly position, closed | |
| 350 module latch() { | |
| 351 // hook around the bar, from the plate side down under the bar and | |
|
5
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
352 // hook_a degrees up its wall side |
| 0 | 353 module _hook() { |
| 354 tip_a = 270 - hook_a; | |
| 355 difference() { | |
|
5
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
356 hull() { |
|
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
357 translate([knuckle_u, bar_z]) circle(r=hook_ro); |
|
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
358 translate([knuckle_u, bar_z - hook_ro]) |
|
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
359 square([plate_u - knuckle_u + epsilon, hook_ro]); |
| 0 | 360 } |
| 361 translate([knuckle_u, bar_z]) circle(r=hook_ri); | |
| 362 // open wedge over the top and the wall side of the bar | |
| 363 translate([knuckle_u, bar_z]) | |
| 364 polygon(concat([[0, 0]], | |
| 365 [for (a = [0:10:tip_a]) 2*hook_ro*[cos(a), sin(a)]], | |
| 366 [2*hook_ro*[cos(tip_a), sin(tip_a)]])); | |
| 367 } | |
| 368 } | |
| 369 | |
| 370 difference() { | |
| 371 _front() union() { | |
| 4 | 372 _yslab(-latch_w/2, latch_w/2) |
| 0 | 373 translate([plate_u, plate_bz]) square([plate_t, latch_z - plate_bz]); |
| 374 _yslab(-latch_slot/2, latch_slot/2) { | |
| 375 hull() { | |
| 376 translate([knuckle_u, latch_z]) circle(r=knuckle_r); | |
| 377 translate([plate_u, latch_z - knuckle_r]) square([plate_t, knuckle_r]); | |
| 378 } | |
| 379 _hook(); | |
| 380 } | |
| 381 } | |
| 382 _latch_pin(); | |
| 383 } | |
| 384 } | |
| 385 | |
| 6 | 386 // content block centred in each cell |
| 387 module _content() { | |
| 0 | 388 color("white", .6) |
| 6 | 389 for (i = [0:1:rows - 1], j = [0:1:columns - 1]) |
| 390 translate([_cell_x(i) - cont_x/2, _cell_y(j) - cont_y/2, floor_t]) | |
| 391 cube([cont_x, cont_y, cont_z]); | |
| 0 | 392 } |
| 393 | |
| 394 // filament of length l along y at x, z | |
| 395 module _filament(x, z, l) { | |
| 396 color("dimgray") translate([x, 0, z]) rotate([90, 0, 0]) | |
| 397 cylinder(d=filament_diameter, h=l, center=true); | |
| 398 } | |
| 399 | |
| 400 module _assembly() { | |
| 401 color("steelblue") body(); | |
| 402 if (preview_hardware && $preview) { | |
| 403 _filament(hinge_x, seam_z, hinge_span); | |
| 4 | 404 _filament(latch_x, bar_z, latch_w); |
| 0 | 405 } |
| 406 translate([hinge_x, 0, seam_z]) rotate([0, preview_lid_angle, 0]) | |
| 407 translate([-hinge_x, 0, -seam_z]) { | |
| 408 color("lightsteelblue") lid(); | |
| 4 | 409 if (preview_hardware && $preview) _filament(latch_x, latch_z, latch_w); |
| 0 | 410 translate([latch_x, 0, latch_z]) rotate([0, preview_latch_angle, 0]) |
| 411 translate([-latch_x, 0, -latch_z]) color("orange") latch(); | |
| 412 } | |
| 6 | 413 if (preview_content && $preview) _content(); |
| 0 | 414 } |
| 415 | |
| 416 module part_view() { | |
| 417 cut_s = max(out_x/2 + plate_u + plate_t, top_z) | |
| 418 + (preview_lid_angle > 0 ? out_x : 0) + 1; | |
| 419 if ($preview && preview_cut) | |
| 420 difference() { | |
| 421 children(); | |
| 422 translate([-cut_s, -cut_s, -cut_s]) cube([2*cut_s, cut_s, 2*cut_s]); | |
| 423 } | |
| 424 else | |
| 425 children(); | |
| 426 } | |
| 427 | |
| 428 module main() { | |
| 429 if (part == "all") | |
| 430 part_view() _assembly(); | |
| 431 else if (part == "body") | |
| 432 part_view() body(); | |
| 433 else if (part == "lid") | |
| 434 part_view() | |
| 435 if ($preview) lid(); | |
| 436 else translate([0, 0, top_z]) rotate([180, 0, 0]) lid(); | |
| 437 else if (part == "latch") | |
| 438 part_view() | |
| 439 if ($preview) latch(); | |
| 440 else translate([latch_z, 0, out_x/2 + plate_u + plate_t]) | |
| 441 rotate([0, -90, 0]) latch(); | |
| 442 } | |
| 443 | |
| 444 main(); | |
| 445 | |
| 446 function paramstring(prefix="", suffix="") = str( | |
| 447 prefix, | |
| 448 part == "all" ? "" : str(part, "_"), | |
| 6 | 449 columns > 1 || rows > 1 ? str("c", columns, "r", rows, "_") : "", |
| 0 | 450 "w", inner_width, "d", inner_depth, "h", inner_height, |
| 2 | 451 "b", round(100*body_ih/inner_height), |
| 0 | 452 "_lw", round(100*line_width), "lh", round(100*layer_height), |
| 453 suffix); | |
| 454 | |
| 455 echo(paramstring("hinged_box_")); |
