再贡献一个脚本 直接从图片转换和zip压缩生成可用的CWS文件
同样图片生成3层 每层曝光45秒 我这里干膜曝光一层即可停止取下 油墨曝光3层比较合适
不同打印机需要自己修改脚本中内嵌的.gcode和XXXXXXXXnf文件内容
---
少了一句以为是注释的“; Number of Slices = 3” 而且XXXXXXXXnf文件是不必要的 脚本已被修改
XXXXXXXXXXXXXXt---
0<0# : ^
'''
@python %~f0 %*
@goto :eof
'''
import zipfile
from PIL import Image
import numpy
import sys
import io
import os
if len(sys.argv)<2 :
print('Make a CWS zipped file with 3 layers using an image file')
print('Usage: python',sys.argv[0],'<image file name> <output CWS filename>')
print('Example: python',sys.argv[0],'circuit.bmp circuit.cws')
exit(1)
if len(sys.argv)>2:
cwsfile=sys.argv[2]
else:
cwsfile=os.path.splitext(sys.argv[1])[0]+'.cws'
img = numpy.array(Image.open(sys.argv[1]).convert('L'))
(h,w)=img.shape
nw=int((w+2)/3)
img2=numpy.empty([h,nw,3], dtype=img.dtype)
for y in range(h):
for x in range(nw):
img2[y,x,2]=img[y,x*3]
img2[y,x,1]=img[y,x*3+1] if x*3+1<w else 0
img2[y,x,0]=img[y,x*3+2] if x*3+2<w else 0
imgio=io.BytesIO()
Image.fromarray(img2).save(imgio, format='PNG')
b_png=imgio.getvalue()
b_gcode=b'''
;Number of Slices = 3
G28
G21 ;Set units to be mm
G91 ;Relative Positioning
M17 ;Enable motors
<Slice> Blank
M106 S0
;<Slice> 0
M106 S255
;<Delay> 45000
M106 S0
;<Slice> Blank
G1 Z4.000 F20
G1 Z-3.950 F20
;<Delay> 34000
;<Slice> 1
M106 S255
;<Delay> 45000
M106 S0
;<Slice> Blank
G1 Z4.000 F20
G1 Z-3.950 F20
;<Delay> 34000
;<Slice> 2
M106 S255
;<Delay> 45000
M106 S0
;<Slice> Blank
G1 Z4.000 F20
G1 Z-3.950 F20
;<Delay> 34000
M18 ;Disable Motors
M106 SO
G1 Z80
;<Completed>
'''
try:
import zlib
zipcompmode=zipfile.ZIP_DEFLATED
except:
zipcompmode=zipfile.ZIP_STORED
with zipfile.ZipFile(cwsfile, mode='w', compression=zipcompmode) as zf:
zf.writestr('b.gcode', b_gcode)
zf.writestr('b000.png', b_png)
zf.writestr('b001.png', b_png)
zf.writestr('b002.png', b_png)
print ('CWS File', cwsfile, 'created')
exit(0)
时段 | 个数 |
---|---|
{{f.startingTime}}点 - {{f.endTime}}点 | {{f.fileCount}} |