@@ -137,14 +137,18 @@ def startCAMmer(self, args, board=None, logger=None):
137
137
popt .SetScale (1 )
138
138
popt .SetMirror (False )
139
139
popt .SetUseGerberAttributes (True )
140
- popt .SetScale (1 )
141
140
popt .SetUseAuxOrigin (True )
142
141
143
142
# This by gerbers only (also the name is truly horrid!)
144
143
popt .SetSubtractMaskFromSilk (False ) #remove solder mask from silk to be sure there is no silk on pads
144
+ popt .SetDrillMarksType (DRILL_MARKS_NO_DRILL_SHAPE )
145
+ popt .SetSkipPlotNPTH_Pads (False )
145
146
146
147
filesToZip = []
147
148
149
+
150
+ # Copper, Silk, Mask
151
+
148
152
for layer in layers .split ("," ):
149
153
if layer not in file_ext .keys ():
150
154
report += "Unknown layer " + layer + "!\n "
@@ -174,25 +178,96 @@ def startCAMmer(self, args, board=None, logger=None):
174
178
else :
175
179
filesToZip .append (newname )
176
180
177
- edge = []
181
+
182
+ # Edge cuts (dimensions) and V_SCORE (from User.Comments)
183
+ # See: https://gitlab.com/kicad/code/kicad/-/issues/13841
184
+
185
+ allEdges = LSEQ ()
178
186
edge_ext = ""
179
187
for e in edges .split ("," ):
180
188
if e in file_ext .keys ():
181
189
edge_ext = file_ext [e ]
182
190
layername = e .replace ("." , "_" )
183
- edge .append (layertable [e ])
191
+ if e in layertable .keys ():
192
+ allEdges .push_back (layertable [e ])
184
193
185
194
if edge_ext == "" :
186
- report += "Unknown edge(s) " + str (edges ) + "\n "
195
+ report += "Unknown edge(s): " + str (edges ) + "\n "
187
196
sysExit = 2
188
197
else :
189
- # TODO: add edge layer merge-and-plot here. Try SetLayerSelection and SetPlotOnAllLayersSelection
190
- pass
198
+ pctl .OpenPlotfile (layername , PLOT_FORMAT_GERBER )
199
+ pctl .PlotLayers (allEdges )
200
+ pctl .ClosePlot () # Release the file - or we can't rename it
201
+
202
+ plotfile = os .path .splitext (sourceBoardFile )[0 ] + "-" + layername + ".gbr"
203
+ newname = os .path .splitext (sourceBoardFile )[0 ] + "." + edge_ext
204
+
205
+ if not os .path .isfile (plotfile ):
206
+ report += "Could not plot " + plotfile + "\n "
207
+ sysExit = 2
208
+ else :
209
+ if os .path .isfile (newname ):
210
+ report += "Deleting existing " + newname + "\n "
211
+ os .remove (newname )
212
+ report += "Renaming " + plotfile + " to " + newname + "\n "
213
+ os .rename (plotfile , newname )
214
+ if not os .path .isfile (newname ):
215
+ report += "Could not rename " + newname + "\n "
216
+ sysExit = 2
217
+ else :
218
+ filesToZip .append (newname )
191
219
192
- # TODO: add Excellon drill file export here
220
+
221
+ # Excellon drill file
193
222
# https://gitlab.com/kicad/code/kicad/-/blob/master/demos/python_scripts_examples/gen_gerber_and_drill_files_board.py
194
223
224
+ # Fabricators need drill files.
225
+ # sometimes a drill map file is asked (for verification purpose)
226
+ drlwriter = EXCELLON_WRITER ( board )
227
+ #drlwriter.SetMapFileFormat( PLOT_FORMAT_PDF )
228
+
229
+ mirror = False
230
+ minimalHeader = False
231
+ offset = VECTOR2I (0 ,0 )
232
+ # False to generate 2 separate drill files (one for plated holes, one for non plated holes)
233
+ # True to generate only one drill file
234
+ mergeNPTH = True
235
+ drlwriter .SetOptions ( mirror , minimalHeader , offset , mergeNPTH )
236
+
237
+ metricFmt = True
238
+ drlwriter .SetFormat ( metricFmt )
239
+
240
+ genDrl = True
241
+ genMap = True
242
+ drlwriter .CreateDrillandMapFilesSet ( pctl .GetPlotDirName (), genDrl , genMap )
243
+
244
+ if mergeNPTH :
245
+ holes = os .path .splitext (sourceBoardFile )[0 ] + ".drl"
246
+ if os .path .isfile (holes ):
247
+ filesToZip .append (holes )
248
+ else :
249
+ report += "No drill file created\n "
250
+ else :
251
+ npth = os .path .splitext (sourceBoardFile )[0 ] + "-NPTH.drl"
252
+ if os .path .isfile (npth ):
253
+ filesToZip .append (npth )
254
+ else :
255
+ report += "No NPTH drill file created\n "
256
+
257
+ pth = os .path .splitext (sourceBoardFile )[0 ] + "-PTH.drl"
258
+ if os .path .isfile (pth ):
259
+ filesToZip .append (pth )
260
+ else :
261
+ report += "No PTH drill file created\n "
262
+
263
+ # One can create a text file to report drill statistics
264
+ rptfn = pctl .GetPlotDirName () + 'drill_report.rpt'
265
+ report += "Drill report: {}\n " .format ( rptfn )
266
+ drlwriter .GenDrillReportFile ( rptfn )
267
+
268
+
195
269
# Zip the files
270
+
196
271
zf = zipfile .ZipFile (zipFilename , "w" )
197
272
for filename in filesToZip :
198
273
zf .write (filename , os .path .basename (filename ), compress_type = zipfile .ZIP_DEFLATED )
@@ -202,6 +277,7 @@ def startCAMmer(self, args, board=None, logger=None):
202
277
zf .write (oi , os .path .basename (oi ), compress_type = zipfile .ZIP_DEFLATED )
203
278
zf .close ()
204
279
280
+
205
281
if sysExit < 0 :
206
282
sysExit = 0
207
283
0 commit comments