-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better support Cura and note detected slicer in output
Adds support for Cura 4.13, which changes the metadata format somewhat. Also adds a post processing script that can be used in Cura(tested on Linux with Cura 4.13). Install to `scripts` directory under Cura resources, e.g. `~/.local/share/cura/4.13/scripts/`. Finally, we now append a comment to `post-process` output with tool version and detected slicer.
- Loading branch information
Showing
3 changed files
with
111 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Copyright (c) 2022 Lasse Dalegaard | ||
# MIT licensed | ||
|
||
from ..Script import Script | ||
from tempfile import TemporaryDirectory | ||
import subprocess | ||
import shutil | ||
import os | ||
|
||
class KlipperEstimator(Script): | ||
""" | ||
Runs klipper_estimator on the resulting gcode. | ||
""" | ||
|
||
def getSettingDataString(self): | ||
return """{ | ||
"name": "Klipper estimator", | ||
"key": "KlipperEstimator", | ||
"metadata": {}, | ||
"version": 2, | ||
"settings": | ||
{ | ||
"path": | ||
{ | ||
"label": "Path to klipper_estimator", | ||
"description": "The path to the klipper_estimator binary.", | ||
"type": "str", | ||
"default_value": "" | ||
}, | ||
"config_kind": | ||
{ | ||
"label": "Kind of config to use(file or moonraker_url)", | ||
"description": "", | ||
"type": "str", | ||
"default_value": "" | ||
}, | ||
"config_arg": | ||
{ | ||
"label": "Config argument", | ||
"description": "Path for file, URL for Moonraker", | ||
"type": "str", | ||
"default_value": "" | ||
} | ||
} | ||
}""" | ||
|
||
def execute(self, data): | ||
with TemporaryDirectory() as work_dir: | ||
filename = os.path.join(work_dir, "work.gcode") | ||
with open(filename, 'w') as work_file: | ||
for line in data: | ||
work_file.write(line + "\n") | ||
|
||
args = [ | ||
self.getSettingValueByKey("path"), | ||
"--config_" + self.getSettingValueByKey("config_kind"), | ||
self.getSettingValueByKey("config_arg"), | ||
"post-process", | ||
filename, | ||
] | ||
|
||
ret = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
if ret.returncode != 0: | ||
raise RuntimeError("Failed to run klipper_estimator\n%s" % (ret.stdout,)) | ||
|
||
with open(filename) as work_file: | ||
return work_file.readlines() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters