Compare commits

..

2 Commits

Author SHA1 Message Date
Neale Pickett 2f6156c0c2 Move to make! 2023-11-26 15:48:09 -07:00
Neale Pickett 78ae418a35 More general file creation 2023-11-26 15:34:26 -07:00
5 changed files with 107 additions and 104 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. This is a tiny temperature tower.
I made it because I suspected my printer's hotend thermistor was reporting too cold. I made it because I suspected my printer's hotend thermistor was reporting too cold.
`build.sh` generates `.3mf` files (I think I was right.)
with extra code to make PrusaSlicer change temperatures automatically.
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`. 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,70 +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
run openscad -o $basename "$@" temp-tower.scad 2>&1 | tee $basename.log
mkdir -p Metadata
custom=Metadata/Prusa_Slicer_custom_gcode_per_print_z.xml
(
echo '<?xml version="1.0" encoding="utf-8"?>'
echo '<custom_gcodes_per_print_z>'
sed -n 's/ECHO: "CUSTOM##\(.*\)"/\1/p' $basename.log
echo '<mode value="SingleExtruder"/>'
echo '</custom_gcodes_per_print_z>'
) > $custom
run zip $basename $custom
rm $custom $basename.log
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 .)

View File

@ -84,17 +84,28 @@ module EngraveText(text) {
text(text, size=3.2, valign="center", font=Font); text(text, size=3.2, valign="center", font=Font);
} }
module Custom(text) { // Ouptut special code to add to 3mf file
echo(str("CUSTOM##", text)); module ZCodeWrite(text) {
echo(str(
"#",
"#CUSTOM",
"#3mf",
"#Metadata/Prusa_Slicer_custom_gcode_per_print_z.xml",
"#", text,
"##"
));
} }
module main() {
ZCodeWrite("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
ZCodeWrite("<custom_gcodes_per_print_z>");
difference() { difference() {
union() { union() {
cube([25, 5, PlateHeight]); // Floor plate cube([25, 5, PlateHeight]); // Floor plate
for (tier = [0 : 1 : Tiers-1]) { for (tier = [0 : 1 : Tiers-1]) {
z = PlateHeight + (5 * tier); z = PlateHeight + (5 * tier);
temp = TempBase + (TempIncrease * tier); temp = TempBase + (TempIncrease * tier);
Custom(str( ZCodeWrite(str(
"<code print_z=\"", z, "\"", "<code print_z=\"", z, "\"",
" type=\"4\"", " type=\"4\"",
" extruder=\"1\"", " extruder=\"1\"",
@ -116,3 +127,9 @@ difference() {
EngraveText(SideText); EngraveText(SideText);
} }
} }
ZCodeWrite("<mode value=\"SingleExtruder\"/>");
ZCodeWrite("</custom_gcodes_per_print_z>");
}
main();