From 20d3c9961dbdedea84e6266cc744a3551853c3aa Mon Sep 17 00:00:00 2001 From: th33xitus Date: Mon, 27 Dec 2021 21:04:15 +0100 Subject: [PATCH] metadata.py: add parsing of nozzle diameter This commit will add parsing of optional nozzle diameter metadata for: - PrusaSlicer and it's derivatives - Simplify3D - Cura - IdeaMaker For Cura and IdeaMaker it is necessary to add a custom start g-code comment. Cura: ;Nozzle diameter = {machine_nozzle_size} IdeaMaker: ;Nozzle diameter = {machine_nozzle_diameter1} Signed-off-by: Dominik Willner --- moonraker/components/file_manager/metadata.py | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/moonraker/components/file_manager/metadata.py b/moonraker/components/file_manager/metadata.py index 251742d..09f84d5 100644 --- a/moonraker/components/file_manager/metadata.py +++ b/moonraker/components/file_manager/metadata.py @@ -254,6 +254,9 @@ class BaseSlicer(object): def parse_layer_count(self) -> Optional[int]: return None + def parse_nozzle_diameter(self) -> Optional[float]: + return None + class UnknownSlicer(BaseSlicer): def check_identity(self, data: str) -> Optional[Dict[str, str]]: return {'slicer': "Unknown"} @@ -359,6 +362,10 @@ class PrusaSlicer(BaseSlicer): return _regex_find_first( r"; first_layer_bed_temperature = (\d+\.?\d*)", self.footer_data) + def parse_nozzle_diameter(self) -> Optional[float]: + return _regex_find_first( + r";\snozzle_diameter\s=\s(\d+\.\d*)", self.footer_data) + def parse_layer_count(self) -> Optional[int]: match = re.search(r"; total layers count = (\d+)", self.footer_data) val: Optional[int] = None @@ -457,6 +464,10 @@ class Cura(BaseSlicer): return _regex_find_first( r"M190 S(\d+\.?\d*)", self.header_data) + def parse_nozzle_diameter(self) -> Optional[float]: + return _regex_find_first( + r";Nozzle\sdiameter\s=\s(\d+\.\d*)", self.header_data) + def parse_thumbnails(self) -> Optional[List[Dict[str, Any]]]: # Attempt to parse thumbnails from file metadata thumbs = super().parse_thumbnails() @@ -563,6 +574,10 @@ class Simplify3D(BaseSlicer): def parse_first_layer_bed_temp(self) -> Optional[float]: return self._get_first_layer_temp("Heated Bed") + def parse_nozzle_diameter(self) -> Optional[float]: + return _regex_find_first( + r";\s+extruderDiameter,(\d+\.\d*)", self.header_data) + class KISSlicer(BaseSlicer): def check_identity(self, data: str) -> Optional[Dict[str, Any]]: match = re.search(r";\sKISSlicer", data) @@ -683,6 +698,10 @@ class IdeaMaker(BaseSlicer): return _regex_find_first( r"M190 S(\d+\.?\d*)", self.header_data) + def parse_nozzle_diameter(self) -> Optional[float]: + return _regex_find_first( + r";Nozzle\sdiameter\s=\s(\d+\.\d*)", self.header_data) + class IceSL(BaseSlicer): def check_identity(self, data) -> Optional[Dict[str, Any]]: match = re.search(r"; ", data) @@ -720,10 +739,19 @@ SUPPORTED_SLICERS: List[Type[BaseSlicer]] = [ KISSlicer, IdeaMaker, IceSL ] SUPPORTED_DATA = [ - 'layer_height', 'first_layer_height', 'object_height', - 'filament_total', 'filament_weight_total', 'estimated_time', - 'thumbnails', 'first_layer_bed_temp', 'first_layer_extr_temp', - 'gcode_start_byte', 'gcode_end_byte', 'layer_count'] + 'gcode_start_byte', + 'gcode_end_byte', + 'layer_count', + 'object_height', + 'estimated_time', + 'nozzle_diameter', + 'layer_height', + 'first_layer_height', + 'first_layer_extr_temp', + 'first_layer_bed_temp', + 'filament_total', + 'filament_weight_total', + 'thumbnails'] def process_objects(file_path: str) -> None: fname = os.path.basename(file_path)