-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathDiagonalZHop.py
97 lines (77 loc) · 3.2 KB
/
DiagonalZHop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# DiagonalZHop
"""
DiagonalZHop for 3D prints.
Diagonal Z Hop
Author: 5axes
Version: 0.1
Note : https://github.com/Ultimaker/Cura/issues/15583
"""
import re #To perform the search
from ..Script import Script
from UM.Application import Application
from UM.Logger import Logger
from UM.Message import Message
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
__version__ = '0.1'
class DiagonalZHop(Script):
def getSettingDataString(self):
return """{
"name": "Diagonal Z Hop",
"key": "DiagonalZHop",
"metadata": {},
"version": 2,
"settings":
{
"extruder_nb":
{
"label": "Extruder Id",
"description": "Define extruder Id in case of multi extruders",
"unit": "",
"type": "int",
"default_value": 1
}
}
}"""
## -----------------------------------------------------------------------------
#
# Main Prog
#
## -----------------------------------------------------------------------------
def execute(self, data):
extruder_id = self.getSettingValueByKey("extruder_nb")
extruder_id = extruder_id -1
# machine_extruder_count
extruder_count=Application.getInstance().getGlobalContainerStack().getProperty("machine_extruder_count", "value")
extruder_count = extruder_count-1
if extruder_id>extruder_count :
extruder_id=extruder_count
extrud = Application.getInstance().getGlobalContainerStack().extruderList
# Get the Cura retraction_hop and speed_z_hop as Zhop parameter
retraction_hop = float(extrud[extruder_id].getProperty("retraction_hop", "value"))
speed_z_hop = int(extrud[extruder_id].getProperty("speed_z_hop", "value"))
speed_z_hop = speed_z_hop * 60
# Check if Z hop is desactivated
retraction_hop_enabled= extrud[extruder_id].getProperty("retraction_hop_enabled", "value")
if retraction_hop_enabled == False:
#
Logger.log('d', 'Mode Z Hop must be activated !')
Message(catalog.i18nc("@message", "Mode Z Hop must be activated !"), title = catalog.i18nc("@info:title", "Post Processing")).show()
return data
In_Zhop = False
for layer_index, layer in enumerate(data):
lines = layer.split("\n")
for line_index, currentLine in enumerate(lines):
# Zhop G1
if currentLine.startswith("G1") and "Z" in currentLine and not "X" in currentLine and not "Y" in currentLine and not In_Zhop :
In_Zhop = True
lines[line_index] = ";" + currentLine + " ; Modified by DiagonalZhop"
else :
if currentLine.startswith("G1") and "Z" in currentLine and not "X" in currentLine and not "Y" in currentLine :
In_Zhop = False
#
# end of analyse
#
final_lines = "\n".join(lines)
data[layer_index] = final_lines
return data