changeset 11:7bef1d0cb914 default tip

updated defaults, added render shell script
author ark
date 2026-11-18 02:35 +0100
parents a7a1b12fd6bf
children
files README.md main.json main.scad render.sh
diffstat 4 files changed, 275 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/README.md	Tue Nov 17 12:53:33 2026 +0100
+++ b/README.md	Wed Nov 18 02:35:11 2026 +0100
@@ -48,8 +48,8 @@
 
 ## Use
 
-Open `main.scad` in OpenSCAD and set the parameters in the Customizer. Two
-presets are stored in `main.json`: "cardbox 45" and "calling cards box".
+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
@@ -61,17 +61,19 @@
 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_w92d92h92b85_lw40lh20`. With a single part selected, the name
-includes the part, as in `hinged_box_lid_w92d92h92b85_lw40lh20`. The
-latch name adds its style: `plate`, `plate-middle` or `block`, as in
-`hinged_box_latch_block_w92d92h92b85_lw40lh20`. A box with more than one
-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`. A latch layout other than a
+`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_w92d92h92b85_lw40lh20`
-for a removable lid latched on all four sides.
+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
--- a/main.json	Tue Nov 17 12:53:33 2026 +0100
+++ b/main.json	Wed Nov 18 02:35:11 2026 +0100
@@ -1,7 +1,7 @@
 {
     "fileFormatVersion": "1",
     "parameterSets": {
-        "cardbox 45": {
+        "gametiles 45x45": {
             "body_ratio": "0.89000000000000001",
             "chamfer_layers": "3",
             "clearance": "0.10000000000000001",
@@ -33,7 +33,7 @@
             "preview_lid_open": "0",
             "wall_lines": "4"
         },
-        "calling cards box": {
+        "calling cards": {
             "body_ratio": "0.98999999999999999",
             "chamfer_layers": "3",
             "clearance": "0.10000000000000001",
@@ -49,20 +49,22 @@
             "inner_height": "86",
             "inner_width": "12",
             "latch_detent": "0.29999999999999999",
-            "latch_grip": "5",
+            "latch_grip": "3.5",
             "latch_hook_lines": "2",
             "latch_layers": "8",
+            "latch_plate_full": "false",
+            "latch_style": "block",
             "latch_width": "10",
             "layer_height": "0.20000000000000001",
             "line_width": "0.40000000000000002",
             "lip_layers": "4",
             "lip_lines": "2",
             "part": "all",
-            "preview_content": "true",
+            "preview_content": "false",
             "preview_cut": "false",
-            "preview_hardware": "true",
-            "preview_latch_angle": "55",
-            "preview_lid_open": "4",
+            "preview_hardware": "false",
+            "preview_latch_angle": "0",
+            "preview_lid_open": "0",
             "wall_lines": "3"
         },
         "contract bridge cards": {
@@ -129,7 +131,7 @@
             "preview_lid_open": "17",
             "wall_lines": "3"
         },
-        "18650x10 battery box": {
+        "batteries 18650x10": {
             "body_ratio": "0.90000000000000002",
             "chamfer_layers": "3",
             "clearance": "0.10000000000000001",
@@ -150,6 +152,7 @@
             "latch_grip": "5",
             "latch_hook_lines": "3",
             "latch_layers": "8",
+            "latch_style": "block",
             "latch_width": "30",
             "layer_height": "0.20000000000000001",
             "line_width": "0.40000000000000002",
@@ -163,6 +166,132 @@
             "preview_lid_open": "25",
             "rows": "2",
             "wall_lines": "4"
+        },
+        "memo block": {
+            "back_side": "hinge",
+            "body_ratio": "0.84999999999999998",
+            "chamfer_layers": "3",
+            "clearance": "0.10000000000000001",
+            "columns": "1",
+            "content_depth": "90",
+            "content_height": "90",
+            "content_width": "90",
+            "divider_lines": "2",
+            "edge_radius": "2",
+            "filament_diameter": "1.8500000000000001",
+            "floor_layers": "6",
+            "hinge_knuckles": "5",
+            "hinge_lines": "3",
+            "inner_depth": "92",
+            "inner_height": "92",
+            "inner_width": "92",
+            "latch_detent": "0.29999999999999999",
+            "latch_front": "true",
+            "latch_grip": "5",
+            "latch_hook_lines": "3",
+            "latch_layers": "8",
+            "latch_left": "false",
+            "latch_middle_ratio": "0.33000000000000002",
+            "latch_plate_full": "false",
+            "latch_right": "false",
+            "latch_style": "plate",
+            "latch_width": "20",
+            "layer_height": "0.20000000000000001",
+            "line_width": "0.40000000000000002",
+            "lip_layers": "4",
+            "lip_lines": "2",
+            "part": "all",
+            "preview_content": "false",
+            "preview_cut": "false",
+            "preview_hardware": "false",
+            "preview_latch_angle": "0",
+            "preview_lid_open": "0",
+            "rows": "1",
+            "wall_lines": "4"
+        },
+        "batteries AAx16": {
+            "back_side": "latch",
+            "body_ratio": "0.70000000000000007",
+            "chamfer_layers": "3",
+            "clearance": "0.10000000000000001",
+            "columns": "4",
+            "content_depth": "14.4",
+            "content_height": "50.5",
+            "content_width": "14.4",
+            "divider_lines": "2",
+            "edge_radius": "7",
+            "filament_diameter": "1.8500000000000001",
+            "floor_layers": "6",
+            "hinge_knuckles": "5",
+            "hinge_lines": "3",
+            "inner_depth": "14.800000000000001",
+            "inner_height": "52",
+            "inner_width": "14.800000000000001",
+            "latch_detent": "0.29999999999999999",
+            "latch_front": "true",
+            "latch_grip": "5",
+            "latch_hook_lines": "3",
+            "latch_layers": "8",
+            "latch_left": "true",
+            "latch_middle_ratio": "0.33000000000000002",
+            "latch_plate_full": "true",
+            "latch_right": "true",
+            "latch_style": "block",
+            "latch_width": "30",
+            "layer_height": "0.20000000000000001",
+            "line_width": "0.40000000000000002",
+            "lip_layers": "3",
+            "lip_lines": "2",
+            "part": "all",
+            "preview_content": "false",
+            "preview_cut": "false",
+            "preview_hardware": "true",
+            "preview_latch_angle": "45",
+            "preview_lid_open": "50",
+            "rows": "4",
+            "wall_lines": "3"
+        },
+        "batteries AAAx16": {
+            "back_side": "latch",
+            "body_ratio": "0.70000000000000007",
+            "chamfer_layers": "3",
+            "clearance": "0.10000000000000001",
+            "columns": "4",
+            "content_depth": "10.5",
+            "content_height": "44.5",
+            "content_width": "10.5",
+            "divider_lines": "2",
+            "edge_radius": "5",
+            "filament_diameter": "1.8500000000000001",
+            "floor_layers": "6",
+            "hinge_knuckles": "5",
+            "hinge_lines": "3",
+            "inner_depth": "11.0",
+            "inner_height": "46",
+            "inner_width": "11.0",
+            "latch_detent": "0.29999999999999999",
+            "latch_front": "true",
+            "latch_grip": "5",
+            "latch_hook_lines": "3",
+            "latch_layers": "8",
+            "latch_left": "false",
+            "latch_middle_ratio": "0.33000000000000002",
+            "latch_plate_full": "true",
+            "latch_right": "false",
+            "latch_style": "block",
+            "latch_width": "30",
+            "layer_height": "0.20000000000000001",
+            "line_width": "0.40000000000000002",
+            "lip_layers": "3",
+            "lip_lines": "2",
+            "part": "all",
+            "preview_content": "false",
+            "preview_cut": "false",
+            "preview_hardware": "true",
+            "preview_latch_angle": "45",
+            "preview_lid_open": "69",
+            "rows": "4",
+            "wall_lines": "3"
         }
     }
 }
--- a/main.scad	Tue Nov 17 12:53:33 2026 +0100
+++ b/main.scad	Wed Nov 18 02:35:11 2026 +0100
@@ -102,6 +102,8 @@
 
 epsilon = .001;
 $fn = $preview ? 60 : 180;
+// parts to export for printing, read by render_openscad.sh
+printable_parts = "body lid latch";
 
 lw = line_width;
 lh = layer_height;
@@ -609,7 +611,7 @@
     // 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,
+    "w", round(10*inner_width), "d", round(10*inner_depth), "h", round(10*inner_height),
     "b", round(100*body_ih/inner_height),
     // latch middle share, only when it differs from the default
     round(100*latch_ratio) == 33 ? "" : str("lm", round(100*latch_ratio)),
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/render.sh	Wed Nov 18 02:35:11 2026 +0100
@@ -0,0 +1,121 @@
+#!/bin/sh
+USAGE="$0 [-o <dir>] [-p <parts>] [<preset> ...]
+
+export the printable parts of the presets in main.json as stl files. the
+file names come from the model, with hinged_box replaced by the preset
+name, spaces turned into underscores. requires jq to read the preset
+names.
+
+options:
+    -o, --output <dir>   output directory, default .
+    -p, --parts <parts>  space separated list of parts to export,
+                         default \"body lid latch\" or \$PARTS
+
+arguments:
+    <preset>             preset to export, default all presets
+
+environment:
+    OPENSCAD             openscad binary, default the one in
+                         /Applications/OpenSCAD.app
+"
+
+: "${OPENSCAD:=/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD}"
+: "${PARTS:=body lid latch}"
+OUTDIR="."
+PRESETS=""
+
+MODEL_DIR=$(dirname "$0")
+MAIN="$MODEL_DIR/main.scad"
+JSON="$MODEL_DIR/main.json"
+
+# export_part PRESET PART -- export one part of one preset to OUTDIR.
+# expects MAIN, JSON, OPENSCAD and TMP_DIR. prints the file name. on
+# failure prints the openscad output to stderr and returns 1.
+export_part() {
+    ECHO_FILE="$TMP_DIR/name.echo"
+    LOG_FILE="$TMP_DIR/openscad.log"
+    PREFIX=$(echo "$1" | tr ' ' '_')
+
+    # the model echoes the file name, starting with hinged_box_
+    "$OPENSCAD" "$MAIN" -p "$JSON" -P "$1" -D "part=\"$2\"" \
+        -o "$ECHO_FILE" 2>"$LOG_FILE" &&
+    NAME=$(sed -n 's/^ECHO: "hinged_box_\([^"]*\)"$/\1/p' "$ECHO_FILE") &&
+    [ -n "$NAME" ] &&
+    FILE="$OUTDIR/${PREFIX}_$NAME.stl" &&
+    "$OPENSCAD" "$MAIN" -p "$JSON" -P "$1" -D "part=\"$2\"" \
+        -o "$FILE" --export-format asciistl 2>"$LOG_FILE" &&
+    echo "$FILE" || {
+        echo "export of $2 for '$1' failed" >&2
+        cat "$LOG_FILE" >&2
+        return 1
+    }
+}
+
+# export_all -- export every part in PARTS for every preset in PRESETS.
+# stops at the first failure and returns 1.
+export_all() {
+    OLD_IFS="$IFS"
+    IFS="
+"
+    for PRESET in $PRESETS; do
+        IFS="$OLD_IFS"
+        # PARTS is a word list, expanded unquoted
+        for PART in $PARTS; do
+            export_part "$PRESET" "$PART" || return 1
+        done
+    done
+    IFS="$OLD_IFS"
+}
+
+while [ "$#" != 0 ]
+do
+    case "$1" in
+        -h|--help) echo "$USAGE"; exit 0 ;;
+        -o|--output) shift; OUTDIR="$1" ;;
+        -p|--parts) shift; PARTS="$1" ;;
+        -*) echo "unknown option '$1'" >&2; exit 1 ;;
+        *)
+            # presets are kept one per line, since their names may
+            # contain spaces
+            if [ -z "$PRESETS" ]; then
+                PRESETS="$1"
+            else
+                PRESETS="$PRESETS
+$1"
+            fi
+            ;;
+    esac
+    shift
+done
+
+if [ ! -x "$OPENSCAD" ]; then
+    echo "openscad not found at '$OPENSCAD'" >&2
+    exit 1
+fi
+if [ ! -d "$OUTDIR" ]; then
+    echo "output directory '$OUTDIR' not found" >&2
+    exit 1
+fi
+if [ -z "$PARTS" ]; then echo "no parts to export" >&2; exit 1; fi
+
+ALL_PRESETS=$(jq -r '.parameterSets | keys_unsorted[]' "$JSON") || exit 1
+if [ -z "$PRESETS" ]; then PRESETS="$ALL_PRESETS"; fi
+
+# openscad falls back to the defaults for an unknown preset, so check
+# the names here
+OLD_IFS="$IFS"
+IFS="
+"
+for PRESET in $PRESETS; do
+    if ! printf '%s\n' "$ALL_PRESETS" | grep -qxF "$PRESET"; then
+        echo "preset '$PRESET' not found in $JSON" >&2
+        exit 1
+    fi
+done
+IFS="$OLD_IFS"
+
+TMP_DIR=$(mktemp -d) || exit 1
+export_all
+STATUS="$?"
+rm -rf "$TMP_DIR"
+exit "$STATUS"