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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
from __future__ import absolute_import
from optparse import OptionParser
import sys
import re
import os
import urllib
import urllib2
import platform
import hashlib
if not hasattr(sys, 'frozen'):
cura_sf_path = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "./cura_sf/"))
if cura_sf_path not in sys.path:
sys.path.append(cura_sf_path)
from Cura.util import profile
from Cura.slice.cura_sf.skeinforge_application.skeinforge_plugins.craft_plugins import export
def fixUTF8(input):
if input.startswith('#UTF8#'):
return input[6:].decode('utf-8')
return input
def main():
parser = OptionParser(usage="usage: %prog [options] <X,Y> <filename>[, <X,Y> <filename>][, ...]")
parser.add_option("-p", "--profile", action="store", type="string", dest="profile",
help="Encoded profile to use for the print")
parser.add_option("-o", "--output", action="store", type="string", dest="output",
help="Output filename")
(options, args) = parser.parse_args()
if options.output is None:
print 'Missing output filename'
sys.exit(1)
if options.profile is not None:
profile.loadGlobalProfileFromString(options.profile)
options.output = fixUTF8(options.output)
clearZ = 0
resultFile = open(options.output, "w")
for idx in xrange(0, len(args), 2):
position = map(float, args[idx].split(','))
if len(position) < 9 + 2:
position = position[0:2]
position += [1,0,0]
position += [0,1,0]
position += [0,0,1]
filenames = fixUTF8(args[idx + 1]).split('|')
profile.setTempOverride('object_center_x', position[0])
profile.setTempOverride('object_center_y', position[1])
if idx == 0:
resultFile.write(';TYPE:CUSTOM\n')
resultFile.write(profile.getAlterationFileContents('start.gcode').replace('?filename?', ' '.join(filenames).encode('ascii', 'replace')))
else:
resultFile.write(';TYPE:CUSTOM\n')
n = output[-1].rfind('Z')+1
zString = output[-1][n:n+20]
zString = zString[0:zString.find(' ')]
clearZ = max(clearZ, float(zString) + 10)
profile.setTempOverride('clear_z', clearZ)
print position
print profile.getAlterationFileContents('nextobject.gcode')
resultFile.write(profile.getAlterationFileContents('nextobject.gcode').replace('?filename?', ' '.join(filenames).encode('ascii', 'replace')))
output = []
for filename in filenames:
extruderNr = filenames.index(filename)
profile.resetTempOverride()
if extruderNr > 0:
profile.setTempOverride('object_center_x', position[0] - profile.getPreferenceFloat('extruder_offset_x%d' % (extruderNr)))
profile.setTempOverride('object_center_y', position[1] - profile.getPreferenceFloat('extruder_offset_y%d' % (extruderNr)))
profile.setTempOverride('fan_enabled', 'False')
profile.setTempOverride('skirt_line_count', '0')
profile.setTempOverride('alternative_center', filenames[0])
else:
profile.setTempOverride('object_center_x', position[0])
profile.setTempOverride('object_center_y', position[1])
profile.setTempOverride('object_matrix', ','.join(map(str, position[2:11])))
output.append(export.getOutput(filename))
profile.resetTempOverride()
if len(output) == 1:
resultFile.write(output[0])
else:
stitchMultiExtruder(output, resultFile)
resultFile.write(';TYPE:CUSTOM\n')
resultFile.write(profile.getAlterationFileContents('end.gcode'))
resultFile.close()
print "Running plugins"
ret = profile.runPostProcessingPlugins(options.output)
if ret is not None:
print ret
print "Finalizing %s" % (os.path.basename(options.output))
if profile.getPreference('submit_slice_information') == 'True':
filenames = fixUTF8(args[idx + 1]).split('|')
for filename in filenames:
m = hashlib.sha512()
f = open(filename, "rb")
while True:
chunk = f.read(1024)
if not chunk:
break
m.update(chunk)
f.close()
data = {
'processor': platform.processor(),
'machine': platform.machine(),
'platform': platform.platform(),
'profile': profile.getGlobalProfileString(),
'modelhash': m.hexdigest(),
}
try:
f = urllib2.urlopen("http://software.ultimaker.com/upload_stats.php", data = urllib.urlencode(data), timeout = 5);
f.read()
f.close()
except:
pass
def stitchMultiExtruder(outputList, resultFile):
print "Stitching %i files for multi-extrusion" % (len(outputList))
currentExtruder = 0
resultFile.write('T%d\n' % (currentExtruder))
layerNr = -1
hasLine = True
outputList = map(lambda o: o.split('\n'), outputList)
outputOrder = range(0, len(outputList))
while hasLine:
hasLine = False
outputOrder.reverse()
for outputIdx in outputOrder:
layerHasLine = False
while len(outputList[outputIdx]) > 0:
line = outputList[outputIdx].pop(0)
hasLine = True
if line.startswith(';LAYER:'):
break
if 'Z' in line:
lastZ = float(re.search('Z([^\s]+)', line).group(1))
if not layerHasLine:
nextExtruder = outputIdx
resultFile.write(';LAYER:%d\n' % (layerNr))
resultFile.write(';EXTRUDER:%d\n' % (nextExtruder))
if nextExtruder != currentExtruder:
resultFile.write(';TYPE:CUSTOM\n')
profile.setTempOverride('extruder', nextExtruder)
resultFile.write(profile.getAlterationFileContents('switchExtruder.gcode') + '\n')
profile.resetTempOverride()
currentExtruder = nextExtruder
layerHasLine = True
resultFile.write(line)
resultFile.write('\n')
layerNr += 1
if __name__ == '__main__':
main()
|