@@ -137,14 +137,18 @@ def startCAMmer(self, args, board=None, logger=None):
137137 popt .SetScale (1 )
138138 popt .SetMirror (False )
139139 popt .SetUseGerberAttributes (True )
140- popt .SetScale (1 )
141140 popt .SetUseAuxOrigin (True )
142141
143142 # This by gerbers only (also the name is truly horrid!)
144143 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 )
145146
146147 filesToZip = []
147148
149+
150+ # Copper, Silk, Mask
151+
148152 for layer in layers .split ("," ):
149153 if layer not in file_ext .keys ():
150154 report += "Unknown layer " + layer + "!\n "
@@ -174,25 +178,96 @@ def startCAMmer(self, args, board=None, logger=None):
174178 else :
175179 filesToZip .append (newname )
176180
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 ()
178186 edge_ext = ""
179187 for e in edges .split ("," ):
180188 if e in file_ext .keys ():
181189 edge_ext = file_ext [e ]
182190 layername = e .replace ("." , "_" )
183- edge .append (layertable [e ])
191+ if e in layertable .keys ():
192+ allEdges .push_back (layertable [e ])
184193
185194 if edge_ext == "" :
186- report += "Unknown edge(s) " + str (edges ) + "\n "
195+ report += "Unknown edge(s): " + str (edges ) + "\n "
187196 sysExit = 2
188197 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 )
191219
192- # TODO: add Excellon drill file export here
220+
221+ # Excellon drill file
193222 # https://gitlab.com/kicad/code/kicad/-/blob/master/demos/python_scripts_examples/gen_gerber_and_drill_files_board.py
194223
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+
195269 # Zip the files
270+
196271 zf = zipfile .ZipFile (zipFilename , "w" )
197272 for filename in filesToZip :
198273 zf .write (filename , os .path .basename (filename ), compress_type = zipfile .ZIP_DEFLATED )
@@ -202,6 +277,7 @@ def startCAMmer(self, args, board=None, logger=None):
202277 zf .write (oi , os .path .basename (oi ), compress_type = zipfile .ZIP_DEFLATED )
203278 zf .close ()
204279
280+
205281 if sysExit < 0 :
206282 sysExit = 0
207283
0 commit comments