I wrote a post process plugin to solve this problem
# Copyright (c) 2020 Belin Fieldson
# LaserCode is released under the terms of the AGPLv3 or higher.
from ..Script import Script
class LaserCode(Script):
version = "1.01"
def __init__(self):
super().__init__()
def getSettingDataString(self):
return """{
"name":"Laser Code v.(""" + self.version + """)",
"key":"LaserCode",
"metadata": {},
"version": 2,
"settings":
{
"_activation":
{
"label": "Laser Activate",
"description": "The code to use to activate the laser",
"type": "str",
"default_value": "M3"
},
"_deactivation":
{
"label": "Laser Deactivate",
"description": "The code to use to deactivate the laser",
"type": "str",
"default_value": "M5"
},
"_prefixActivation":
{
"label": "Active GCODE",
"description": "The gcode that the activate code should be prefixed to",
"type": "str",
"default_value": "G1"
},
"_prefixDeactivation":
{
"label": "Inactive GCODE",
"description": "The gcode that the deactivate code should be prefixed to",
"type": "str",
"default_value": "G0"
}
}
}"""
def execute(self, data):
activation = self.getSettingValueByKey("_activation");
deactivation = self.getSettingValueByKey("_deactivation");
searchActivation = self.getSettingValueByKey("_prefixActivation");
searchDeactivation = self.getSettingValueByKey("_prefixDeactivation");
activated = False;
# Declare output gcode
for layer in data:
index = data.index(layer)
lines = layer.split("\n")
newLayer = ""
for line in lines:
if (searchActivation in line and not activated):
newLayer += activation + "\n"
activated = True
if (searchDeactivation in line and activated):
newLayer += deactivation + "\n"
activated = False
newLayer += line + "\n"
data[index] = newLayer
return data