naming
This commit is contained in:
parent
147d8d7b96
commit
7f480c698d
1 changed files with 9 additions and 1 deletions
|
|
@ -39,12 +39,20 @@ def parse_gcode_metadata(gcode: str) -> dict[str, Any]:
|
|||
def get_gcode_name_from_metadata(gcode: str, default: str = "output") -> str:
|
||||
"""Generates a descriptive name for the G-code based on its objects_info metadata."""
|
||||
parts_match = re.search(r"; objects_info = (.*)", gcode)
|
||||
|
||||
filament_match = re.search(r"; filament_type = (.*)", gcode)
|
||||
filament = filament_match[1] if filament_match else ''
|
||||
|
||||
printer_match = re.search(r"; printer_model = (.*)", gcode)
|
||||
printer = printer_match[1] if printer_match else ''
|
||||
|
||||
if parts_match:
|
||||
try:
|
||||
gcode_info = json.loads(parts_match.group(1))
|
||||
names: list[str] = [str(v['name'].split(" id:")[0]) for v in gcode_info['objects']]
|
||||
counts = Counter(names)
|
||||
return "-".join(f"{c}x{n}" if c > 1 else n for n, c in counts.items())
|
||||
object_names = "-".join(f"{c}x{n}" if c > 1 else n for n, c in counts.items())
|
||||
return "-".join([object_names, filament, printer])
|
||||
except:
|
||||
pass
|
||||
return default
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue