Update some python scripts to be compatible with python2/python3 and changes in Kicad code.
This commit is contained in:
parent
713f39ef71
commit
60719b66bb
|
@ -118,7 +118,7 @@ class add_automatic_border( ActionPlugin ):
|
||||||
edge_candidate = False
|
edge_candidate = False
|
||||||
# Detect if current drawing is a PCB edge
|
# Detect if current drawing is a PCB edge
|
||||||
# and a candicate for north/south/east or west
|
# and a candicate for north/south/east or west
|
||||||
if draw.GetClass() == 'DRAWSEGMENT' \
|
if draw.GetClass() == 'PCB_SHAPE' \
|
||||||
and draw.GetLayer() == Edge_Cuts:
|
and draw.GetLayer() == Edge_Cuts:
|
||||||
# Try candicate for east/west ?
|
# Try candicate for east/west ?
|
||||||
if draw.GetStart().x == draw.GetEnd().x:
|
if draw.GetStart().x == draw.GetEnd().x:
|
||||||
|
@ -201,7 +201,7 @@ class add_automatic_border( ActionPlugin ):
|
||||||
need_add = False
|
need_add = False
|
||||||
if west is None:
|
if west is None:
|
||||||
need_add = True
|
need_add = True
|
||||||
west = DRAWSEGMENT()
|
west = PCB_SHAPE()
|
||||||
west.SetLayer( Edge_Cuts )
|
west.SetLayer( Edge_Cuts )
|
||||||
|
|
||||||
west.SetStart( wxPoint( min_x, min_y ) )
|
west.SetStart( wxPoint( min_x, min_y ) )
|
||||||
|
@ -212,7 +212,7 @@ class add_automatic_border( ActionPlugin ):
|
||||||
need_add = False
|
need_add = False
|
||||||
if north is None:
|
if north is None:
|
||||||
need_add = True
|
need_add = True
|
||||||
north = DRAWSEGMENT()
|
north = PCB_SHAPE()
|
||||||
north.SetLayer( Edge_Cuts )
|
north.SetLayer( Edge_Cuts )
|
||||||
|
|
||||||
north.SetStart( wxPoint( min_x, min_y ) )
|
north.SetStart( wxPoint( min_x, min_y ) )
|
||||||
|
@ -223,7 +223,7 @@ class add_automatic_border( ActionPlugin ):
|
||||||
need_add = False
|
need_add = False
|
||||||
if east is None:
|
if east is None:
|
||||||
need_add = True
|
need_add = True
|
||||||
east = DRAWSEGMENT()
|
east = PCB_SHAPE()
|
||||||
east.SetLayer( Edge_Cuts )
|
east.SetLayer( Edge_Cuts )
|
||||||
|
|
||||||
east.SetStart( wxPoint( max_x, min_y ) )
|
east.SetStart( wxPoint( max_x, min_y ) )
|
||||||
|
@ -234,7 +234,7 @@ class add_automatic_border( ActionPlugin ):
|
||||||
need_add = False
|
need_add = False
|
||||||
if south is None:
|
if south is None:
|
||||||
need_add = True
|
need_add = True
|
||||||
south = DRAWSEGMENT()
|
south = PCB_SHAPE()
|
||||||
south.SetLayer( Edge_Cuts )
|
south.SetLayer( Edge_Cuts )
|
||||||
|
|
||||||
south.SetStart( wxPoint( min_x, max_y ) )
|
south.SetStart( wxPoint( min_x, max_y ) )
|
||||||
|
|
|
@ -22,8 +22,15 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from pcbnew import *
|
from pcbnew import *
|
||||||
|
|
||||||
|
# A helper function to convert a string filename for python2 or python3
|
||||||
|
def getFName( afilename ):
|
||||||
|
if sys.version_info < (3, 0):
|
||||||
|
return afilename.encode()
|
||||||
|
else:
|
||||||
|
return afilename
|
||||||
|
|
||||||
filename=sys.argv[1]
|
filename=sys.argv[1]
|
||||||
|
|
||||||
board = LoadBoard(filename)
|
board = LoadBoard(filename)
|
||||||
|
@ -51,7 +58,6 @@ popt.SetIncludeGerberNetlistInfo(True)
|
||||||
popt.SetCreateGerberJobFile(gen_job_file)
|
popt.SetCreateGerberJobFile(gen_job_file)
|
||||||
popt.SetUseGerberProtelExtensions(False)
|
popt.SetUseGerberProtelExtensions(False)
|
||||||
popt.SetExcludeEdgeLayer(False);
|
popt.SetExcludeEdgeLayer(False);
|
||||||
popt.SetScale(1)
|
|
||||||
popt.SetUseAuxOrigin(True)
|
popt.SetUseAuxOrigin(True)
|
||||||
|
|
||||||
# This by gerbers only
|
# This by gerbers only
|
||||||
|
@ -73,6 +79,7 @@ jobfile_writer = GERBER_JOBFILE_WRITER( board )
|
||||||
# param 2 is a comment
|
# param 2 is a comment
|
||||||
plot_plan = [
|
plot_plan = [
|
||||||
( "CuTop", F_Cu, "Top layer" ),
|
( "CuTop", F_Cu, "Top layer" ),
|
||||||
|
( "In1Top", In1_Cu, "In1 layer" ),
|
||||||
( "CuBottom", B_Cu, "Bottom layer" ),
|
( "CuBottom", B_Cu, "Bottom layer" ),
|
||||||
( "PasteBottom", B_Paste, "Paste Bottom" ),
|
( "PasteBottom", B_Paste, "Paste Bottom" ),
|
||||||
( "PasteTop", F_Paste, "Paste top" ),
|
( "PasteTop", F_Paste, "Paste top" ),
|
||||||
|
@ -92,11 +99,13 @@ for layer_info in plot_plan:
|
||||||
|
|
||||||
pctl.SetLayer(layer_info[1])
|
pctl.SetLayer(layer_info[1])
|
||||||
pctl.OpenPlotfile(layer_info[0], PLOT_FORMAT_GERBER, layer_info[2])
|
pctl.OpenPlotfile(layer_info[0], PLOT_FORMAT_GERBER, layer_info[2])
|
||||||
print('plot %s' % pctl.GetPlotFileName())
|
|
||||||
|
print( 'plot %s' % getFName( pctl.GetPlotFileName() ) )
|
||||||
|
|
||||||
if gen_job_file == True:
|
if gen_job_file == True:
|
||||||
jobfile_writer.AddGbrFile( layer_info[1], os.path.basename(pctl.GetPlotFileName()) );
|
jobfile_writer.AddGbrFile( layer_info[1], os.path.basename(pctl.GetPlotFileName()) );
|
||||||
if pctl.PlotLayer() == False:
|
if pctl.PlotLayer() == False:
|
||||||
print("plot error")
|
print( "plot error" )
|
||||||
|
|
||||||
#generate internal copper layers, if any
|
#generate internal copper layers, if any
|
||||||
lyrcnt = board.GetCopperLayerCount();
|
lyrcnt = board.GetCopperLayerCount();
|
||||||
|
@ -106,9 +115,11 @@ for innerlyr in range ( 1, lyrcnt-1 ):
|
||||||
pctl.SetLayer(innerlyr)
|
pctl.SetLayer(innerlyr)
|
||||||
lyrname = 'inner%s' % innerlyr
|
lyrname = 'inner%s' % innerlyr
|
||||||
pctl.OpenPlotfile(lyrname, PLOT_FORMAT_GERBER, "inner")
|
pctl.OpenPlotfile(lyrname, PLOT_FORMAT_GERBER, "inner")
|
||||||
print('plot %s' % pctl.GetPlotFileName())
|
|
||||||
|
print( "plot %s" % getFName( pctl.GetPlotFileName() ) )
|
||||||
|
|
||||||
if pctl.PlotLayer() == False:
|
if pctl.PlotLayer() == False:
|
||||||
print("plot error")
|
print( "plot error" )
|
||||||
|
|
||||||
|
|
||||||
# At the end you have to close the last plot, otherwise you don't know when
|
# At the end you have to close the last plot, otherwise you don't know when
|
||||||
|
@ -133,18 +144,20 @@ drlwriter.SetFormat( metricFmt )
|
||||||
|
|
||||||
genDrl = True
|
genDrl = True
|
||||||
genMap = True
|
genMap = True
|
||||||
print('create drill and map files in %s' % pctl.GetPlotDirName())
|
print( 'create drill and map files in %s' % getFName( pctl.GetPlotFileName() ) )
|
||||||
drlwriter.CreateDrillandMapFilesSet( pctl.GetPlotDirName(), genDrl, genMap );
|
drlwriter.CreateDrillandMapFilesSet( pctl.GetPlotDirName(), genDrl, genMap );
|
||||||
|
|
||||||
# One can create a text file to report drill statistics
|
# One can create a text file to report drill statistics
|
||||||
rptfn = pctl.GetPlotDirName() + 'drill_report.rpt'
|
rptfn = pctl.GetPlotDirName() + 'drill_report.rpt'
|
||||||
print('report: %s' % rptfn)
|
print( 'report: %s' % getFName( rptfn ) )
|
||||||
drlwriter.GenDrillReportFile( rptfn );
|
drlwriter.GenDrillReportFile( rptfn );
|
||||||
|
|
||||||
if gen_job_file == True:
|
if gen_job_file == True:
|
||||||
#job_fn=os.path.splitext(pctl.GetPlotFileName())[0] + '.gbrjob'
|
#job_fn=os.path.splitext(pctl.GetPlotFileName())[0] + '.gbrjob'
|
||||||
job_fn=os.path.dirname(pctl.GetPlotFileName()) + '/' + os.path.basename(filename)
|
job_fn=os.path.dirname(pctl.GetPlotFileName()) + '/' + os.path.basename(filename)
|
||||||
job_fn=os.path.splitext(job_fn)[0] + '.gbrjob'
|
job_fn=os.path.splitext(job_fn)[0] + '.gbrjob'
|
||||||
print('create job file %s' % job_fn)
|
|
||||||
|
print( 'create job file %s ' % getFName( job_fn ) )
|
||||||
|
|
||||||
jobfile_writer.CreateJobFile( job_fn )
|
jobfile_writer.CreateJobFile( job_fn )
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,10 @@ popt = pctl.GetPlotOptions()
|
||||||
popt.SetOutputDirectory("plot/")
|
popt.SetOutputDirectory("plot/")
|
||||||
|
|
||||||
# Set some important plot options:
|
# Set some important plot options:
|
||||||
|
# One cannot plot the frame references, because the board does not know
|
||||||
|
# the frame references.
|
||||||
popt.SetPlotFrameRef(False)
|
popt.SetPlotFrameRef(False)
|
||||||
popt.SetLineWidth(FromMM(0.35))
|
popt.SetSketchPadLineWidth(FromMM(0.1))
|
||||||
|
|
||||||
popt.SetAutoScale(False)
|
popt.SetAutoScale(False)
|
||||||
popt.SetScale(1)
|
popt.SetScale(1)
|
||||||
|
@ -72,7 +74,7 @@ plot_plan = [
|
||||||
for layer_info in plot_plan:
|
for layer_info in plot_plan:
|
||||||
pctl.SetLayer(layer_info[1])
|
pctl.SetLayer(layer_info[1])
|
||||||
pctl.OpenPlotfile(layer_info[0], PLOT_FORMAT_GERBER, layer_info[2])
|
pctl.OpenPlotfile(layer_info[0], PLOT_FORMAT_GERBER, layer_info[2])
|
||||||
print(layer_info[0])
|
print ( layer_info[0] )
|
||||||
pctl.PlotLayer()
|
pctl.PlotLayer()
|
||||||
|
|
||||||
# Our fabricators want two additional gerbers:
|
# Our fabricators want two additional gerbers:
|
||||||
|
@ -106,9 +108,6 @@ popt.SetPlotReference(True)
|
||||||
popt.SetPlotValue(True)
|
popt.SetPlotValue(True)
|
||||||
popt.SetPlotInvisibleText(False)
|
popt.SetPlotInvisibleText(False)
|
||||||
|
|
||||||
# Comments in, uhmm... green
|
|
||||||
#Note: currently, color is overidden by plot functions, so SetColor is not useful.
|
|
||||||
popt.SetColor( COLOR4D( 1.0, 0, 0, 1.0 ) ) # color = RED, GREEN, BLUE, OPACITY )
|
|
||||||
pctl.SetLayer(Cmts_User)
|
pctl.SetLayer(Cmts_User)
|
||||||
pctl.PlotLayer()
|
pctl.PlotLayer()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue