From 10ca5634997f3c5711c082331d67a9a2eda3201b Mon Sep 17 00:00:00 2001 From: GregValiant <64202104+GregValiant@users.noreply.github.com> Date: Thu, 22 Jun 2023 13:21:14 -0400 Subject: [PATCH 1/8] Obsolete DisplayFilename and DisplayProgress These two files become obsolete if DisplayInfoOnLCD is accepted. --- .../scripts/DisplayFilenameAndLayerOnLCD.py | 109 ---------- .../scripts/DisplayProgressOnLCD.py | 198 ------------------ 2 files changed, 307 deletions(-) delete mode 100644 plugins/PostProcessingPlugin/scripts/DisplayFilenameAndLayerOnLCD.py delete mode 100644 plugins/PostProcessingPlugin/scripts/DisplayProgressOnLCD.py diff --git a/plugins/PostProcessingPlugin/scripts/DisplayFilenameAndLayerOnLCD.py b/plugins/PostProcessingPlugin/scripts/DisplayFilenameAndLayerOnLCD.py deleted file mode 100644 index b9184b59c3..0000000000 --- a/plugins/PostProcessingPlugin/scripts/DisplayFilenameAndLayerOnLCD.py +++ /dev/null @@ -1,109 +0,0 @@ -# Cura PostProcessingPlugin -# Author: Amanda de Castilho -# Date: August 28, 2018 -# Modified: November 16, 2018 by Joshua Pope-Lewis - -# Description: This plugin shows custom messages about your print on the Status bar... -# Please look at the 5 options -# - Scrolling (SCROLL_LONG_FILENAMES) if enabled in Marlin and you aren't printing a small item select this option. -# - Name: By default it will use the name generated by Cura (EG: TT_Test_Cube) - Type a custom name in here -# - Start Num: Choose which number you prefer for the initial layer, 0 or 1 -# - Max Layer: Enabling this will show how many layers are in the entire print (EG: Layer 1 of 265!) -# - Add prefix 'Printing': Enabling this will add the prefix 'Printing' - -from ..Script import Script -from UM.Application import Application - -class DisplayFilenameAndLayerOnLCD(Script): - def __init__(self): - super().__init__() - - def getSettingDataString(self): - return """{ - "name": "Display Filename And Layer On LCD", - "key": "DisplayFilenameAndLayerOnLCD", - "metadata": {}, - "version": 2, - "settings": - { - "scroll": - { - "label": "Scroll enabled/Small layers?", - "description": "If SCROLL_LONG_FILENAMES is enabled select this setting however, if the model is small disable this setting!", - "type": "bool", - "default_value": false - }, - "name": - { - "label": "Text to display:", - "description": "By default the current filename will be displayed on the LCD. Enter text here to override the filename and display something else.", - "type": "str", - "default_value": "" - }, - "startNum": - { - "label": "Initial layer number:", - "description": "Choose which number you prefer for the initial layer, 0 or 1", - "type": "int", - "default_value": 0, - "minimum_value": 0, - "maximum_value": 1 - }, - "maxlayer": - { - "label": "Display max layer?:", - "description": "Display how many layers are in the entire print on status bar?", - "type": "bool", - "default_value": true - }, - "addPrefixPrinting": - { - "label": "Add prefix 'Printing'?", - "description": "This will add the prefix 'Printing'", - "type": "bool", - "default_value": true - } - } - }""" - - def execute(self, data): - max_layer = 0 - lcd_text = "M117 " - if self.getSettingValueByKey("name") != "": - name = self.getSettingValueByKey("name") - else: - name = Application.getInstance().getPrintInformation().jobName - if self.getSettingValueByKey("addPrefixPrinting"): - lcd_text += "Printing " - if not self.getSettingValueByKey("scroll"): - lcd_text += "Layer " - else: - lcd_text += name + " - Layer " - i = self.getSettingValueByKey("startNum") - for layer in data: - display_text = lcd_text + str(i) - layer_index = data.index(layer) - lines = layer.split("\n") - for line in lines: - if line.startswith(";LAYER_COUNT:"): - max_layer = line - max_layer = max_layer.split(":")[1] - if self.getSettingValueByKey("startNum") == 0: - max_layer = str(int(max_layer) - 1) - if line.startswith(";LAYER:"): - if self.getSettingValueByKey("maxlayer"): - display_text = display_text + " of " + max_layer - if not self.getSettingValueByKey("scroll"): - display_text = display_text + " " + name - else: - if not self.getSettingValueByKey("scroll"): - display_text = display_text + " " + name + "!" - else: - display_text = display_text + "!" - line_index = lines.index(line) - lines.insert(line_index + 1, display_text) - i += 1 - final_lines = "\n".join(lines) - data[layer_index] = final_lines - - return data diff --git a/plugins/PostProcessingPlugin/scripts/DisplayProgressOnLCD.py b/plugins/PostProcessingPlugin/scripts/DisplayProgressOnLCD.py deleted file mode 100644 index eb74955319..0000000000 --- a/plugins/PostProcessingPlugin/scripts/DisplayProgressOnLCD.py +++ /dev/null @@ -1,198 +0,0 @@ -# Cura PostProcessingPlugin -# Author: Mathias Lyngklip Kjeldgaard, Alexander Gee, Kimmo Toivanen, Inigo Martinez -# Date: July 31, 2019 -# Modified: Nov 30, 2021 - -# Description: This plugin displays progress on the LCD. It can output the estimated time remaining and the completion percentage. - -from ..Script import Script - -import re -import datetime - -class DisplayProgressOnLCD(Script): - - def __init__(self): - super().__init__() - - def getSettingDataString(self): - return """{ - "name": "Display Progress On LCD", - "key": "DisplayProgressOnLCD", - "metadata": {}, - "version": 2, - "settings": - { - "time_remaining": - { - "label": "Time Remaining", - "description": "Select to write remaining time to the display.Select to write remaining time on the display using M117 status line message (almost all printers) or using M73 command (Prusa and Marlin 2 if enabled).", - "type": "bool", - "default_value": false - }, - "time_remaining_method": - { - "label": "Time Reporting Method", - "description": "How should remaining time be shown on the display? It could use a generic message command (M117, almost all printers), or a specialised time remaining command (M73, Prusa and Marlin 2).", - "type": "enum", - "options": { - "m117":"M117 - All printers", - "m73":"M73 - Prusa, Marlin 2", - "m118":"M118 - Octoprint" - }, - "enabled": "time_remaining", - "default_value": "m117" - }, - "update_frequency": - { - "label": "Update frequency", - "description": "Update remaining time for every layer or periodically every minute or faster.", - "type": "enum", - "options": {"0":"Every layer","15":"Every 15 seconds","30":"Every 30 seconds","60":"Every minute"}, - "default_value": "0", - "enabled": "time_remaining" - }, - "percentage": - { - "label": "Percentage", - "description": "When enabled, set the completion bar percentage on the LCD using Marlin's M73 command.", - "type": "bool", - "default_value": false - } - } - }""" - - # Get the time value from a line as a float. - # Example line ;TIME_ELAPSED:1234.6789 or ;TIME:1337 - def getTimeValue(self, line): - list_split = re.split(":", line) # Split at ":" so we can get the numerical value - return float(list_split[1]) # Convert the numerical portion to a float - - def outputTime(self, lines, line_index, time_left, mode): - # Do some math to get the time left in seconds into the right format. (HH,MM,SS) - time_left = max(time_left, 0) - m, s = divmod(time_left, 60) - h, m = divmod(m, 60) - # Create the string - if mode == "m117": - current_time_string = "{:d}h{:02d}m{:02d}s".format(int(h), int(m), int(s)) - # And now insert that into the GCODE - lines.insert(line_index, "M117 Time Left {}".format(current_time_string)) - elif mode == "m118": - current_time_string = "{:d}h{:02d}m{:02d}s".format(int(h), int(m), int(s)) - # And now insert that into the GCODE - lines.insert(line_index, "M118 A1 P0 action:notification Time Left {}".format(current_time_string)) - else: - mins = int(60 * h + m + s / 30) - lines.insert(line_index, "M73 R{}".format(mins)) - - def execute(self, data): - output_time = self.getSettingValueByKey("time_remaining") - output_time_method = self.getSettingValueByKey("time_remaining_method") - output_frequency = int(self.getSettingValueByKey("update_frequency")) - output_percentage = self.getSettingValueByKey("percentage") - line_set = {} - if output_percentage or output_time: - total_time = -1 - previous_layer_end_percentage = 0 - previous_layer_end_time = 0 - for layer in data: - layer_index = data.index(layer) - lines = layer.split("\n") - - for line in lines: - if (line.startswith(";TIME:") or line.startswith(";PRINT.TIME:")) and total_time == -1: - # This line represents the total time required to print the gcode - total_time = self.getTimeValue(line) - line_index = lines.index(line) - - # In the beginning we may have 2 M73 lines, but it makes logic less complicated - if output_time: - self.outputTime(lines, line_index, total_time, output_time_method) - - if output_percentage: - # Emit 0 percent to sure Marlin knows we are overriding the completion percentage - if output_time_method == "m118": - lines.insert(line_index, "M118 A1 P0 action:notification Data Left 0/100") - else: - lines.insert(line_index, "M73 P0") - - elif line.startswith(";TIME_ELAPSED:"): - # We've found one of the time elapsed values which are added at the end of layers - - # If we have seen this line before then skip processing it. We can see lines multiple times because we are adding - # intermediate percentages before the line being processed. This can cause the current line to shift back and be - # encountered more than once - if line in line_set: - continue - line_set[line] = True - - # If total_time was not already found then noop - if total_time == -1: - continue - - current_time = self.getTimeValue(line) - line_index = lines.index(line) - - if output_time: - if output_frequency == 0: - # Here we calculate remaining time - self.outputTime(lines, line_index, total_time - current_time, output_time_method) - else: - # Here we calculate remaining time and how many outputs are expected for the layer - layer_time_delta = int(current_time - previous_layer_end_time) - layer_step_delta = int((current_time - previous_layer_end_time) / output_frequency) - # If this layer represents less than 1 step then we don't need to emit anything, continue to the next layer - if layer_step_delta != 0: - # Grab the index of the current line and figure out how many lines represent one second - step = line_index / layer_time_delta - # Move new lines further as we add new lines above it - lines_added = 1 - # Run through layer in seconds - for seconds in range(1, layer_time_delta + 1): - # Time from start to decide when to update - line_time = int(previous_layer_end_time + seconds) - # Output every X seconds and after last layer - if line_time % output_frequency == 0 or line_time == total_time: - # Line to add the output - time_line_index = int((seconds * step) + lines_added) - - # Insert remaining time into the GCODE - self.outputTime(lines, time_line_index, total_time - line_time, output_time_method) - # Next line will be again lower - lines_added = lines_added + 1 - - previous_layer_end_time = int(current_time) - - if output_percentage: - # Calculate percentage value this layer ends at - layer_end_percentage = int((current_time / total_time) * 100) - - # Figure out how many percent of the total time is spent in this layer - layer_percentage_delta = layer_end_percentage - previous_layer_end_percentage - - # If this layer represents less than 1 percent then we don't need to emit anything, continue to the next layer - if layer_percentage_delta != 0: - # Grab the index of the current line and figure out how many lines represent one percent - step = line_index / layer_percentage_delta - - for percentage in range(1, layer_percentage_delta + 1): - # We add the percentage value here as while processing prior lines we will have inserted - # percentage lines before the current one. Failing to do this will upset the spacing - percentage_line_index = int((percentage * step) + percentage) - - # Due to integer truncation of the total time value in the gcode the percentage we - # calculate may slightly exceed 100, as that is not valid we cap the value here - output = min(percentage + previous_layer_end_percentage, 100) - - # Now insert the sanitized percentage into the GCODE - if output_time_method == "m118": - lines.insert(percentage_line_index, "M118 A1 P0 action:notification Data Left {}/100".format(output)) - else: - lines.insert(percentage_line_index, "M73 P{}".format(output)) - - previous_layer_end_percentage = layer_end_percentage - - # Join up the lines for this layer again and store them in the data array - data[layer_index] = "\n".join(lines) - return data From 5f3b96c26c67ce8780c8d8eae7b7282e03768d6b Mon Sep 17 00:00:00 2001 From: GregValiant <64202104+GregValiant@users.noreply.github.com> Date: Thu, 22 Jun 2023 13:15:38 -0400 Subject: [PATCH 2/8] Update DisplayInfoOnLCD.py Remove code that added the PP name to the gcode. Create DisplayInfoOnLCD.py This post processor combines DisplayLayerAndFilename with DisplayProgress. Those two post processors would be obsolete. --- .../scripts/DisplayInfoOnLCD.py | 273 ++++++++++++++++++ 1 file changed, 273 insertions(+) create mode 100644 plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py diff --git a/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py b/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py new file mode 100644 index 0000000000..341685be1d --- /dev/null +++ b/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py @@ -0,0 +1,273 @@ +# Display Filename and Layer on the LCD by Amanda de Castilho on August 28, 2018 +# Modified: Joshua Pope-Lewis on November 16, 2018 +# Display Progress on LCD by Mathias Lyngklip Kjeldgaard, Alexander Gee, Kimmo Toivanen, Inigo Martinez on July 31, 2019 +# Show Progress was adapted from Display Progress by Louis Wooters on January 6, 2020. His changes are included here. +#--------------------------------------------------------------- +# DisplayNameOrProgressOnLCD.py +# Cura Post-Process plugin +# Combines 'Display Filename and Layer on the LCD' with 'Display Progress' +# Combined and adapted by: GregValiant (Greg Foresi) +# Date: March 5, 2023 +# NOTE: This combined post processor will make 'Display Filename and Layer on the LCD' and 'Display Progress' obsolete +# Description: Display Filename and Layer options: +# Status messages sent to the printer... +# - Scrolling (SCROLL_LONG_FILENAMES) if enabled in Marlin and you aren't printing a small item select this option. +# - Name: By default it will use the name generated by Cura (EG: TT_Test_Cube) - You may enter a custom name here +# - Start Num: Choose which number you prefer for the initial layer, 0 or 1 +# - Max Layer: Enabling this will show how many layers are in the entire print (EG: Layer 1 of 265!) +# - Add prefix 'Printing': Enabling this will add the prefix 'Printing' +# - Example Line on LCD: Printing Layer 0 of 395 3DBenchy +# Display Progress options: +# - Display Total Layer Count +# - Disply Time Remaining for the print +# - Time Fudge Factor % - Divide the Actual Print Time by the Cura Estimate. Enter as a percentage and the displayed time will be adjusted. This allows you to bring the displayed time closer to reality (Ex: Entering 87.5 would indicate an adjustement to 87.5% of the Cura estimate). +# - Example line on LCD: 1/479 | ET 2h13m +# - 'Add M118 Line' is available with either option. M118 will bounce the message back to a remote print server through the USB connection. + +from ..Script import Script +from UM.Application import Application + +class DisplayInfoOnLCD(Script): + def __init__(self): + super().__init__() + + def getSettingDataString(self): + return """{ + "name": "Display Info on LCD", + "key": "DisplayInfoOnLCD", + "metadata": {}, + "version": 2, + "settings": + { + "display_option": + { + "label": "LCD display option...", + "description": "Display Filename and Layer was formerly 'Display Filename and Layer on LCD' post-processor. The message format on the LCD is 'Printing Layer 0 of 15 3D Benchy'. Display Progress is similar to the former 'Display Progress on LCD' post-processor. The display format is '1/16 | ET 2hr28m'. Display Progress includes a fudge factor for the print time estimate.", + "type": "enum", + "options": { + "display_progress": "Display Progress", + "filename_layer": "Filename and Layer" + }, + "default_value": "display_progress" + }, + "format_option": + { + "label": "Scroll enabled/Small layers?", + "description": "If SCROLL_LONG_FILENAMES is enabled in your firmware select this setting.", + "type": "bool", + "default_value": false, + "enabled": "display_option == 'filename_layer'" + }, + "name": + { + "label": "Text to display:", + "description": "By default the current filename will be displayed on the LCD. Enter text here to override the filename and display something else.", + "type": "str", + "default_value": "", + "enabled": "display_option == 'filename_layer'" + }, + "startNum": + { + "label": "Initial layer number:", + "description": "Choose which number you prefer for the initial layer, 0 or 1", + "type": "int", + "default_value": 0, + "minimum_value": 0, + "maximum_value": 1, + "enabled": "display_option == 'filename_layer'" + }, + "maxlayer": + { + "label": "Display max layer?:", + "description": "Display how many layers are in the entire print on status bar?", + "type": "bool", + "default_value": true, + "enabled": "display_option == 'filename_layer'" + }, + "addPrefixPrinting": + { + "label": "Add prefix 'Printing'?", + "description": "This will add the prefix 'Printing'", + "type": "bool", + "default_value": true, + "enabled": "display_option == 'filename_layer'" + }, + "display_total_layers": + { + "label": "Display total layers", + "description": "This setting adds the 'Total Layers' to the LCD message as '17/234'.", + "type": "bool", + "default_value": true, + "enabled": "display_option == 'display_progress'" + }, + "display_remaining_time": + { + "label": "Display remaining time", + "description": "This will add the remaining printing time to the LCD message.", + "type": "bool", + "default_value": true, + "enabled": "display_option == 'display_progress'" + }, + "add_m118_line": + { + "label": "Add M118 Line", + "description": "Adds M118 in addition to the M117. It will bounce the message back through the USB port to a computer print server (if a printer server is enabled).", + "type": "bool", + "default_value": false + }, + "speed_factor": + { + "label": "Time Fudge Factor %", + "description": "Tweak this value to get better estimates. ([Actual Print Time]/[Cura Estimate]) x 100 = Time Fudge Factor. If Cura estimated 9hr and the print actually took 10hr30min then enter 117 here to adjust any estimate closer to reality.", + "type": "float", + "unit": "%", + "default_value": 100, + "enabled": "display_option == 'display_progress'" + } + } + }""" + + def execute(self, data): + display_option = self.getSettingValueByKey("display_option") + add_m118_line = self.getSettingValueByKey("add_m118_line") + + # This is Display Filename and Layer on LCD--------------------------------------------------------- + if display_option == "filename_layer": + max_layer = 0 + lcd_text = "M117 " + if self.getSettingValueByKey("name") != "": + name = self.getSettingValueByKey("name") + else: + name = Application.getInstance().getPrintInformation().jobName + if self.getSettingValueByKey("addPrefixPrinting"): + lcd_text += "Printing " + if not self.getSettingValueByKey("scroll"): + lcd_text += "Layer " + else: + lcd_text += name + " - Layer " + i = self.getSettingValueByKey("startNum") + for layer in data: + display_text = lcd_text + str(i) + layer_index = data.index(layer) + lines = layer.split("\n") + for line in lines: + if line.startswith(";LAYER_COUNT:"): + max_layer = line + max_layer = max_layer.split(":")[1] + if self.getSettingValueByKey("startNum") == 0: + max_layer = str(int(max_layer) - 1) + if ";LAYER:" in line: + if self.getSettingValueByKey("maxlayer"): + display_text = display_text + " of " + max_layer + if not self.getSettingValueByKey("scroll"): + display_text = display_text + " " + name + else: + if not self.getSettingValueByKey("scroll"): + display_text = display_text + " " + name + "!" + else: + display_text = display_text + "!" + line_index = lines.index(line) + lines.insert(line_index + 1, display_text) + if add_m118_line: + lines.insert(line_index + 2, str(display_text.replace("M117", "M118", 1))) + i += 1 + final_lines = "\n".join(lines) + data[layer_index] = final_lines + + # Display Progress (from 'Show Progress' and 'Display Progress on LCD')--------------------------------------- + elif display_option == "display_progress": + # get settings + display_total_layers = self.getSettingValueByKey("display_total_layers") + display_remaining_time = self.getSettingValueByKey("display_remaining_time") + speed_factor = self.getSettingValueByKey("speed_factor") / 100 + # initialize global variables + first_layer_index = 0 + time_total = 0 + number_of_layers = 0 + time_elapsed = 0 + # if at least one of the settings is disabled, there is enough room on the display to display "layer" + first_section = data[0] + lines = first_section.split("\n") + for line in lines: + if ";TIME:" in line: + tindex = lines.index(line) + print_time = int(line.split(":")[1]) + print_time = print_time*speed_factor + hhh = print_time/3600 + hr = round(hhh // 1) + mmm = round((hhh % 1) * 60) + if add_m118_line: lines.insert(tindex+1,"M118 Adjusted Print Time " + str(hr) + "hr " + str(mmm) + "min") + lines.insert(tindex+1,"M117 ET " + str(hr) + "hr " + str(mmm) + "min") + data[0] = "\n".join(lines) + data[len(data)-1] += "M117 Orig Est " + str(hr) + "hr " + str(mmm) + "min\n" + if add_m118_line: data[len(data)-1] += "M118 Orig Est w/FudgeFactor at " + str(speed_factor * 100) + "% was " + str(hr) + "hr " + str(mmm) + "min\n" + if not display_total_layers or not display_remaining_time: + base_display_text = "layer " + else: + base_display_text = "" + layer = data[len(data)-1] + data[len(data)-1] = layer.replace(";End of Gcode" + "\n", "") + data[len(data)-1] += ";End of Gcode" + "\n" + # Search for the number of layers and the total time from the start code + for index in range(len(data)): + data_section = data[index] + # We have everything we need, save the index of the first layer and exit the loop + if ";LAYER:" in data_section: + first_layer_index = index + break + else: + for line in data_section.split("\n"): + if line.startswith(";LAYER_COUNT:"): + number_of_layers = int(line.split(":")[1]) + elif line.startswith(";TIME:"): + time_total = int(line.split(":")[1]) + # for all layers... + current_layer = 0 + for layer_counter in range(len(data)-2): + current_layer += 1 + layer_index = first_layer_index + layer_counter + display_text = base_display_text + display_text += str(current_layer) + # create a list where each element is a single line of code within the layer + lines = data[layer_index].split("\n") + if not ";LAYER:" in data[layer_index]: + current_layer -= 1 + continue + # add the total number of layers if this option is checked + if display_total_layers: + display_text += "/" + str(number_of_layers) + # if display_remaining_time is checked, it is calculated in this loop + if display_remaining_time: + time_remaining_display = " | ET " # initialize the time display + m = (time_total - time_elapsed) // 60 # estimated time in minutes + m *= speed_factor # correct for printing time + m = int(m) + h, m = divmod(m, 60) # convert to hours and minutes + # add the time remaining to the display_text + if h > 0: # if it's more than 1 hour left, display format = xhxxm + time_remaining_display += str(h) + "h" + if m < 10: # add trailing zero if necessary + time_remaining_display += "0" + time_remaining_display += str(m) + "m" + else: + time_remaining_display += str(m) + "m" + display_text += time_remaining_display + # find time_elapsed at the end of the layer (used to calculate the remaining time of the next layer) + if not current_layer == number_of_layers: + for line_index in range(len(lines) - 1, -1, -1): + line = lines[line_index] + if line.startswith(";TIME_ELAPSED:"): + # update time_elapsed for the NEXT layer and exit the loop + time_elapsed = int(float(line.split(":")[1])) + break + # insert the text AFTER the first line of the layer (in case other scripts use ";LAYER:") + for l_index, line in enumerate(lines): + if line.startswith(";LAYER:"): + lines[l_index] += "\nM117 " + display_text + if add_m118_line: + lines[l_index] += "\nM118 " + display_text + break + # overwrite the layer with the modified layer + data[layer_index] = "\n".join(lines) + + return data From 362b4d894fad76c0671ef5ca25ded1e89cd3472a Mon Sep 17 00:00:00 2001 From: GregValiant <64202104+GregValiant@users.noreply.github.com> Date: Sat, 12 Aug 2023 08:58:34 -0400 Subject: [PATCH 3/8] Update DisplayInfoOnLCD.py Added TimeToPause to DisplayProgress --- .../scripts/DisplayInfoOnLCD.py | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py b/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py index 341685be1d..8a5533d45a 100644 --- a/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py +++ b/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py @@ -123,6 +123,14 @@ class DisplayInfoOnLCD(Script): "unit": "%", "default_value": 100, "enabled": "display_option == 'display_progress'" + }, + "countdown_to_pause": + { + "label": "Countdown to Pauses", + "description": "Instead of layer number and remaining print time the LCD will show 'layers remaining before pause' and 'Est Time to Pause' (ETP).", + "type": "bool", + "default_value": false, + "enabled": "display_option == 'display_progress'" } } }""" @@ -269,5 +277,50 @@ class DisplayInfoOnLCD(Script): break # overwrite the layer with the modified layer data[layer_index] = "\n".join(lines) - + + # If enabled then change the ET to TP for 'Time To Pause' + if bool(self.getSettingValueByKey("countdown_to_pause")): + time_list = [] + time_list.append("0") + time_list.append("0") + this_time = 0 + pause_index = 1 + + # Get the layer times + for num in range(2,len(data) - 1): + layer = data[num] + lines = layer.split("\n") + for line in lines: + if line.startswith(";TIME_ELAPSED:"): + this_time = (float(line.split(":")[1]))*speed_factor + time_list.append(str(this_time)) + if "PauseAtHeight.py" in layer: + for qnum in range(num - 1, pause_index, -1): + time_list[qnum] = str(float(this_time) - float(time_list[qnum])) + "P" + pause_index = num-1 + + # Make the adjustments to the M117 (and M118) lines that are prior to a pause + for num in range (2, len(data) - 1,1): + layer = data[num] + lines = layer.split("\n") + for line in lines: + if line.startswith("M117") and "|" in line and "P" in time_list[num]: + M117_line = line.split("|")[0] + "| TP " + alt_time = time_list[num][:-1] + hhh = int(float(alt_time) / 3600) + if hhh > 0: + hhr = str(hhh) + "h" + else: + hhr = "" + mmm = ((float(alt_time) / 3600) - (int(float(alt_time) / 3600))) * 60 + sss = int((mmm - int(mmm)) * 60) + mmm = str(round(mmm)) + "m" + time_to_go = str(hhr) + str(mmm) + if hhr == "": time_to_go = time_to_go + str(sss) + "s" + M117_line = M117_line + time_to_go + layer = layer.replace(line, M117_line) + if line.startswith("M118") and "|" in line and "P" in time_list[num]: + M118_line = line.split("|")[0] + "| TP " + time_to_go + layer = layer.replace(line, M118_line) + data[num] = layer return data From 099cfe8294fad6dea9e9e2b4bc53851b574789bd Mon Sep 17 00:00:00 2001 From: GregValiant <64202104+GregValiant@users.noreply.github.com> Date: Fri, 8 Sep 2023 08:59:26 -0400 Subject: [PATCH 4/8] Add 'Print Finish Time' estimate as a message Get the current print time estimate, adjust it by the Fudge Factor, and add it to the current time +10 minutes (to actually start the print.) Update DisplayInfoOnLCD.py Change message format for Finish Time Estimate. --- .../scripts/DisplayInfoOnLCD.py | 102 +++++++++++++++--- 1 file changed, 86 insertions(+), 16 deletions(-) diff --git a/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py b/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py index 8a5533d45a..4718d55256 100644 --- a/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py +++ b/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py @@ -1,13 +1,13 @@ # Display Filename and Layer on the LCD by Amanda de Castilho on August 28, 2018 -# Modified: Joshua Pope-Lewis on November 16, 2018 +# Modified: Joshua Pope-Lewis on November 16, 2018 # Display Progress on LCD by Mathias Lyngklip Kjeldgaard, Alexander Gee, Kimmo Toivanen, Inigo Martinez on July 31, 2019 # Show Progress was adapted from Display Progress by Louis Wooters on January 6, 2020. His changes are included here. #--------------------------------------------------------------- # DisplayNameOrProgressOnLCD.py # Cura Post-Process plugin # Combines 'Display Filename and Layer on the LCD' with 'Display Progress' -# Combined and adapted by: GregValiant (Greg Foresi) -# Date: March 5, 2023 +# Combined and with additions by: GregValiant (Greg Foresi) +# Date: September 8, 2023 # NOTE: This combined post processor will make 'Display Filename and Layer on the LCD' and 'Display Progress' obsolete # Description: Display Filename and Layer options: # Status messages sent to the printer... @@ -20,17 +20,24 @@ # Display Progress options: # - Display Total Layer Count # - Disply Time Remaining for the print -# - Time Fudge Factor % - Divide the Actual Print Time by the Cura Estimate. Enter as a percentage and the displayed time will be adjusted. This allows you to bring the displayed time closer to reality (Ex: Entering 87.5 would indicate an adjustement to 87.5% of the Cura estimate). +# - Time Fudge Factor % - Divide the Actual Print Time by the Cura Estimate. Enter as a percentage and the displayed time will be adjusted. This allows you to bring the displayed time closer to reality (Ex: Entering 87.5 would indicate an adjustment to 87.5% of the Cura estimate). # - Example line on LCD: 1/479 | ET 2h13m +# - Time to Pauses changes the M117/M118 lines to countdown to the next pause as 1/479 | TP 2h36m # - 'Add M118 Line' is available with either option. M118 will bounce the message back to a remote print server through the USB connection. +# - Enable 'Finish-Time' Message when checked takes the Print Time, adds 10 minutes for print start-up, and calculates when the print will end. It takes into account the Time Fudge Factor. (Available for Display Filename as well.) from ..Script import Script from UM.Application import Application +from UM.Qt.Duration import DurationFormat +import UM.Util +import configparser +from UM.Preferences import Preferences +import time +import datetime +from UM.Message import Message class DisplayInfoOnLCD(Script): - def __init__(self): - super().__init__() - + def getSettingDataString(self): return """{ "name": "Display Info on LCD", @@ -74,7 +81,7 @@ class DisplayInfoOnLCD(Script): "default_value": 0, "minimum_value": 0, "maximum_value": 1, - "enabled": "display_option == 'filename_layer'" + "enabled": "display_option == 'filename_layer'" }, "maxlayer": { @@ -118,11 +125,11 @@ class DisplayInfoOnLCD(Script): "speed_factor": { "label": "Time Fudge Factor %", - "description": "Tweak this value to get better estimates. ([Actual Print Time]/[Cura Estimate]) x 100 = Time Fudge Factor. If Cura estimated 9hr and the print actually took 10hr30min then enter 117 here to adjust any estimate closer to reality.", + "description": "When using 'Display Progress' tweak this value to get better estimates. ([Actual Print Time]/[Cura Estimate]) x 100 = Time Fudge Factor. If Cura estimated 9hr and the print actually took 10hr30min then enter 117 here to adjust any estimate closer to reality. This Fudge Factor is also used to calculate the time that the print will end if you were to start it 10 minutes after slicing.", "type": "float", "unit": "%", "default_value": 100, - "enabled": "display_option == 'display_progress'" + "enabled": "enable_end_message or display_option == 'display_progress'" }, "countdown_to_pause": { @@ -131,6 +138,14 @@ class DisplayInfoOnLCD(Script): "type": "bool", "default_value": false, "enabled": "display_option == 'display_progress'" + }, + "enable_end_message": + { + "label": "Enable 'Finish-Time' Message", + "description": "Get a message when you save a fresh slice. It will show the estimated date and time that the print would finish (with a 10 minute lag from the end of slicing to the start of the print).", + "type": "bool", + "default_value": true, + "enabled": true } } }""" @@ -181,7 +196,11 @@ class DisplayInfoOnLCD(Script): i += 1 final_lines = "\n".join(lines) data[layer_index] = final_lines - + if bool(self.getSettingValueByKey("enable_end_message")): + message_str = self.message_to_user(self.getSettingValueByKey("speed_factor") / 100) + Message(title = "Display Info on LCD - Estimated Finish Time", text = message_str[0] + "\n\n" + message_str[1] + "\n" + message_str[2] + "\n" + message_str[3]).show() + return data + # Display Progress (from 'Show Progress' and 'Display Progress on LCD')--------------------------------------- elif display_option == "display_progress": # get settings @@ -215,7 +234,7 @@ class DisplayInfoOnLCD(Script): base_display_text = "" layer = data[len(data)-1] data[len(data)-1] = layer.replace(";End of Gcode" + "\n", "") - data[len(data)-1] += ";End of Gcode" + "\n" + data[len(data)-1] += ";End of Gcode" + "\n" # Search for the number of layers and the total time from the start code for index in range(len(data)): data_section = data[index] @@ -277,15 +296,15 @@ class DisplayInfoOnLCD(Script): break # overwrite the layer with the modified layer data[layer_index] = "\n".join(lines) - - # If enabled then change the ET to TP for 'Time To Pause' + + # If enabled then change the ET to TP for 'Time To Pause' if bool(self.getSettingValueByKey("countdown_to_pause")): time_list = [] time_list.append("0") time_list.append("0") this_time = 0 pause_index = 1 - + # Get the layer times for num in range(2,len(data) - 1): layer = data[num] @@ -298,7 +317,7 @@ class DisplayInfoOnLCD(Script): for qnum in range(num - 1, pause_index, -1): time_list[qnum] = str(float(this_time) - float(time_list[qnum])) + "P" pause_index = num-1 - + # Make the adjustments to the M117 (and M118) lines that are prior to a pause for num in range (2, len(data) - 1,1): layer = data[num] @@ -323,4 +342,55 @@ class DisplayInfoOnLCD(Script): M118_line = line.split("|")[0] + "| TP " + time_to_go layer = layer.replace(line, M118_line) data[num] = layer + setting_data = "" + if bool(self.getSettingValueByKey("enable_end_message")): + message_str = self.message_to_user(speed_factor) + Message(title = "Display Info on LCD - Estimated Finish Time", text = message_str[0] + "\n\n" + message_str[1] + "\n" + message_str[2] + "\n" + message_str[3]).show() return data + + def message_to_user(self, speed_factor: float): + # Message the user of the projected finish time of the print (figuring a 10 minute delay from end-of-slice to start-of-print + print_time = Application.getInstance().getPrintInformation().currentPrintTime.getDisplayString(DurationFormat.Format.ISO8601) + #Get the current data/time info + yr = int(time.strftime("%Y")) + day = int(time.strftime("%d")) + mo = int(time.strftime("%m")) + hr = int(time.strftime("%H")) + min = int(time.strftime("%M")) + sec = int(time.strftime("%S")) + date_and_time = datetime.datetime(yr, mo, day, hr, min, sec) + #Split the Cura print time + pr_hr = int(print_time.split(":")[0]) + pr_min = int(print_time.split(":")[1]) + pr_sec = int(print_time.split(":")[2]) + #Adjust the print time by 10 minutes to account for a lag in starting a print + print_seconds = pr_hr*3600 + pr_min*60 + pr_sec + 600 + #Adjust the total seconds by the Fudge Factor + adjusted_print_time = print_seconds * speed_factor + #Break down the adjusted seconds back into hh:mm:ss + adj_hr = int(adjusted_print_time/3600) + print_seconds = adjusted_print_time - (adj_hr * 3600) + adj_min = int(print_seconds) / 60 + adj_sec = int(print_seconds - (adj_min * 60)) + #Get the print time to add to the start time + time_change = datetime.timedelta(hours=adj_hr, minutes=adj_min, seconds=adj_sec) + new_time = date_and_time + time_change + #Get the day of the week that the print will end on + week_day = str(["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][int(new_time.strftime("%w"))]) + #Get the month that the print will end in + mo_str = str(["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][int(new_time.strftime("%m"))-1]) + #Make adjustments from 24hr time to 12hr time + if int(new_time.strftime("%H")) > 12: + show_hr = str(int(new_time.strftime("%H")) - 12) + ":" + show_ampm = " PM" + elif int(new_time.strftime("%H")) == 0: + show_hr = "12:" + show_ampm = " AM" + else: + show_hr = str(new_time.strftime("%H")) + ":" + show_ampm = " AM" + message_str = "\n" + "(Finish Time estimate is based on the Cura printing time estimate and using your 'Fudge Factor' of " + str(speed_factor * 100) + "% - and a 10 minute lag between saving the file and starting the print.)" + finish_str = week_day + " " + str(mo_str) + " " + str(new_time.strftime("%d")) + ", " + str(new_time.strftime("%Y")) + " at " + str(show_hr) + str(new_time.strftime("%M")) + str(show_ampm) + estimate_str = "Cura Print Time Estimate: " + str(print_time) + adjusted_str = " Adjusted Time Estimate: " + str(time_change) + " (Fudged plus 10min startup delay)" + return finish_str, estimate_str, adjusted_str, message_str \ No newline at end of file From c2a541f5e1c878b4e8bd7fc57c3b884f27e62924 Mon Sep 17 00:00:00 2001 From: GregValiant <64202104+GregValiant@users.noreply.github.com> Date: Thu, 14 Sep 2023 22:16:28 -0400 Subject: [PATCH 5/8] Update DisplayInfoOnLCD.py Changed "name" variable to "file_name" to avoid any conficts. --- .../scripts/DisplayInfoOnLCD.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py b/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py index 4718d55256..d185f22887 100644 --- a/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py +++ b/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py @@ -65,7 +65,7 @@ class DisplayInfoOnLCD(Script): "default_value": false, "enabled": "display_option == 'filename_layer'" }, - "name": + "file_name": { "label": "Text to display:", "description": "By default the current filename will be displayed on the LCD. Enter text here to override the filename and display something else.", @@ -158,16 +158,16 @@ class DisplayInfoOnLCD(Script): if display_option == "filename_layer": max_layer = 0 lcd_text = "M117 " - if self.getSettingValueByKey("name") != "": - name = self.getSettingValueByKey("name") + if self.getSettingValueByKey("file_name") != "": + file_name = self.getSettingValueByKey("file_name") else: - name = Application.getInstance().getPrintInformation().jobName + file_name = Application.getInstance().getPrintInformation().jobName if self.getSettingValueByKey("addPrefixPrinting"): lcd_text += "Printing " if not self.getSettingValueByKey("scroll"): lcd_text += "Layer " else: - lcd_text += name + " - Layer " + lcd_text += file_name + " - Layer " i = self.getSettingValueByKey("startNum") for layer in data: display_text = lcd_text + str(i) @@ -183,10 +183,10 @@ class DisplayInfoOnLCD(Script): if self.getSettingValueByKey("maxlayer"): display_text = display_text + " of " + max_layer if not self.getSettingValueByKey("scroll"): - display_text = display_text + " " + name + display_text = display_text + " " + file_name else: if not self.getSettingValueByKey("scroll"): - display_text = display_text + " " + name + "!" + display_text = display_text + " " + file_name + "!" else: display_text = display_text + "!" line_index = lines.index(line) From 4d5e4ce3c5f2e2bf01ffa7a8dc8fce550a9368f1 Mon Sep 17 00:00:00 2001 From: GregValiant <64202104+GregValiant@users.noreply.github.com> Date: Sun, 24 Sep 2023 09:40:02 -0400 Subject: [PATCH 6/8] Update DisplayInfoOnLCD.py Add a line below the ";TIME:" line to convert "seconds" to Hours:Minutes --- .../scripts/DisplayInfoOnLCD.py | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py b/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py index d185f22887..4f2bcc4771 100644 --- a/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py +++ b/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py @@ -37,7 +37,7 @@ import datetime from UM.Message import Message class DisplayInfoOnLCD(Script): - + def getSettingDataString(self): return """{ "name": "Display Info on LCD", @@ -200,7 +200,7 @@ class DisplayInfoOnLCD(Script): message_str = self.message_to_user(self.getSettingValueByKey("speed_factor") / 100) Message(title = "Display Info on LCD - Estimated Finish Time", text = message_str[0] + "\n\n" + message_str[1] + "\n" + message_str[2] + "\n" + message_str[3]).show() return data - + # Display Progress (from 'Show Progress' and 'Display Progress on LCD')--------------------------------------- elif display_option == "display_progress": # get settings @@ -218,16 +218,21 @@ class DisplayInfoOnLCD(Script): for line in lines: if ";TIME:" in line: tindex = lines.index(line) - print_time = int(line.split(":")[1]) - print_time = print_time*speed_factor + cura_time = int(line.split(":")[1]) + print_time = cura_time*speed_factor hhh = print_time/3600 hr = round(hhh // 1) mmm = round((hhh % 1) * 60) + orig_hhh = cura_time/3600 + orig_hr = round(orig_hhh // 1) + orig_mmm = round((orig_hhh % 1) * 60) if add_m118_line: lines.insert(tindex+1,"M118 Adjusted Print Time " + str(hr) + "hr " + str(mmm) + "min") lines.insert(tindex+1,"M117 ET " + str(hr) + "hr " + str(mmm) + "min") + # This line goes in to convert seconds to hours and minutes + lines.insert(tindex+1, f";Cura Time: {orig_hr}hr {orig_mmm}min") data[0] = "\n".join(lines) - data[len(data)-1] += "M117 Orig Est " + str(hr) + "hr " + str(mmm) + "min\n" - if add_m118_line: data[len(data)-1] += "M118 Orig Est w/FudgeFactor at " + str(speed_factor * 100) + "% was " + str(hr) + "hr " + str(mmm) + "min\n" + data[len(data)-1] += "M117 Orig Cura Est " + str(orig_hr) + "hr " + str(orig_mmm) + "min\n" + if add_m118_line: data[len(data)-1] += "M118 Est w/FudgeFactor " + str(speed_factor * 100) + "% was " + str(hr) + "hr " + str(mmm) + "min\n" if not display_total_layers or not display_remaining_time: base_display_text = "layer " else: @@ -347,7 +352,7 @@ class DisplayInfoOnLCD(Script): message_str = self.message_to_user(speed_factor) Message(title = "Display Info on LCD - Estimated Finish Time", text = message_str[0] + "\n\n" + message_str[1] + "\n" + message_str[2] + "\n" + message_str[3]).show() return data - + def message_to_user(self, speed_factor: float): # Message the user of the projected finish time of the print (figuring a 10 minute delay from end-of-slice to start-of-print print_time = Application.getInstance().getPrintInformation().currentPrintTime.getDisplayString(DurationFormat.Format.ISO8601) @@ -369,9 +374,9 @@ class DisplayInfoOnLCD(Script): adjusted_print_time = print_seconds * speed_factor #Break down the adjusted seconds back into hh:mm:ss adj_hr = int(adjusted_print_time/3600) - print_seconds = adjusted_print_time - (adj_hr * 3600) + print_seconds = adjusted_print_time - (adj_hr * 3600) adj_min = int(print_seconds) / 60 - adj_sec = int(print_seconds - (adj_min * 60)) + adj_sec = int(print_seconds - (adj_min * 60)) #Get the print time to add to the start time time_change = datetime.timedelta(hours=adj_hr, minutes=adj_min, seconds=adj_sec) new_time = date_and_time + time_change From c40dad5119171edc8fc18e9a244b23f9731acd7f Mon Sep 17 00:00:00 2001 From: GregValiant <64202104+GregValiant@users.noreply.github.com> Date: Wed, 11 Oct 2023 19:47:57 -0400 Subject: [PATCH 7/8] Update DisplayInfoOnLCD.py Added Print Finish Time option. Changed a couple of if statements to "line.startswith". --- .../scripts/DisplayInfoOnLCD.py | 63 ++++++++++++++----- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py b/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py index 4f2bcc4771..6d2e83d545 100644 --- a/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py +++ b/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py @@ -24,7 +24,7 @@ # - Example line on LCD: 1/479 | ET 2h13m # - Time to Pauses changes the M117/M118 lines to countdown to the next pause as 1/479 | TP 2h36m # - 'Add M118 Line' is available with either option. M118 will bounce the message back to a remote print server through the USB connection. -# - Enable 'Finish-Time' Message when checked takes the Print Time, adds 10 minutes for print start-up, and calculates when the print will end. It takes into account the Time Fudge Factor. (Available for Display Filename as well.) +# - Enable 'Finish-Time' Message - when enabled, takes the Print Time, adds 15 minutes for print start-up, and calculates when the print will end. It takes into account the Time Fudge Factor. The user may enter a print start time. This is also available for Display Filename. from ..Script import Script from UM.Application import Application @@ -125,7 +125,7 @@ class DisplayInfoOnLCD(Script): "speed_factor": { "label": "Time Fudge Factor %", - "description": "When using 'Display Progress' tweak this value to get better estimates. ([Actual Print Time]/[Cura Estimate]) x 100 = Time Fudge Factor. If Cura estimated 9hr and the print actually took 10hr30min then enter 117 here to adjust any estimate closer to reality. This Fudge Factor is also used to calculate the time that the print will end if you were to start it 10 minutes after slicing.", + "description": "When using 'Display Progress' tweak this value to get better estimates. ([Actual Print Time]/[Cura Estimate]) x 100 = Time Fudge Factor. If Cura estimated 9hr and the print actually took 10hr30min then enter 117 here to adjust any estimate closer to reality. This Fudge Factor is also used to calculate the time that the print will end if you were to start it 15 minutes after slicing.", "type": "float", "unit": "%", "default_value": 100, @@ -142,11 +142,21 @@ class DisplayInfoOnLCD(Script): "enable_end_message": { "label": "Enable 'Finish-Time' Message", - "description": "Get a message when you save a fresh slice. It will show the estimated date and time that the print would finish (with a 10 minute lag from the end of slicing to the start of the print).", + "description": "Get a message when you save a fresh slice. It will show the estimated date and time that the print would finish (with a 15 minute lag from the end of slicing to the start of the print).", "type": "bool", "default_value": true, "enabled": true + }, + "print_start_time": + { + "label": "Print Start Time (Ex 16:45)", + "description": "Use 'Military' time. 16:45 would be 4:45PM. 09:30 would be 9:30AM. If you leave this blank it will be assumed that the print start will 15 minutes after slicing.", + "type": "str", + "default_value": "", + "unit": "hrs ", + "enabled": "enable_end_message" } + } }""" @@ -179,7 +189,7 @@ class DisplayInfoOnLCD(Script): max_layer = max_layer.split(":")[1] if self.getSettingValueByKey("startNum") == 0: max_layer = str(int(max_layer) - 1) - if ";LAYER:" in line: + if line.startswith(";LAYER:"): if self.getSettingValueByKey("maxlayer"): display_text = display_text + " of " + max_layer if not self.getSettingValueByKey("scroll"): @@ -216,7 +226,7 @@ class DisplayInfoOnLCD(Script): first_section = data[0] lines = first_section.split("\n") for line in lines: - if ";TIME:" in line: + if line.startswith(";TIME:"): tindex = lines.index(line) cura_time = int(line.split(":")[1]) print_time = cura_time*speed_factor @@ -350,26 +360,40 @@ class DisplayInfoOnLCD(Script): setting_data = "" if bool(self.getSettingValueByKey("enable_end_message")): message_str = self.message_to_user(speed_factor) - Message(title = "Display Info on LCD - Estimated Finish Time", text = message_str[0] + "\n\n" + message_str[1] + "\n" + message_str[2] + "\n" + message_str[3]).show() + Message(title = "[Display Info on LCD] - Estimated Finish Time", text = message_str[0] + "\n\n" + message_str[1] + "\n" + message_str[2] + "\n" + message_str[3]).show() return data def message_to_user(self, speed_factor: float): - # Message the user of the projected finish time of the print (figuring a 10 minute delay from end-of-slice to start-of-print + # Message the user of the projected finish time of the print (figuring a 15 minute delay from end-of-slice to start-of-print print_time = Application.getInstance().getPrintInformation().currentPrintTime.getDisplayString(DurationFormat.Format.ISO8601) + print_start_time = self.getSettingValueByKey("print_start_time") + # If the user entered a print start time make sure it is in the correct format or ignore it. + if print_start_time == "" or print_start_time == "0" or len(print_start_time) != 5 or not ":" in print_start_time: + print_start_time = "" + # Change the print start time to proper time format, or, use the current time + if print_start_time != "": + hr = int(print_start_time.split(":")[0]) + min = int(print_start_time.split(":")[1]) + sec = 0 + fifteen_minute_delay = 0 + else: + hr = int(time.strftime("%H")) + min = int(time.strftime("%M")) + sec = int(time.strftime("%S")) + fifteen_minute_delay = 900 + #Get the current data/time info yr = int(time.strftime("%Y")) day = int(time.strftime("%d")) mo = int(time.strftime("%m")) - hr = int(time.strftime("%H")) - min = int(time.strftime("%M")) - sec = int(time.strftime("%S")) + date_and_time = datetime.datetime(yr, mo, day, hr, min, sec) #Split the Cura print time pr_hr = int(print_time.split(":")[0]) pr_min = int(print_time.split(":")[1]) pr_sec = int(print_time.split(":")[2]) - #Adjust the print time by 10 minutes to account for a lag in starting a print - print_seconds = pr_hr*3600 + pr_min*60 + pr_sec + 600 + #Adjust the print time if none was entered + print_seconds = pr_hr*3600 + pr_min*60 + pr_sec + fifteen_minute_delay #Adjust the total seconds by the Fudge Factor adjusted_print_time = print_seconds * speed_factor #Break down the adjusted seconds back into hh:mm:ss @@ -394,8 +418,15 @@ class DisplayInfoOnLCD(Script): else: show_hr = str(new_time.strftime("%H")) + ":" show_ampm = " AM" - message_str = "\n" + "(Finish Time estimate is based on the Cura printing time estimate and using your 'Fudge Factor' of " + str(speed_factor * 100) + "% - and a 10 minute lag between saving the file and starting the print.)" + if print_start_time == "": + start_str = "and a 15 minute lag between saving the file and starting the print." + else: + start_str = "and your entered 'print start time' of " + print_start_time + "hrs." + if print_start_time != "": + print_start_str = "Print Start Time................." + str(print_start_time) + "hrs" + else: + print_start_str = "Print Start Time.................15 minutes from now." + estimate_str = "Cura Time Estimate.........." + str(print_time) + adjusted_str = "Adjusted Time Estimate..." + str(time_change) finish_str = week_day + " " + str(mo_str) + " " + str(new_time.strftime("%d")) + ", " + str(new_time.strftime("%Y")) + " at " + str(show_hr) + str(new_time.strftime("%M")) + str(show_ampm) - estimate_str = "Cura Print Time Estimate: " + str(print_time) - adjusted_str = " Adjusted Time Estimate: " + str(time_change) + " (Fudged plus 10min startup delay)" - return finish_str, estimate_str, adjusted_str, message_str \ No newline at end of file + return finish_str, estimate_str, adjusted_str, print_start_str \ No newline at end of file From cd6e583f435c65ab964921cdc390db805483417c Mon Sep 17 00:00:00 2001 From: GregValiant <64202104+GregValiant@users.noreply.github.com> Date: Mon, 16 Oct 2023 14:22:10 -0400 Subject: [PATCH 8/8] Update DisplayInfoOnLCD.py Add pause count notification Update DisplayInfoOnLCD.py Moved some line insertions to accommodate newer Creality firmware. Change DisplayFIlename and DIsplayProgress Add messages to use DIsplay Info and add exit code. Update DisplayInfoOnLCD.py Some changes --- .../scripts/DisplayFilenameAndLayerOnLCD.py | 37 +++++++++++++++++ .../scripts/DisplayInfoOnLCD.py | 32 +++++++++++---- .../scripts/DisplayProgressOnLCD.py | 40 +++++++++++++++++++ 3 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 plugins/PostProcessingPlugin/scripts/DisplayFilenameAndLayerOnLCD.py create mode 100644 plugins/PostProcessingPlugin/scripts/DisplayProgressOnLCD.py diff --git a/plugins/PostProcessingPlugin/scripts/DisplayFilenameAndLayerOnLCD.py b/plugins/PostProcessingPlugin/scripts/DisplayFilenameAndLayerOnLCD.py new file mode 100644 index 0000000000..bfe04b2bea --- /dev/null +++ b/plugins/PostProcessingPlugin/scripts/DisplayFilenameAndLayerOnLCD.py @@ -0,0 +1,37 @@ +# Cura PostProcessingPlugin +# Author: Amanda de Castilho +# Date: August 28, 2018 +# Modified: November 16, 2018 by Joshua Pope-Lewis + +# Description: This plugin is now an option in 'Display Info on LCD' + +from ..Script import Script +from UM.Application import Application +from UM.Message import Message + +class DisplayFilenameAndLayerOnLCD(Script): + def initialize(self) -> None: + Message(title = "[Display Filename and Layer on LCD]", text = "This script is now an option in 'Display Info on LCD'. This post processor no longer works.").show() + + def getSettingDataString(self): + return """{ + "name": "Display Filename And Layer On LCD", + "key": "DisplayFilenameAndLayerOnLCD", + "metadata": {}, + "version": 2, + "settings": + { + "enable_script": + { + "label": "Deprecated/Obsolete", + "description": "This script is now included in 'Display Info on LCD'.", + "type": "bool", + "default_value": true + } + } + }""" + + def execute(self, data): + Message(title = "[Display Filename and Layer on LCD]", text = "This post is now included in 'Display Info on LCD'. This script will exit.").show() + data[0] += "; [Display Filename and Layer on LCD] Did not run. It is now included in 'Display Info on LCD'.\n" + return data diff --git a/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py b/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py index 6d2e83d545..bfd88534f8 100644 --- a/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py +++ b/plugins/PostProcessingPlugin/scripts/DisplayInfoOnLCD.py @@ -134,7 +134,7 @@ class DisplayInfoOnLCD(Script): "countdown_to_pause": { "label": "Countdown to Pauses", - "description": "Instead of layer number and remaining print time the LCD will show 'layers remaining before pause' and 'Est Time to Pause' (ETP).", + "description": "When enabled - DisplayInfoOnLCD must run AFTER all PauseAtHeight and Filament Change scripts. Instead of layer number and remaining print time the LCD will show 'layers remaining before pause/filament change and the time to pause/filament change' (TP).", "type": "bool", "default_value": false, "enabled": "display_option == 'display_progress'" @@ -163,7 +163,7 @@ class DisplayInfoOnLCD(Script): def execute(self, data): display_option = self.getSettingValueByKey("display_option") add_m118_line = self.getSettingValueByKey("add_m118_line") - + # This is Display Filename and Layer on LCD--------------------------------------------------------- if display_option == "filename_layer": max_layer = 0 @@ -229,17 +229,33 @@ class DisplayInfoOnLCD(Script): if line.startswith(";TIME:"): tindex = lines.index(line) cura_time = int(line.split(":")[1]) - print_time = cura_time*speed_factor + print_time = cura_time * speed_factor hhh = print_time/3600 hr = round(hhh // 1) mmm = round((hhh % 1) * 60) orig_hhh = cura_time/3600 orig_hr = round(orig_hhh // 1) - orig_mmm = round((orig_hhh % 1) * 60) - if add_m118_line: lines.insert(tindex+1,"M118 Adjusted Print Time " + str(hr) + "hr " + str(mmm) + "min") - lines.insert(tindex+1,"M117 ET " + str(hr) + "hr " + str(mmm) + "min") + orig_min = int((cura_time - (orig_hr * 3600))/60) # Not rounded up + orig_mmm = round((orig_hhh % 1) * 60) # Rounded up + orig_sec = round(cura_time - orig_hr * 3600 - orig_min * 60) + if add_m118_line: lines.insert(tindex + 3,"M118 Adjusted Print Time " + str(hr) + "hr " + str(mmm) + "min") + lines.insert(tindex + 3,"M117 ET " + str(hr) + "hr " + str(mmm) + "min") + # If Countdown to pause is enabled then count the pauses and/or filament changes + pause_str = "" + if bool(self.getSettingValueByKey("countdown_to_pause")): + pause_count = 0 + filament_change_count = 0 + for num in range(2,len(data) - 1, 1): + if "PauseAtHeight.py" in data[num]: + pause_count += 1 + if "M600" in data[num]: + filament_change_count += 1 + if pause_count > 0: + pause_str = f" with {pause_count} pause(s)" + if filament_change_count > 0: + pause_str += f" and {filament_change_count} filament change(s)" # This line goes in to convert seconds to hours and minutes - lines.insert(tindex+1, f";Cura Time: {orig_hr}hr {orig_mmm}min") + lines.insert(tindex + 3, f";Cura Time Estimate: {cura_time}sec = {orig_hr}hr {orig_min}min {orig_sec}sec {pause_str}") data[0] = "\n".join(lines) data[len(data)-1] += "M117 Orig Cura Est " + str(orig_hr) + "hr " + str(orig_mmm) + "min\n" if add_m118_line: data[len(data)-1] += "M118 Est w/FudgeFactor " + str(speed_factor * 100) + "% was " + str(hr) + "hr " + str(mmm) + "min\n" @@ -328,7 +344,7 @@ class DisplayInfoOnLCD(Script): if line.startswith(";TIME_ELAPSED:"): this_time = (float(line.split(":")[1]))*speed_factor time_list.append(str(this_time)) - if "PauseAtHeight.py" in layer: + if "PauseAtHeight.py" in layer or "M600" in layer: for qnum in range(num - 1, pause_index, -1): time_list[qnum] = str(float(this_time) - float(time_list[qnum])) + "P" pause_index = num-1 diff --git a/plugins/PostProcessingPlugin/scripts/DisplayProgressOnLCD.py b/plugins/PostProcessingPlugin/scripts/DisplayProgressOnLCD.py new file mode 100644 index 0000000000..4d24aedac0 --- /dev/null +++ b/plugins/PostProcessingPlugin/scripts/DisplayProgressOnLCD.py @@ -0,0 +1,40 @@ +# Cura PostProcessingPlugin +# Author: Mathias Lyngklip Kjeldgaard, Alexander Gee, Kimmo Toivanen, Inigo Martinez +# Date: July 31, 2019 +# Modified: Nov 30, 2021 + +# Description: This plugin displays progress on the LCD. It can output the estimated time remaining and the completion percentage. + +from ..Script import Script + +import re +import datetime +from UM.Message import Message + +class DisplayProgressOnLCD(Script): + + def initialize(self) -> None: + Message(title = "[Display Progress on LCD]", text = "This script is now an option in 'Display Info on LCD'. This post processor no longer works.").show() + + def getSettingDataString(self): + return """{ + "name": "Display Progress On LCD", + "key": "DisplayProgressOnLCD", + "metadata": {}, + "version": 2, + "settings": + { + "enable_script": + { + "label": "Deprecated/Obsolete", + "description": "This script is now included in 'Display Info on LCD'.", + "type": "bool", + "default_value": true + } + } + }""" + + def execute(self, data): + Message(title = "[Display Progress on LCD]", text = "This post is now included in 'Display Info on LCD'. This script will exit.").show() + data[0] += "; [Display Progress on LCD] Did not run. It is now included in 'Display Info on LCD'.\n" + return data