Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file_manager: Added additional metadata to aid tool selection on single extruder multi-material prints #962

Merged
merged 14 commits into from
Feb 26, 2025
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
12 changes: 8 additions & 4 deletions docs/external_api/file_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ GET /server/files/metadata?filename=tools/drill.gcode

/// api-response-spec
open: True

| Field | Type | Description |
| ----------------------- | :------: | ------------------------------------------------------------ |
| `size` | int | The gcode file size in bytes. |
Expand All @@ -277,10 +276,15 @@ GET /server/files/metadata?filename=tools/drill.gcode
| `first_layer_extr_temp` | float | The configured first layer extruder temperature, in Celsius. |
| `first_layer_bed_temp` | float | The configured first layer bed temperature, in Celsius. |
| `chamber_temp` | float | The configured chamber temperature, in Celsius. |
| `filament_name` | str | The name of the filament used. |
| `filament_type` | str | The type of filament used, ie: `PLA`. |
| `filament_name` | string | The name(s) of the filaments contained in print. |
| `filament_colors` | [string] | List of filament colors used in #RRGGBB format. |
| `extruder_colors` | [string] | List of slicer defined extruder colors for the print. |
| `filament_temps` | [int] | List of base temperatures for filaments, in Celsius. |
| `filament_type` | string | The type(s) of filament used, ie: `PLA`. |
| `filament_total` | float | The total length filament used in mm. |
| `filament_weight_total` | float | The total weight of filament used in grams. |
| `mmu_print` | int | Identifies a multimaterial print with single extruder. |
| `referenced_tools` | [int] | List of tool numbers used in the print. |
| `thumbnails` | [object] | A list of `Thumbnail Info` objects. |
| | | #thumbnail-info-spec |+
| `job_id` | string? | The last `history` job ID associated with the gcode. |
Expand Down Expand Up @@ -1226,4 +1230,4 @@ Not Available

The body of the response contains the contents of `moonraker.log`.

///
///
66 changes: 65 additions & 1 deletion moonraker/components/file_manager/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ def regex_find_ints(pattern: str, data: str) -> List[int]:
pass
return []

def regex_find_strings(pattern: str, separators: str, data: str) -> List[str]:
pattern = pattern.replace(r"(%S)", r"(.*)")
separators = re.escape(separators)
delimiters = rf"[{separators}]"
match = re.search(pattern, data)
if match and match.group(1):
return re.split(delimiters, match.group(1).strip('"'))
return []

def regex_find_float(pattern: str, data: str) -> Optional[float]:
pattern = pattern.replace(r"(%F)", r"([0-9]*\.?[0-9]+)")
match = re.search(pattern, data)
Expand Down Expand Up @@ -204,6 +213,21 @@ def parse_filament_name(self) -> Optional[str]:
def parse_filament_type(self) -> Optional[str]:
return None

def parse_filament_colors(self) -> Optional[List[str]]:
return None

def parse_extruder_colors(self) -> Optional[List[str]]:
return None

def parse_filament_temps(self) -> Optional[List[int]]:
return None

def parse_referenced_tools(self) -> Optional[List[int]]:
return None

def parse_mmu_print(self) -> Optional[int]:
return None

def parse_estimated_time(self) -> Optional[float]:
return None

Expand Down Expand Up @@ -381,13 +405,48 @@ def parse_filament_weight_total(self) -> Optional[float]:
)

def parse_filament_type(self) -> Optional[str]:
return regex_find_string(r";\sfilament_type\s=\s(%S)", self.footer_data)
return regex_find_string(
r";\sfilament_type\s=\s(%S)", self.footer_data
)

def parse_filament_name(self) -> Optional[str]:
return regex_find_string(
r";\sfilament_settings_id\s=\s(%S)", self.footer_data
)

def parse_filament_colors(self) -> Optional[List[str]]:
return regex_find_strings(
r";\sfilament_colour\s=\s(%S)", ",;", self.footer_data
)

def parse_extruder_colors(self) -> Optional[List[str]]:
return regex_find_strings(
r";\sextruder_colour\s=\s(%S)", ",;", self.footer_data
)

def parse_filament_temps(self) -> Optional[List[int]]:
temps = regex_find_strings(
r";\s(?:nozzle_)?temperature\s=\s(%S)", ",;", self.footer_data
)
try:
return [int(t) for t in temps]
except ValueError:
return None

def parse_referenced_tools(self) -> Optional[List[int]]:
tools = regex_find_strings(
r";\sreferenced_tools\s=\s(%S)", ",;", self.footer_data
)
try:
return [int(t) for t in tools]
except ValueError:
return None

def parse_mmu_print(self) -> Optional[int]:
return regex_find_int(
r";\ssingle_extruder_multi_material\s=\s(%D)", self.footer_data
)

def parse_estimated_time(self) -> Optional[float]:
time_match = re.search(
r';\sestimated\sprinting\stime.*', self.footer_data)
Expand Down Expand Up @@ -939,6 +998,11 @@ def parse_first_layer_bed_temp(self) -> Optional[float]:
'chamber_temp',
'filament_name',
'filament_type',
'filament_colors',
'extruder_colors',
'filament_temps',
'referenced_tools',
'mmu_print',
'filament_total',
'filament_weight_total',
'thumbnails'
Expand Down
Loading