successfully zipping automatically

This commit is contained in:
Brendan Haines 2021-06-29 02:33:05 -06:00
parent afd893fe48
commit e87997a287

View File

@ -2,6 +2,7 @@ import pcbnew
import os import os
from datetime import datetime from datetime import datetime
from pathlib import Path from pathlib import Path
import zipfile
__all__ = ["FabOutputs"] __all__ = ["FabOutputs"]
@ -33,7 +34,8 @@ class FabOutputs(pcbnew.ActionPlugin):
rev = str.upper(pcb.GetTitleBlock().GetRevision()) rev = str.upper(pcb.GetTitleBlock().GetRevision())
suffix = "" suffix = ""
suffix += f"_REV{rev}" if rev != "":
suffix += f"_REV{rev}"
suffix += f"_{now.strftime('%Y%m%d_%H%M%S')}" suffix += f"_{now.strftime('%Y%m%d_%H%M%S')}"
layer_count = pcb.GetDesignSettings().GetCopperLayerCount() layer_count = pcb.GetDesignSettings().GetCopperLayerCount()
@ -82,100 +84,104 @@ class FabOutputs(pcbnew.ActionPlugin):
"soldermask defined": None, # TODO: how do I want to determine this? "soldermask defined": None, # TODO: how do I want to determine this?
} }
with zipfile.ZipFile(dir_fab / f"{project_name}{suffix}.zip", "w") as z:
# ================ # ================
# Gerbers # Gerbers
# ================ # ================
plot_controller = pcbnew.PLOT_CONTROLLER(pcb) plot_controller = pcbnew.PLOT_CONTROLLER(pcb)
plot_options = plot_controller.GetPlotOptions() plot_options = plot_controller.GetPlotOptions()
# Set General Options: # Set General Options:
plot_options.SetOutputDirectory(dir_fab) plot_options.SetOutputDirectory(dir_fab)
plot_options.SetPlotFrameRef(False) plot_options.SetPlotFrameRef(False)
plot_options.SetPlotValue(False) plot_options.SetPlotValue(False)
plot_options.SetPlotReference(True) plot_options.SetPlotReference(True)
plot_options.SetPlotInvisibleText(False) plot_options.SetPlotInvisibleText(False)
plot_options.SetPlotViaOnMaskLayer(False) plot_options.SetPlotViaOnMaskLayer(False)
plot_options.SetExcludeEdgeLayer(True) plot_options.SetExcludeEdgeLayer(True)
plot_options.SetUseAuxOrigin(False) plot_options.SetUseAuxOrigin(False)
plot_options.SetMirror(False) plot_options.SetMirror(False)
plot_options.SetNegative(False) plot_options.SetNegative(False)
#plot_options.SetDrillMarksType(PLOT_DRILL_MARKS_TYPE) #plot_options.SetDrillMarksType(PLOT_DRILL_MARKS_TYPE)
#plot_options.SetScale(PLOT_SCALE) #plot_options.SetScale(PLOT_SCALE)
plot_options.SetAutoScale(True) plot_options.SetAutoScale(True)
#plot_options.SetPlotMode(PLOT_MODE) #plot_options.SetPlotMode(PLOT_MODE)
#plot_options.SetLineWidth(pcbnew.FromMM(PLOT_LINE_WIDTH)) #plot_options.SetLineWidth(pcbnew.FromMM(PLOT_LINE_WIDTH))
plot_options.SetUseGerberAttributes(True) plot_options.SetUseGerberAttributes(True)
plot_options.SetUseGerberProtelExtensions(False) plot_options.SetUseGerberProtelExtensions(False)
plot_options.SetCreateGerberJobFile(False) plot_options.SetCreateGerberJobFile(False)
plot_options.SetSubtractMaskFromSilk(True) plot_options.SetSubtractMaskFromSilk(True)
plot_options.SetIncludeGerberNetlistInfo(False) plot_options.SetIncludeGerberNetlistInfo(False)
plot_plan = [ plot_plan = [
# ( layer ID, file extension, description) # ( layer ID, file extension, description)
( pcbnew.F_Paste, 'gtp', 'Front Paste' ), ( pcbnew.F_Paste, 'gtp', 'Front Paste' ),
( pcbnew.F_SilkS, 'gto', 'Front SilkScreen' ), ( pcbnew.F_SilkS, 'gto', 'Front SilkScreen' ),
( pcbnew.F_Mask, 'gts', 'Front Mask' ), ( pcbnew.F_Mask, 'gts', 'Front Mask' ),
( pcbnew.F_Cu, 'gtl', 'Front Copper' ), ( pcbnew.F_Cu, 'gtl', 'Front Copper' ),
*[(layer, f'g{layer}', f'Inner Layer {layer} Copper') for layer in range(1, layer_count-1)], *[(layer, f'g{layer}', f'Inner Layer {layer} Copper') for layer in range(1, layer_count-1)],
( pcbnew.B_Cu, 'gbl', 'Back Copper' ), ( pcbnew.B_Cu, 'gbl', 'Back Copper' ),
( pcbnew.B_Mask, 'gbs', 'Back Mask' ), ( pcbnew.B_Mask, 'gbs', 'Back Mask' ),
( pcbnew.B_SilkS, 'gbo', 'Back SilkScreen' ), ( pcbnew.B_SilkS, 'gbo', 'Back SilkScreen' ),
( pcbnew.B_Paste, 'gbp', 'Back Paste' ), ( pcbnew.B_Paste, 'gbp', 'Back Paste' ),
( pcbnew.Edge_Cuts, 'gm1', 'Edges Cuts' ), ( pcbnew.Edge_Cuts, 'gm1', 'Edges Cuts' ),
] ]
for layer_info in plot_plan: for layer_info in plot_plan:
plot_controller.SetLayer(layer_info[0]) plot_controller.SetLayer(layer_info[0])
plot_controller.OpenPlotfile('', pcbnew.PLOT_FORMAT_GERBER, layer_info[2]) plot_controller.OpenPlotfile('', pcbnew.PLOT_FORMAT_GERBER, layer_info[2])
plot_controller.PlotLayer() plot_controller.PlotLayer()
os.rename(dir_fab / f"{project_name}.gbr", dir_fab / f"{project_name}{suffix}.{layer_info[1]}") os.rename(dir_fab / f"{project_name}.gbr", dir_fab / f"{project_name}{suffix}.{layer_info[1]}")
z.write(dir_fab / f"{project_name}{suffix}.{layer_info[1]}", arcname=f"{project_name}{suffix}.{layer_info[1]}")
plot_controller.ClosePlot() plot_controller.ClosePlot()
# ================ # ================
# Drill Files # Drill Files
# ================ # ================
METRIC = True METRIC = True
ZERO_FORMAT = pcbnew.GENDRILL_WRITER_BASE.DECIMAL_FORMAT ZERO_FORMAT = pcbnew.GENDRILL_WRITER_BASE.DECIMAL_FORMAT
INTEGER_DIGITS = 3 INTEGER_DIGITS = 3
MANTISSA_DIGITS = 3 MANTISSA_DIGITS = 3
MIRROR_Y_AXIS = False MIRROR_Y_AXIS = False
HEADER = True HEADER = True
OFFSET = pcbnew.wxPoint(0,0) OFFSET = pcbnew.wxPoint(0,0)
MERGE_PTH_NPTH = True MERGE_PTH_NPTH = True
DRILL_FILE = True DRILL_FILE = True
MAP_FILE = False MAP_FILE = False
REPORTER = None REPORTER = None
drill_writer = pcbnew.EXCELLON_WRITER(pcb) drill_writer = pcbnew.EXCELLON_WRITER(pcb)
drill_writer.SetFormat(METRIC, ZERO_FORMAT, INTEGER_DIGITS, MANTISSA_DIGITS) drill_writer.SetFormat(METRIC, ZERO_FORMAT, INTEGER_DIGITS, MANTISSA_DIGITS)
drill_writer.SetOptions(MIRROR_Y_AXIS, HEADER, OFFSET, MERGE_PTH_NPTH) drill_writer.SetOptions(MIRROR_Y_AXIS, HEADER, OFFSET, MERGE_PTH_NPTH)
drill_writer.CreateDrillandMapFilesSet(str(dir_fab), DRILL_FILE, MAP_FILE, REPORTER) drill_writer.CreateDrillandMapFilesSet(str(dir_fab), DRILL_FILE, MAP_FILE, REPORTER)
os.rename(dir_fab / f"{project_name}.drl", dir_fab / f"{project_name}{suffix}.drl") os.rename(dir_fab / f"{project_name}.drl", dir_fab / f"{project_name}{suffix}.drl")
z.write(dir_fab / f"{project_name}{suffix}.drl", arcname=f"{project_name}{suffix}.drl")
# ================
# Fab Drawing
# ================
with open(dir_fab / f"README_FABRICATION{suffix}.TXT", "w") as f:
f.write(f"{project_name}-REV{rev}\n")
f.write(f"Layer Order\n")
# for layer in plot_plan:
z.write(dir_fab / f"README_FABRICATION{suffix}.TXT", arcname=f"README_FABRICATION{suffix}.TXT")
# ================ # ================
# Pick and Place # Pick and Place
# ================ # ================s
# TODO # TODO
# ================
# Fab Drawing
# ================
with open(dir_fab / f"README_FABRICATION{suffix}.TXT", "w") as f:
f.write(f"{project_name}-REV{rev}\n")
f.write(f"Layer Order\n")
# for layer in plot_plan:
# ================ # ================
# Assembly Drawing # Assembly Drawing
# ================ # ================