Move to make!

This commit is contained in:
Neale Pickett 2023-11-26 15:48:09 -07:00
parent 78ae418a35
commit 2f6156c0c2
4 changed files with 63 additions and 76 deletions

16
Makefile Normal file
View File

@ -0,0 +1,16 @@
PARAMSETS != cat params.json | jq -r '.parameterSets | keys[] | select(length > 0)'
OUTPUTS = $(PARAMSETS:%=%.3mf)
all: $(OUTPUTS)
clean:
rm -f $(OUTPUTS) *.bare.3mf *.log
targets:
@for i in $(PARAMSETS); do echo $$i.3mf; done
%.bare.3mf %.log: temp-tower.scad params.json
openscad -o $*.bare.3mf -P $* -p params.json temp-tower.scad 2>$*.log
%.3mf: %.bare.3mf %.log postprocess.sh
./postprocess.sh $@ $*.bare.3mf $*.log

View File

@ -4,14 +4,31 @@ A Tiny Temperature Tower
This is a tiny temperature tower.
I made it because I suspected my printer's hotend thermistor was reporting too cold.
`build.sh` generates `.3mf` files
with extra code to make PrusaSlicer change temperatures automatically.
(I think I was right.)
Defining A New Model
======================
You can add a new set of model parameters to `params.json`.
Building
----------
This uses make(1).
If you've never used make(1) before,
here's a quick introduction:
make all # Build everything
make clean # Remove build files
make targets # List everything you can build
Building A New Model
---------------------------
You can add a new set of model parameters to [params.json](params.json).
Let's say you named your new parameters `my-new-parameters`.
`build.sh my-new-parameters` will generate `my-new-parameters.3mf`,
with PrusaSlicer temperature changes and ponies and everything.
make my-new-parameters.3mf # Build only your model
The resulting 3mf file will have
temperature changes for PrusaSlicer
and ponies
and everything!

View File

@ -1,69 +0,0 @@
#! /bin/sh
set -e
# paramsets contains the location of the OpenSCAD parameter sets.
# see https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Customizer#Saving_Parameters_value_in_JSON_file
paramsets=params.json
# run executes a program after printing the commandline to stdout.
run () {
echo "=== $*"
"$@"
}
# render turns OpenSCAD echo into 3mf temperature changes.
#
# It does this by kludging together a PrusaSlicer-specific Metadata file.
render () {
basename=$1; shift
logfile=$basename.log
run openscad -o $basename "$@" temp-tower.scad 2>&1 | tee $logfile
rm -rf Metadata
mkdir -p Metadata
cat $logfile | while IFS=# read _ _ custom type path text _; do
[ "$custom#$type" = "CUSTOM#3mf" ] || continue
echo $text >> $path
done
run zip $basename $custom
rm $custom $logfile
rmdir Metadata
}
# paramsets lists all defined parameter sets, one per line.
paramsets () {
cat $paramsets | jq -r '.parameterSets | keys[] | select(length > 0)'
}
case "$1" in
-h|-help|--help)
cat <<EOD
Usage: $0 [-paramsets] [PARAMSET ...]
Generates .3mf files with temperature changes
for each given parameter set.
Parameter sets are specified in $paramsets.
-paramsets List all defined parameter sets, and exit.
EOD
exit 1
;;
-p*|--p*)
paramsets
exit
;;
"")
paramsets | while read paramset; do
render $paramset.3mf -P $paramset -p $paramsets
done
;;
*)
for paramset in "$@"; do
render $paramset.3mf -P $paramset -p $paramsets
done
;;
esac

23
postprocess.sh Executable file
View File

@ -0,0 +1,23 @@
#! /bin/sh
## Postprocess a 3mf file, adding in anything in the log
set -e
outfile=$(realpath $1)
infile=$(realpath $2)
logfile=$(realpath $3)
tmpdir=$(mktemp -d --tmpdir 3mf.XXXXXXXXXX)
trap "rm -rf $tmpdir" EXIT
(cd $tmpdir && unzip $infile)
cat $logfile | while IFS=# read _ _ custom type path text _; do
[ "$custom#$type" = "CUSTOM#3mf" ] || continue
basepath=$(dirname $path)
mkdir -p $tmpdir/$basepath
echo $text >> $tmpdir/$path
done
(cd $tmpdir && zip -r $outfile .)