forked from fieldOfView/Cura-SimpleShapes
-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
FlowTower.py
126 lines (109 loc) · 5.2 KB
/
FlowTower.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#------------------------------------------------------------------------------------------------------------------------------------
#
# Cura PostProcessing Script
# Author: 5axes
# Date: August 29, 2021
#
# Description: postprocessing script to easily define a Flow Tower
#
#------------------------------------------------------------------------------------------------------------------------------------
#
# Version 1.0 29/08/2021
# Version 1.1 15/02/2022 Change Int for Layeroffset & changelayer
#
#------------------------------------------------------------------------------------------------------------------------------------
from ..Script import Script
from UM.Application import Application
from UM.Logger import Logger
import re #To perform the search
__version__ = '1.1'
class FlowTower(Script):
def __init__(self):
super().__init__()
def getSettingDataString(self):
return """{
"name": "FlowTower",
"key": "FlowTower",
"metadata": {},
"version": 2,
"settings":
{
"startValue":
{
"label": "Starting value",
"description": "The starting value of the Tower.",
"type": "float",
"default_value": 110.0
},
"valueChange":
{
"label": "Value Increment",
"description": "The value change of each block, can be positive or negative. I you want 110 and then 108, you need to set this to -2.",
"type": "float",
"default_value": -2.0
},
"changelayer":
{
"label": "Change Layer",
"description": "How many layers needs to be printed before the value should be changed.",
"type": "int",
"default_value": 40,
"minimum_value": 1,
"maximum_value": 1000,
"maximum_value_warning": 100
},
"changelayeroffset":
{
"label": "Change Layer Offset",
"description": "If the print has a base, indicate the number of layers from which to start the changes.",
"type": "int",
"default_value": 0,
"minimum_value": 0,
"maximum_value": 1000,
"maximum_value_warning": 100
},
"lcdfeedback":
{
"label": "Display details on LCD",
"description": "This setting will insert M117 gcode instructions, to display current modification in the G-Code is being used.",
"type": "bool",
"default_value": true
}
}
}"""
def execute(self, data):
UseLcd = self.getSettingValueByKey("lcdfeedback")
StartValue = float(self.getSettingValueByKey("startValue"))
ValueChange = float(self.getSettingValueByKey("valueChange"))
ChangeLayer = int(self.getSettingValueByKey("changelayer"))
ChangeLayerOffset = int(self.getSettingValueByKey("changelayeroffset"))
ChangeLayerOffset += 2 # Modification to take into account the numbering offset in Gcode
# layer_index = 0 for initial Block 1= Start Gcode normaly first layer = 0
CurrentValue = StartValue
Command=""
idl=0
for layer in data:
layer_index = data.index(layer)
lines = layer.split("\n")
for line in lines:
if line.startswith(";LAYER:"):
line_index = lines.index(line)
# Logger.log('d', 'Instruction : {}'.format(Instruction))
if (layer_index==ChangeLayerOffset):
Command = "M221 S{:d}".format(int(CurrentValue))
lcd_gcode = "M117 Flow S{:d}".format(int(CurrentValue))
lines.insert(line_index + 1, ";TYPE:CUSTOM LAYER")
lines.insert(line_index + 2, Command)
if UseLcd == True :
lines.insert(line_index + 3, lcd_gcode)
if ((layer_index-ChangeLayerOffset) % ChangeLayer == 0) and ((layer_index-ChangeLayerOffset)>0):
CurrentValue += ValueChange
Command = "M221 S{:d}".format(int(CurrentValue))
lcd_gcode = "M117 Flow S{:d}".format(int(CurrentValue))
lines.insert(line_index + 1, ";TYPE:CUSTOM VALUE")
lines.insert(line_index + 2, Command)
if UseLcd == True :
lines.insert(line_index + 3, lcd_gcode)
result = "\n".join(lines)
data[layer_index] = result
return data