Skip to content

Commit 79923a0

Browse files
committed
Generate zip file after output gerber files
1 parent 05bdf40 commit 79923a0

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

gerber_drill.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,20 @@
2424
import os
2525
import re
2626
import math
27+
import zipfile as zf
2728

2829
from pcbnew import *
29-
def GenGerberDrill(board = None, split_G85 = 0.2, plotDir = "plot/", plotReference = True):
30+
def def_logger(*args):
31+
r = ""
32+
for t in args:
33+
r = r + str(t) + " "
34+
print r
35+
def GenGerberDrill(board = None, split_G85 = 0.2, plotDir = "plot/", plotReference = True, logger = def_logger):
3036
if not board:
3137
board = GetBoard()
3238

39+
plotFiles = []
40+
3341
pctl = PLOT_CONTROLLER(board)
3442

3543
popt = pctl.GetPlotOptions()
@@ -74,9 +82,9 @@ def GenGerberDrill(board = None, split_G85 = 0.2, plotDir = "plot/", plotReferen
7482
for layer_info in plot_plan:
7583
pctl.SetLayer(layer_info[1])
7684
pctl.OpenPlotfile(layer_info[0], PLOT_FORMAT_GERBER, layer_info[2])
77-
print 'plot %s' % pctl.GetPlotFileName()
85+
logger('plot %s' % pctl.GetPlotFileName())
7886
if pctl.PlotLayer() == False:
79-
print "plot error"
87+
logger("plot error")
8088

8189
#generate internal copper layers, if any
8290
lyrcnt = board.GetCopperLayerCount();
@@ -85,9 +93,9 @@ def GenGerberDrill(board = None, split_G85 = 0.2, plotDir = "plot/", plotReferen
8593
pctl.SetLayer(innerlyr)
8694
lyrname = 'inner%s' % innerlyr
8795
pctl.OpenPlotfile(lyrname, PLOT_FORMAT_GERBER, "inner")
88-
print 'plot %s' % pctl.GetPlotFileName()
96+
logger('plot %s' % pctl.GetPlotFileName())
8997
if pctl.PlotLayer() == False:
90-
print "plot error"
98+
logger("plot error")
9199

92100

93101
# At the end you have to close the last plot, otherwise you don't know when
@@ -112,8 +120,8 @@ def GenGerberDrill(board = None, split_G85 = 0.2, plotDir = "plot/", plotReferen
112120

113121
genDrl = True
114122
genMap = False
115-
print 'create drill and map files in %s' % pctl.GetPlotDirName()
116-
drlwriter.CreateDrillandMapFilesSet( pctl.GetPlotDirName(), genDrl, genMap );
123+
logger('create drill and map files in %s' % pctl.GetPlotDirName())
124+
drlwriter.CreateDrillandMapFilesSet( pctl.GetPlotDirName(), genDrl, genMap )
117125

118126
# One can create a text file to report drill statistics
119127
#rptfn = pctl.GetPlotDirName() + 'drill_report.rpt'
@@ -122,6 +130,25 @@ def GenGerberDrill(board = None, split_G85 = 0.2, plotDir = "plot/", plotReferen
122130

123131
if split_G85:
124132
SplitG85InDrill(pctl.GetPlotDirName(), False, split_G85)
133+
134+
files = [f for f in os.listdir(pctl.GetPlotDirName()) if f.endswith('.gbr')]
135+
for f in files:
136+
plotFiles.append( pctl.GetPlotDirName() + f )
137+
138+
files = [f for f in os.listdir(pctl.GetPlotDirName()) if f.endswith('.drl')]
139+
for f in files:
140+
plotFiles.append( pctl.GetPlotDirName() + f )
141+
142+
brdName = board.GetFileName()
143+
brdName = brdName[brdName.rfind(os.path.sep)+1: brdName.rfind('.')]
144+
zipName = pctl.GetPlotDirName() + brdName + "_gerber.zip"
145+
logger("Zip them into " + zipName)
146+
147+
azip = zf.ZipFile(zipName, 'w')
148+
for f in plotFiles:
149+
azip.write(filename=f, arcname = os.path.split(f)[1] , compress_type=zf.ZIP_DEFLATED)
150+
azip.close()
151+
125152
return pctl.GetPlotDirName()
126153

127154
def FromGerberPosition(position_str):

mf_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ def Onclick(self, e):
703703
GenMFDoc(needGenBOM = self.chkBOM.GetValue(), needGenPos = self.chkPos.GetValue(), logger = lambda *args: self.log(*args) )
704704
if self.chkGerber.GetValue():
705705
self.area_text.AppendText("Start generate gerber files\n")
706-
gerberPath = gd.GenGerberDrill(board = None, split_G85 = 0.2, plotDir = "gerber/", plotReference = self.chkPlotRef.GetValue())
706+
gerberPath = gd.GenGerberDrill(board = None, split_G85 = 0.2, plotDir = "gerber/", plotReference = self.chkPlotRef.GetValue(), logger = lambda *args: self.log(*args))
707707
self.area_text.AppendText( 'Gerber file dir is "%s"' % gerberPath)
708708
except Exception as e:
709709
self.area_text.AppendText("Error:\n")

0 commit comments

Comments
 (0)