# Hinged box

A parametric OpenSCAD box with a filament hinge at the back and a hinged
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, 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. With a
latch at the back instead, the lid has no hinge and comes off once all
latches are open.

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
the latch snaps over the bar when closed.

The latch comes in two styles. The plate style joins knuckle and hook
with a plate in front of the outer knuckles, and a grip tab below the
hook gives a finger hold. The plate either spans the full latch width
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 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
opens. A notch at the bottom edge of the back face takes a fingernail.
The block prints standing on its side.

Wall, floor and knuckle sizes are set in extrusions and layers. The model
converts them with the line width and layer height from the print
settings.

## Use

Open `main.scad` in OpenSCAD and set the parameters in the Customizer. 
Several presets are stored in `main.json`.

Select the part to export with the `part` setting. For export, the lid is
turned upside down, and the latch is laid flat or stood on its side as
its style needs, both ready to print. The body prints as it stands. All
parts use the same parameters, so export all three without changing
anything else.

The console lists the derived sizes: wall thickness, outer size, body and
lid height, pin hole diameter, knuckle length, latch detent and the
clearance of the lid over the content when it opens. The last echo
line is a file name that encodes the main parameters, for example
`hinged_box_w920d920h920b85_lw40lh20`. The inner sizes are given in
tenths of a millimetre. With a single part selected, the name includes
the part, as in `hinged_box_lid_w920d920h920b85_lw40lh20`. The latch
name adds its style: `plate`, `plate-middle` or `block`, as in
`hinged_box_latch_block_w920d920h920b85_lw40lh20`. A box with more than
one cell adds the column and row count, as in
`hinged_box_c3r2_w920d920h920b85_lw40lh20`. A latch middle share other
than .33 adds `lm` and the share in percent after the body ratio, as in
`hinged_box_w920d920h920b85lm50_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_w920d920h920b85_lw40lh20` for a removable lid latched
on all four sides.

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

The Customizer comments describe every parameter, including edge radius,
lip size, chamfer and the preview options. The ones below set the box.

`inner_depth`, `inner_width` and `inner_height` give the inner size in mm,
front to back, left to right and floor to lid ceiling. For a paper stack,
`inner_width` is the thickness of the stack.

`columns` and `rows` divide the body into cells, columns left to right and
rows front to back as seen from the top front. `inner_width` and
`inner_depth` are then the size of one cell, and the box grows by the
cells and the divider walls between them. The dividers are
`divider_lines` extrusions thick and reach from the floor to the top of
the lip. The preview mockup puts the content in each cell, and the lid
sweep check uses the front row.

`content_depth`, `content_width` and `content_height` give the size of
what goes into one cell, such as a paper stack. The preview mockup shows
it with `preview_content`, and the lid sweep check uses depth and height.
Nothing else uses them. A size larger than the cell or the inner height
is reduced to fit, and the console prints a warning with the size
actually used.

`body_ratio` is the share of the inner height taken by the body. The lid
needs enough height for the latch knuckles and the lip recess. If the
ratio leaves less, the body is made lower and the console prints a
warning with the ratio actually used.

Walls are `wall_lines` extrusions thick. Floor and lid top are
`floor_layers` layers.

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 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
middle slot and the latch prints on its side. `latch_layers` sets the
plate thickness in layers. On its side, that thickness is rounded up to
whole extrusions. `latch_grip` is the length of the grip tab below the
hook, or for the block style, how far the block reaches below the hook.

The hook tip has to pass `latch_detent` mm of overlap at the bar. With 0
the latch swings freely. `latch_hook_lines` sets the hook wall around
the bar in extrusions. On the block, the wall in front of the bar is the
larger of `latch_hook_lines` and `hinge_lines`.

`line_width` and `layer_height` are the extrusion width and layer height
the walls are built from. `clearance` is the gap between moving parts and
around the pins.

## Checks

The model stops with an error if the hinge knuckles get too short, the
detent is too large for the bar, the chamfer is higher than the floor, or
the inner height leaves no room for the body.
