Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions gcode_metadata/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,26 @@ def same_or_nothing(value_list):
return value_list[0]


def support_material_flag(value: str) -> int:
"""Read `support_material` as 0/1 in both slicer generations.

PrusaSlicer 3.0 names the mode; any mode but `none` generates supports,
which is what `1` meant before 3.0.

>>> support_material_flag("1"), support_material_flag("0")
(1, 0)
>>> support_material_flag("everywhere")
1
>>> support_material_flag("enforcers_only")
1
>>> support_material_flag("none")
0
"""
if value in ("none", "enforcers_only", "everywhere"):
return int(value != "none")
return int(value)


def extract_data(input_string):
"""Extracts metadata from the filename
>>> extract_data("HP_PLA,PLA_MK3SMMU3_3h22m.gcode") #doctest: +ELLIPSIS
Expand Down Expand Up @@ -554,7 +574,7 @@ def set_attr(self, name, value):
"layer_height": float,
"fill_density": str,
"brim_width": int,
"support_material": int,
"support_material": support_material_flag,
"ironing": int,
"quiet_percent_present": bool,
"quiet_left_present": bool,
Expand Down Expand Up @@ -603,7 +623,10 @@ def set_attr(self, name, value):
}

METADATA_START_OFFSET = 800000 # Read 800KB from the start
METADATA_END_OFFSET = 40000 # Read 40KB at the end of the file
# Read 256KB at the end of the file. PrusaSlicer 3.0 writes a JSON copy of
# the config (~56KB for 4 tools, growing with the tool count) between
# max_layer_z and the INI block, putting max_layer_z ~90KB from the end.
METADATA_END_OFFSET = 256000
# Number of times the search for M73 is going to repeat if info
# is incomplete
MAX_M73_SEARCH_BYTES = 100000
Expand Down
Loading
Loading