What is the problem?
I moved the start GCode from CURA to OctoPrint and commented it out so I could put it back and also to keep as a reference. I did the same for the end GCode, altering it to use a snippet, and also modified the afterPrintCancelled script with part of the same end code. The start GCode executes, as it draws the same purge line it always did, but when I cancel a print, the printer just stops and doesn't move the hotend out of the way. The same happens with afterPrintCancelled. I came down this morning and the hotend was stopped where he last move had left it - fortunately there was no damage to the model.
afterPrintDone:
G91 ;Relative positioning
G1 E-2 F2700 ;Retract a bit
G1 E-2 Z0.2 F2400 ;Retract and raise Z
G1 X5 Y5 F3000 ;Wipe out
G1 Z10 ;Raise Z more
G90 ;Absolute positioning
G1 X0 Y235 ;Present print
; disable motors, heaters and fan
{% snippet 'DisableMotorsAndHeaters' %}
afterPrintCancelled:
G91 ;Relative positioning
G1 E-2 F2700 ;Retract a bit
G1 E-2 Z0.5 F2400 ;Retract and raise Z
G1 X5 Y5 F3000 ;Wipe out
G1 Z10 ;Raise Z more
; disable motors, heaters and fan
{% snippet 'DisableMotorsAndHeaters' %}
And snippets/DisableMotorsAndHeaters
; disable motors
M84 X Y E
;disable all heaters
{% snippet 'disable_hotends' %}
{% snippet 'disable_bed' %}
;disable fan
M106 S0
Looking in the log, it seems that OctoPrint is looking for 'gcode/snippets/snippets/disable_hotend'.
I thought the disable_hotend and disable_bed snippets were predefined as Builtin Scripts? In any event, I can't find any files with those names on the disk. Am I wron? Do I need to create them?
Also if I create them, do I put them in 'gcode/snippets' or 'gcode/snippets/snippets'? What happens if I use further low level snippets? Will I need 'gcode/snippets/snippets/snippets' etc? Would I need multiple copies of snippets at different levels? This would defeat the main purpose of having them which is to have a single common piece of code in one location.
By the way, I realise that, for now, I could just put the GCode commands M104 T0 S0
and M140 S0
in the files, but if I ever change printers...
What did you already try to solve it?
Checked log and script syntax.
I also tried creating 'snippets/disable_hotends' and 'snippets/disable_bed', even though they are supposed to be built in, but it still failed looking for 'gcode/snippets/snippets/disable_hotends'.
Having created the supposedly builtin snippets, I then created a soft link
ln -s snippets/snippets snippet
This then failed with the error:
IOError: [Errno 40] Too many levels of symbolic links: u'/home/pi/.octoprint/scripts/gcode/snippets/snippets/disable_hotends'
For now, the only workaround I've come up with is to put the "builtin" snippet code inline:
; disable motors
M84 X Y E
;disable all heaters
;;;--- snippet 'disable_hotends' ---
{% if printer_profile.extruder.sharedNozzle %}
M104 T0 S0
{% else %}
{% for tool in range(printer_profile.extruder.count) %}
M104 T{{ tool }} S0
{% endfor %}
{% endif %}
;;;--- snippet 'disable_bed' ---
{% if printer_profile.heatedBed %}
M140 S0
{% endif %}
;disable fan
M106 S0
Logs - octoprint.log
2020-06-17 13:06:17,761 - octoprint.events - INFO - Executing a system command
2020-06-17 13:06:17,851 - octoprint.settings - ERROR - Exception while trying to render script gcode:afterPrintCancelled
Traceback (most recent call last):
File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/settings.py", line 1632, in loadScript
script = template.render(**context)
File "/home/pi/oprint/local/lib/python2.7/site-packages/jinja2/environment.py", line 989, in render
return self.environment.handle_exception(exc_info, True)
File "/home/pi/oprint/local/lib/python2.7/site-packages/jinja2/environment.py", line 754, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/pi/.octoprint/scripts/gcode/afterPrintCancelled", line 7, in top-level template code
{% snippet 'DisableMotorsAndHeaters' %}
File "/home/pi/.octoprint/scripts/gcode/snippets/DisableMotorsAndHeaters", line 5, in top-level template code
{% snippet 'disable_hotends' %}
File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/settings.py", line 760, in get_source
return self._default.get_source(environment, template)
File "/home/pi/oprint/local/lib/python2.7/site-packages/jinja2/loaders.py", line 399, in get_source
raise TemplateNotFound(template)
TemplateNotFound: gcode/snippets/snippets/disable_hotends
2020-06-17 13:06:17,883 - octoprint.plugins.DisplayLayerProgress - INFO - Printing stopped. Detailed progress stopped.
2020-06-17 13:06:17,900 - octoprint.util.comm - INFO - Changing monitoring state from "Cancelling" to "Operational"
2020-06-17 13:06:18,220 - octoprint.plugins.detailedprogress - INFO - Printing stopped. Detailed progress stopped.
Additional information about your setup
OctoPrint version: 1.4.0
OctoPi version: 0.17.0
Printer: CReality Ender-3
Printer firmware: Marlin 2.0.5.3
Browser: Chrome (83.0 at time of log)
Operating system: Windows 10 2004 Build 19645