mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-25 23:53:56 -06:00
Merge pull request #490 from markwal/master
Add back placeholder expansion for start/end gcode
This commit is contained in:
commit
d39e8b7613
3 changed files with 40 additions and 3 deletions
|
@ -273,4 +273,4 @@ class CuraEngineBackend(Backend):
|
||||||
self._process.terminate()
|
self._process.terminate()
|
||||||
except: # terminating a process that is already terminating causes an exception, silently ignore this.
|
except: # terminating a process that is already terminating causes an exception, silently ignore this.
|
||||||
pass
|
pass
|
||||||
self.slicingCancelled.emit()
|
self.slicingCancelled.emit()
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
# Cura is released under the terms of the AGPLv3 or higher.
|
# Cura is released under the terms of the AGPLv3 or higher.
|
||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
|
from string import Formatter
|
||||||
|
import traceback
|
||||||
|
|
||||||
from UM.Job import Job
|
from UM.Job import Job
|
||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
|
@ -14,6 +16,19 @@ from cura.OneAtATimeIterator import OneAtATimeIterator
|
||||||
|
|
||||||
from . import Cura_pb2
|
from . import Cura_pb2
|
||||||
|
|
||||||
|
## Formatter class that handles token expansion in start/end gcod
|
||||||
|
class GcodeStartEndFormatter(Formatter):
|
||||||
|
def get_value(self, key, args, kwargs):
|
||||||
|
if isinstance(key, str):
|
||||||
|
try:
|
||||||
|
return kwargs[key]
|
||||||
|
except KeyError:
|
||||||
|
Logger.log("w", "Unable to replace '%s' placeholder in start/end gcode", key)
|
||||||
|
return "{" + key + "}"
|
||||||
|
else:
|
||||||
|
Logger.log("w", "Incorrectly formatted placeholder '%s' in start/end gcode", key)
|
||||||
|
return "{" + str(key) + "}"
|
||||||
|
|
||||||
## Job class that handles sending the current scene data to CuraEngine
|
## Job class that handles sending the current scene data to CuraEngine
|
||||||
class StartSliceJob(Job):
|
class StartSliceJob(Job):
|
||||||
def __init__(self, profile, socket):
|
def __init__(self, profile, socket):
|
||||||
|
@ -90,12 +105,28 @@ class StartSliceJob(Job):
|
||||||
|
|
||||||
self.setResult(True)
|
self.setResult(True)
|
||||||
|
|
||||||
|
def _expandGcodeTokens(self, key, value, settings):
|
||||||
|
try:
|
||||||
|
# any setting can be used as a token
|
||||||
|
fmt = GcodeStartEndFormatter()
|
||||||
|
return str(fmt.format(value, **settings)).encode("utf-8")
|
||||||
|
except:
|
||||||
|
Logger.log("w", "Unabled to do token replacement on start/end gcode %s", traceback.format_exc())
|
||||||
|
return str(value).encode("utf-8")
|
||||||
|
|
||||||
def _sendSettings(self, profile):
|
def _sendSettings(self, profile):
|
||||||
msg = Cura_pb2.SettingList()
|
msg = Cura_pb2.SettingList()
|
||||||
for key, value in profile.getAllSettingValues(include_machine = True).items():
|
settings = profile.getAllSettingValues(include_machine = True)
|
||||||
|
start_gcode = settings["machine_start_gcode"]
|
||||||
|
settings["material_bed_temp_prepend"] = not "{material_bed_temperature}" in start_gcode
|
||||||
|
settings["material_print_temp_prepend"] = not "{material_print_temperature" in start_gcode
|
||||||
|
for key, value in settings.items():
|
||||||
s = msg.settings.add()
|
s = msg.settings.add()
|
||||||
s.name = key
|
s.name = key
|
||||||
s.value = str(value).encode("utf-8")
|
if key == "machine_start_gcode" or key == "machine_end_gcode":
|
||||||
|
s.value = self._expandGcodeTokens(key, value, settings)
|
||||||
|
else:
|
||||||
|
s.value = str(value).encode("utf-8")
|
||||||
|
|
||||||
self._socket.sendMessage(msg)
|
self._socket.sendMessage(msg)
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,12 @@
|
||||||
"description": "Gcode commands to be executed at the very end - separated by \\n.",
|
"description": "Gcode commands to be executed at the very end - separated by \\n.",
|
||||||
"default": "M104 S0\nM140 S0\n;Retract the filament\nG92 E1\nG1 E-1 F300\nG28 X0 Y0\nM84"
|
"default": "M104 S0\nM140 S0\n;Retract the filament\nG92 E1\nG1 E-1 F300\nG28 X0 Y0\nM84"
|
||||||
},
|
},
|
||||||
|
"material_bed_temp_wait": {
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
|
"material_print_temp_wait": {
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
"machine_width": {
|
"machine_width": {
|
||||||
"description": "The width (X-direction) of the printable area.",
|
"description": "The width (X-direction) of the printable area.",
|
||||||
"default": 100
|
"default": 100
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue