-
Notifications
You must be signed in to change notification settings - Fork 5
/
Slcr.py
100 lines (78 loc) · 2.63 KB
/
Slcr.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
import os, importlib, sys, FreeCAD, subprocess, configparser
from SlcrDoc import SlcrDoc
from SlcrDialogUtil import DialogUtil
import configparser
def exportVisible():
try:
doc=SlcrDoc()
doc.exportVisible()
DialogUtil.showInfoMessage(
"STL exported to:\n\n"+
doc.getStlFileName()
)
except Exception as e:
DialogUtil.showErrorMessage(e)
def slice():
global Slcr_subprocess
try:
Slcr_subprocess
except NameError:
Slcr_subprocess=None
try:
doc=SlcrDoc()
doc.exportVisible()
preferences=FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/slcr")
slic3rPath=preferences.GetString('slic3rPath')
if not slic3rPath.strip():
raise Exception("Please set the path to the slic3r executable in preferences")
if Slcr_subprocess:
Slcr_subprocess.terminate()
Slcr_subprocess=subprocess.Popen([slic3rPath,doc.getStlFileName()])
except Exception as e:
DialogUtil.showErrorMessage(e)
def sliceInfo():
try:
doc=SlcrDoc()
doc.exportVisible()
doc.generateGcode()
preferences=FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/slcr")
slic3rIniPath=preferences.GetString('slic3rIniPath')
with open(slic3rIniPath, 'r') as f:
configString = '[dummy_section]\n' + f.read()
config=configparser.ConfigParser()
config.read_string(configString)
patterns=[
"; generated by",
"; total filament cost",
"; estimated printing time",
"; filament used"
]
message=(
"Printer: "+config["dummy_section"]["printer_settings_id"]+"\n"+
"Profile: "+config["dummy_section"]["print_settings_id"]+"\n\n"
)
for line in open(doc.getGcodeFileName()):
for pattern in patterns:
if pattern in line:
message+=line
DialogUtil.showInfoMessage(message)
except Exception as e:
DialogUtil.showErrorMessage(e)
def exportGcode():
try:
doc=SlcrDoc()
doc.exportVisible()
doc.generateGcode()
DialogUtil.showInfoMessage(
"Gcode exported to:\n\n"+
doc.getGcodeFileName()
)
except Exception as e:
DialogUtil.showErrorMessage(e)
def devReload():
if not os.path.isfile(os.path.dirname(__file__)+"/__dev__.py"):
return
print("Reloading module")
importlib.reload(sys.modules["SlcrDialogUtil"])
importlib.reload(sys.modules["SlcrDoc"])
importlib.reload(sys.modules["Slcr"])