diff --git a/E3S1PROFORKBYTT_printdata_prusaslicer_v27_thumbnail.py b/E3S1PROFORKBYTT_printdata_prusaslicer_v27_thumbnail.py index b3e1328..daf94f4 100644 --- a/E3S1PROFORKBYTT_printdata_prusaslicer_v27_thumbnail.py +++ b/E3S1PROFORKBYTT_printdata_prusaslicer_v27_thumbnail.py @@ -97,11 +97,14 @@ def main(source_file): lines[thumbnail_start] = f'; thumbnail_JPG begin 250x250 {len(image_jpg_data)} {start_line_number} {end_line_number} {filament_used_m} {filament_used_g} {layer_height} {filament_diameter} {filament_density} {after_layer_change_count}\n' # Insert 'M117 Pxxx Qxxx' before each ';AFTER_LAYER_CHANGE' - layer_number = 1 + layer_number = 0 i = 0 while i < len(lines): if lines[i].startswith(';AFTER_LAYER_CHANGE'): - m117_line = "M117 L{} M{} G{}".format(layer_number, math.ceil(remaining_filament_m), math.ceil(remaining_filament_g)) + if layer_number == 0: + m117_line = "M117 L1 M{} G{} Z{} Q{}".format(math.ceil(remaining_filament_m), math.ceil(remaining_filament_g), layers, layer_height) + else: + m117_line = "M117 L{} M{} G{}".format(layer_number + 1, math.ceil(remaining_filament_m), math.ceil(remaining_filament_g)) lines.insert(i, m117_line + '\n') remaining_filament_m -= filament_used_m_per_layer remaining_filament_g -= filament_used_g_per_layer @@ -110,10 +113,10 @@ def main(source_file): i += 1 i += 1 - if m117_added == 0: - print("No M117 commands were added. Check the G-code for ';AFTER_LAYER_CHANGE' markers.") - else: + if m117_added > 0: print("Added {} M117 commands.".format(m117_added)) + else: + print("No M117 commands were added. Check the G-code for ';AFTER_LAYER_CHANGE' markers.") # Remove the '; generated by PrusaSlicer' line and any leading semicolons or empty lines lines = [line for line in lines if line.strip() and not line.startswith('; generated by PrusaSlicer')] @@ -127,4 +130,4 @@ if __name__ == "__main__": print("Usage: python3 script.py ") sys.exit(1) - main(sys.argv[1]) \ No newline at end of file + main(sys.argv[1])