2424import os
2525import re
2626import math
27+ import zipfile as zf
2728
2829from 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
127154def FromGerberPosition (position_str ):
0 commit comments