metadata.py: add parsing of filament type
This commit will add parsing of optional filament type metadata for: - PrusaSlicer and it's derivatives - Cura - IdeaMaker For Cura and IdeaMaker it is necessary to add a custom start g-code comment. Cura: ;Filament type = {material_type} IdeaMaker: ;Filament type = {filament_name_abbreviation1} Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
parent
20d3c9961d
commit
d145442d4b
|
@ -26,6 +26,7 @@ from typing import (
|
||||||
Dict,
|
Dict,
|
||||||
List,
|
List,
|
||||||
Type,
|
Type,
|
||||||
|
Union
|
||||||
)
|
)
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
pass
|
pass
|
||||||
|
@ -83,6 +84,12 @@ def _regex_find_first(pattern: str, data: str) -> Optional[float]:
|
||||||
return None
|
return None
|
||||||
return val
|
return val
|
||||||
|
|
||||||
|
def _regex_find_string(pattern: str, data: str) -> Optional[str]:
|
||||||
|
match = re.search(pattern, data)
|
||||||
|
if match:
|
||||||
|
return match.group(1)
|
||||||
|
return None
|
||||||
|
|
||||||
# Slicer parsing implementations
|
# Slicer parsing implementations
|
||||||
class BaseSlicer(object):
|
class BaseSlicer(object):
|
||||||
def __init__(self, file_path: str) -> None:
|
def __init__(self, file_path: str) -> None:
|
||||||
|
@ -172,6 +179,9 @@ class BaseSlicer(object):
|
||||||
def parse_filament_weight_total(self) -> Optional[float]:
|
def parse_filament_weight_total(self) -> Optional[float]:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def parse_filament_type(self) -> Optional[str]:
|
||||||
|
return None
|
||||||
|
|
||||||
def parse_estimated_time(self) -> Optional[float]:
|
def parse_estimated_time(self) -> Optional[float]:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -336,6 +346,10 @@ class PrusaSlicer(BaseSlicer):
|
||||||
return _regex_find_first(
|
return _regex_find_first(
|
||||||
r"total\sfilament\sused\s\[g\]\s=\s(\d+\.\d*)", self.footer_data)
|
r"total\sfilament\sused\s\[g\]\s=\s(\d+\.\d*)", self.footer_data)
|
||||||
|
|
||||||
|
def parse_filament_type(self) -> Optional[str]:
|
||||||
|
return _regex_find_string(
|
||||||
|
r";\sfilament_type\s=\s(.*)", self.footer_data)
|
||||||
|
|
||||||
def parse_estimated_time(self) -> Optional[float]:
|
def parse_estimated_time(self) -> Optional[float]:
|
||||||
time_match = re.search(
|
time_match = re.search(
|
||||||
r';\sestimated\sprinting\stime.*', self.footer_data)
|
r';\sestimated\sprinting\stime.*', self.footer_data)
|
||||||
|
@ -453,6 +467,10 @@ class Cura(BaseSlicer):
|
||||||
return _regex_find_first(
|
return _regex_find_first(
|
||||||
r";Filament\sweight\s=\s.(\d+\.\d+).", self.header_data)
|
r";Filament\sweight\s=\s.(\d+\.\d+).", self.header_data)
|
||||||
|
|
||||||
|
def parse_filament_type(self) -> Optional[str]:
|
||||||
|
return _regex_find_string(
|
||||||
|
r";Filament\stype\s=\s(.*)", self.header_data)
|
||||||
|
|
||||||
def parse_estimated_time(self) -> Optional[float]:
|
def parse_estimated_time(self) -> Optional[float]:
|
||||||
return self._parse_max_float(r";TIME:.*", self.header_data)
|
return self._parse_max_float(r";TIME:.*", self.header_data)
|
||||||
|
|
||||||
|
@ -671,6 +689,10 @@ class IdeaMaker(BaseSlicer):
|
||||||
return sum(filament)
|
return sum(filament)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def parse_filament_type(self) -> Optional[str]:
|
||||||
|
return _regex_find_string(
|
||||||
|
r";Filament\stype\s=\s(.*)", self.header_data)
|
||||||
|
|
||||||
def parse_filament_weight_total(self) -> Optional[float]:
|
def parse_filament_weight_total(self) -> Optional[float]:
|
||||||
pi = 3.141592653589793
|
pi = 3.141592653589793
|
||||||
length = _regex_find_floats(
|
length = _regex_find_floats(
|
||||||
|
@ -751,6 +773,7 @@ SUPPORTED_DATA = [
|
||||||
'first_layer_bed_temp',
|
'first_layer_bed_temp',
|
||||||
'filament_total',
|
'filament_total',
|
||||||
'filament_weight_total',
|
'filament_weight_total',
|
||||||
|
'filament_type',
|
||||||
'thumbnails']
|
'thumbnails']
|
||||||
|
|
||||||
def process_objects(file_path: str) -> None:
|
def process_objects(file_path: str) -> None:
|
||||||
|
|
Loading…
Reference in New Issue