Skip to content

ENH: write cumulative per-layer filament usage into slice_info.config - #12147

Open
jobshimo wants to merge 1 commit into
bambulab:masterfrom
jobshimo:enh/slice-info-layer-usage
Open

ENH: write cumulative per-layer filament usage into slice_info.config#12147
jobshimo wants to merge 1 commit into
bambulab:masterfrom
jobshimo:enh/slice-info-layer-usage

Conversation

@jobshimo

@jobshimo jobshimo commented Sep 7, 2026

Copy link
Copy Markdown

Implements #12145.

slice_info.config carries each filament's plate total (used_g), and the printer reports layer_num while it prints, so anyone estimating how much filament an interrupted print used has to scale the total linearly by layers. On real plates that is wrong by a wide margin, because the bottom layers are solid and the infill layers are light: measured on seven A1 plates in the issue, the linear estimate is off by up to 36 % of the plate on a 293-layer part and 70 % on a 26-layer one.

This writes, per filament, the cumulative usage at the end of each layer:

<filament id="4" tray_info_idx="GFG99" type="PETG" color="#FFFFFF" used_m="36.94" used_g="112.83" .../>
<filament_layer_usage id="4" unit="g" values="0.19,6.81,13.94,21.40,...,112.83"/>

Entry 0 is what was extruded before the first layer (purge line, priming); the last entry equals used_g; layer_num from the printer indexes the list directly. The values are an attribute rather than text content so the element is read and written like every other element in the file.

Changes

  • GCodeProcessor: UsedFilaments::record_layer commits the active filament's cache and snapshots every filament's cumulative total. It runs at each ; CHANGE_LAYER tag, before m_layer_id is bumped, and once in finalize after process_caches, so the series has total layer number + 1 entries. A filament first used later in the print is padded with zeros for the layers before it. The series travels in PrintEstimatedStatistics::layer_volumes_per_extruder next to total_volumes_per_extruder.
  • PlateData::parse_filament_info converts the volumes to grams with the same density and diameter it uses for used_g, into FilamentInfo::layer_used_g.
  • _add_slice_info_config_file_to_archive writes the element after the <filament> elements; _handle_start_config_filament_layer_usage reads it back when a sliced project is opened.

Size: about six bytes per layer per filament; a 1000-layer, four-filament plate adds roughly 25 KB to slice_info.config. used_g, used_m and every existing element are unchanged, and a reader that does not know the new element is unaffected.

Verification

Built on Ubuntu 22.04 with BuildLinux.sh -s on top of the docker/BuildDepsDockerfile image, then sliced a test part from the CLI with the A1 0.4 mm nozzle system presets (0.20 mm Standard, Generic PETG, textured PEI plate): a 60 × 60 × 3 mm base with a 12 × 12 × 30 mm pillar, 165 layers.

  • slice_info.config gets <filament_layer_usage id="1" unit="g" values="0.09,0.96,1.83,2.70,...,10.85"/>: 166 entries for 165 layers, last entry equal to used_g (10.85).
  • Summing the relative E moves of the exported plate_1.gcode between ; CHANGE_LAYER markers and converting with the header's density and diameter reproduces the series to within 0.05 g at every entry. That residue is constant along the series and is the same difference that sum shows against used_g itself.
  • The shape is the reason for the change: after layer 15, the end of the base, the part has used 8.57 g of 10.85 g; the linear estimate for that layer is 0.99 g.

Not covered here: multi-filament plates (the zero padding for a filament first used after the first layers is written but was not exercised), and the importer side. _handle_start_config_filament_layer_usage mirrors _handle_start_config_filament, but a CLI --export-3mf without slicing drops the sliced plate data, so there is no command-line round trip to observe it with.

slice_info.config carries each filament's plate total (used_g) and the
printer reports layer_num while it prints, so estimating how much filament
an interrupted print used means scaling the total linearly by layers. That
is wrong by up to a third of the plate on parts with solid bottom layers
and sparse infill (bambulab#12145).

Record every filament's cumulative extruded volume at each layer change
and once at the end, convert it to grams the way used_g is, and write it
as <filament_layer_usage id="N" unit="g" values="..."/> after the
<filament> elements. Entry 0 is what was extruded before the first layer,
the last entry equals used_g, and layer_num indexes the list directly. The
importer reads the element back so it survives a round trip.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant