Skip to content

How does the plugin works

electronicm edited this page Sep 9, 2021 · 13 revisions

How does the plugin works (since V1.21.0+)

The following description gives you some insides about how the plugin works (with default-settings).

During fileupload

  • If you upload a file via Web-UI or via OctoPrint-API (used by Slicers like CURA) each gcode line is scanned
  • If a layer-comment is identified (e.g. ;LAYER:10) an M117-command is added to the gcode. The result looks like this:
...
;LAYER:10
M117 INDICATOR-Layer10
...
  • The identification is done via a few regular expressions. E.g for CURA ;\s*LAYER:\s*([0-9]+).*

    Some slicers are not able to include the layer number directly into the gcode, instead they just comment a beginning of a layer-section, like this: ;BEFORE_LAYER_CHANGE. In that case the plugin counts the appearance of this text.

    The default settings include expressions for CURA, Simplify3D, ideaMakerIn, KISSlicer, Slic3r

  • ATTENTION: For performance reason the scanner only includes comments that where begins in column one of a line

    Working Example:

    ; move to layer: 10
    G1 X45.733 Y59.266 
    

    Not working:

    G1 X45.733 Y59.266 ; move to layer: 10
    
  • HINT: You can disable the "adding-feature" during upload, but then your slicer needs to add the M117 INDICATOR into your gcode.

  • HINT: If you disable/uninstall the plugin, the M117 INDICATOR commands were still in the uploaded files. You need to reupload the file, if you want to prevent that INDICATOR-Layer appears in your printer-display!

  • But why did you do that??? Because during print OctoPrint doesn't provide the comments to the "plugin-processors", only real gcode. Thats the reason why I added this M117 Indicator GCode.

During print

  • The plugin listen on different events, parse the event-payload and send this informations to the UI, EventBus and also to the printer.

Here are the events:

  1. When print height changed (this is calculated based on G command and Z being present in your gcode)
  2. When layer number changed (this is calculated based on M117 INDICATOR-Layer in your gcode)
  3. When saving settings or OctoPrint UI requested it
  4. Every time if you have "Only while printing" checked and you are printing (this one is very dangerous)
  5. When print progress changed - I think it is disabled by default
  6. When feed rate changed (this is calculated based on G command and F being present in your gcode) - I think it is disabled by default
  7. When fan speed changed (this is calculated based on M106 in your gcode) - I think it is disabled by default

HINT: It is only sent, if the "display-message" is really changed. E.g. the display should only show layer and progress, like this 1/23 34%. If the feedrate is changed 100.000times, it is not sent to the printer/UI.

Technical details about "event-listening"

Additional infos

If you print from SD-Card the plugin is not involved, because the GCode is not passed thru OctoPrint during print and can't analysed by the plugins -> no layer-informations could be displayed.

Manuell adding Layer-Indicators via Slicer

If you use large gcode files (>50MB) it could be necessary to add the Layer indicators via your slicer instead of during upload by the Raspi. Turn off the checkbox in the settings Add Layer-Indicators during upload

PrusaSlicer 2.2.0

go to Printer Settings, Custom G-code, Before layer change G-Code, and add (for example):

M117 INDICATOR-Layer[layer_num]

CURA

Unfortunately Cura doesn't support layer numbers during adding custom gcode...so I wrote a Cura PostProcesser Script. It is based on the default script 'Insert at layer change'.

Installation:

  • Download InsertAtLayerChangeEnhancement from here
  • Copy the file to your Cura PostProcessingPlugin-Directory (next to InsertAtLayerChange.py)
MacOS: cura/Resources/plugins/plugins/PostProcessingPlugin
Windows: C:\Program Files\Ultimaker Cura [Version]\plugins\PostProcessingPlugin\scripts
  • Restart/Start Cura
  • Go to Extension / Post Processing / Modify G-Code ... and add Insert at layer change (enhancement)
  • Select Before
  • And enter: M117 INDICATOR-Layer[layer_num]

After slicing and saving the file the gcode looks like this:

...
;LAYER_COUNT:44
M117 INDICATOR-Layer0
;LAYER:0
...
M117 INDICATOR-Layer1
;LAYER:1
...

....maybe you should read this as well. I found an other option without installation a new PostProcessing-Script ;-)

Just use the build in "Search and Replace" Script

  • Search: ;Layer:
  • Replace: M117 INDICATOR-Layer
  • Leave reg ex unchecked