infill-solver.py solves for Bambu Studio Sparse infill density (%) by
re-slicing a configured .3mf and reading predicted mass from G-code metadata.
Use it for neutral/positive/negative buoyancy targets, with optional extra mass and extra displaced volume (for example, line on a finger spool).
- Reads model volume directly from the 3MF mesh (same geometry the slicer uses).
- Computes target mass:
water_density * (volume + extra_volume) - extra_massand applies optional buoyancy bias. - Binary-searches infill density by calling the Bambu Studio CLI and parsing:
; total filament weight [g] : <value> - Uses a practical 0.1% infill search resolution.
- Writes the final infill back into the original
.3mf(optional backup flag available).
- Python dependencies: stdlib only (no
requirements.txtneeded). - Docker compose service
bambustudiois configured and runs successfully. - Wrapper script exists:
run-infill-solver.sh. - Input
.3mfalready has print settings finalized except sparse infill density.
Your docker-compose.yml needs a bambustudio service that can run:
- Bambu Studio CLI binary (default used by wrapper:
/opt/bambustudio/bin/bambu-studio) - Python 3
- Volume mount for this project directory at
/data
Run from the host with the wrapper (executes inside the container):
"/media/internal/Development/3D-printing/Buoyant Prints/run-infill-solver.sh" \
"/media/internal/Development/3D-printing/Buoyant Prints/Finger-Spool.3mf" \
--water-density 1.0 --buoyancy neutralNote: --water-density 1.0 overrides the script default (1.025 for salt water).
"/media/internal/Development/3D-printing/Buoyant Prints/run-infill-solver.sh" \
"/media/internal/Development/3D-printing/Buoyant Prints/Finger-Spool.3mf" \
--water-density 1.0 \
--extra-mass-g 12.4 \
--extra-volume-cc 9.2--volume-cc: override auto-read 3MF volume--extra-volume-cc: additional displaced volume (cm^3)--extra-mass-g: additional carried mass (g)--water-density: 1.000 for fresh, ~1.025 for salt--tolerance-g: stop whenabs(error) <= tolerance(default 0.02 g)--buoyancy:neutral,positive, ornegative--bias-g: bias applied for positive/negative buoyancy (default 0.05 g)--backup: writes<model>.3mf.bakbefore updating the source file--verbose: show Bambu CLI output each iteration--dry-run: print computed target mass and exit (no slicing, no file write)
volume from 3MF: 19.0621 cm^3
target mass: 19.0621 g
iter 01: infill= 50.00% predicted_mass= 20.60 g target= 19.06 g err= +1.54 g
iter 02: infill= 25.00% predicted_mass= 19.35 g target= 19.06 g err= +0.29 g
iter 03: infill= 12.50% predicted_mass= 18.72 g target= 19.06 g err= -0.34 g
iter 04: infill= 18.80% predicted_mass= 19.05 g target= 19.06 g err= -0.01 g
- The script updates the source
.3mfin place. - Use
--backupwhen you want an on-disk rollback point. - Close the same project in Bambu Studio while the solver runs to avoid stale UI state.
- Uses slicer-predicted mass, not measured print mass; calibration/flow error can shift real results.
- Assumes monotonic mass vs infill; unusual presets may reduce search quality.
- 3MF volume extraction is mesh-based and may differ slightly from CAD solid volume.
- Does not model flooding, trapped-air leaks, deformation, or material water absorption.
- Multi-plate or process-specific overrides in some projects may still require manual verification in GUI.