Skip to content

Commit

Permalink
fix mmu attributes parsing (#42)
Browse files Browse the repository at this point in the history
* fix mmu attributes parsing
* parse extruder_colour out of gcode
  • Loading branch information
sarkafa authored Jul 1, 2024
1 parent 1ed0c19 commit deb5de7
Show file tree
Hide file tree
Showing 3 changed files with 148,314 additions and 27 deletions.
26 changes: 16 additions & 10 deletions gcode_metadata/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
r"((?P<seconds>[0-9]+)s)?")

PRINTERS = [
'MK4IS', 'MK4MMU3', 'MK4', 'MK3SMMU3', 'MK3MMU3', 'MK3SMMU2S',
'MK3MMU2', 'MK3S', 'MK3', 'MK2.5SMMU2S', 'MK2.5MMU2', 'MK2.5S',
'MK2.5', 'MK3.5', 'MK3.9', 'MINI', 'MINIIS', 'XL5', 'XL4', 'XL3',
'XL2', 'XL', 'iX', 'SL1', 'SHELF', 'EXTRACTOR', 'HARVESTER'
]
'MK4IS', 'MK4MMU3', 'MK4', 'MK3SMMU3', 'MK3MMU3', 'MK3SMMU2S', 'MK3MMU2',
'MK3S', 'MK3', 'MK2.5SMMU2S', 'MK2.5MMU2', 'MK2.5S', 'MK2.5', 'MK3.5',
'MK3.9', 'MINI', 'MINIIS', 'XL5', 'XL4', 'XL3', 'XL2', 'XL', 'iX', 'SL1',
'SHELF', 'EXTRACTOR', 'HARVESTER'
]

PRINTERS.sort(key=len, reverse=True)

MATERIALS = [
'PLA', 'PETG', 'ABS', 'ASA', 'FLEX', 'HIPS', 'EDGE', 'NGEN', 'PA',
'PVA', 'PCTG', 'PP', 'PC', 'PEBA', 'CPE', 'PVB', 'PET', 'PLA Tough',
'METAL', 'TPU', 'NYLON'
'PLA', 'PETG', 'ABS', 'ASA', 'FLEX', 'HIPS', 'EDGE', 'NGEN', 'PA', 'PVA',
'PCTG', 'PP', 'PC', 'PEBA', 'CPE', 'PVB', 'PET', 'PLA Tough', 'METAL',
'TPU', 'NYLON'
]

IMAGE_FORMATS = ['PNG', 'JPG']
Expand Down Expand Up @@ -440,10 +440,13 @@ def from_string(self, raw_value):

class FDMMetaData(MetaData):
"""Class for extracting Metadata for FDM gcodes"""

# pylint: disable=too-many-instance-attributes

def set_attr(self, name, value):
"""Set an attribute, but add support for mmu list attributes"""
if value == '""': # e.g. when no extruder_colour
return
if name in self.MMUAttrs:
value_list, single_value = self.MMUAttrs[name].from_string(value)
mmu_name = get_mmu_name(name)
Expand Down Expand Up @@ -489,6 +492,10 @@ def set_attr(self, name, value):
"nozzle_diameter":
MMUAttribute(separator=",",
value_type=float,
conversion=same_or_nothing),
"extruder_colour":
MMUAttribute(separator=";",
value_type=str,
conversion=same_or_nothing)
}

Expand Down Expand Up @@ -613,8 +620,7 @@ def from_comment_line(self, line):

# We store the image data only during parsing. If actively parsing:
if self.img is not None:
line = line[2:].strip()
self.img.append(line)
self.img.append(line[2:].strip())

# For the bulk of metadata comments
match = self.KEY_VAL_PAT.match(line)
Expand Down
Loading

0 comments on commit deb5de7

Please sign in to comment.