- https://github.com/INTI-CMNB/KiAuto
- KiKit
- InteractiveHtmlBom
Last active
November 25, 2023 22:11
-
-
Save snhobbs/39f217ce1071c9b8aa11ac42347c932b to your computer and use it in GitHub Desktop.
Makefile for exporting a KICAD 7 Design for Manufacturing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import pcbnew | |
def get_version(pcb): | |
board = pcbnew.LoadBoard(pcb) | |
title = board.GetTitleBlock() | |
version = title.GetRevision() | |
return version | |
if __name__ == "__main__": | |
version = get_version(sys.argv[1]) | |
print(version) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#auto_saved_files# | |
fp-info-cache | |
*-backups | |
fab | |
fp-lib-table | |
*.log | |
*.out | |
build | |
*.egg-info | |
__pycache__ | |
CMakeFiles | |
schematic-positions-to-layout.debug | |
_autosave* | |
*.lck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requires: | |
# + KiAuto : https://github.com/INTI-CMNB/KiAuto | |
# + KiCAD 7.0.0+ | |
# + InteractiveHtmlBOM : https://github.com/openscopeproject/InteractiveHtmlBom | |
# + KiKit: V 1.0.3+ | |
# | |
# | |
# | |
# Tools & Tool Paths | |
KICAD=kicad-cli | |
IBOM_SCRIPT=${HOME}/tools/InteractiveHtmlBom/InteractiveHtmlBom/generate_interactive_bom.py | |
PYTHON="/usr/bin/python3" | |
KICAD_PYTHON_PATH=/usr/lib/kicad/lib/python3/dist-packages | |
BOM_SCRIPT="/usr/share/kicad/plugins/bom_csv_grouped_by_value.py" | |
PCBNEW_DO=pcbnew_do | |
KIKIT=kikit | |
TMP=/tmp | |
MANUFACTURING_DIR=fab | |
DRC_RESULT=drc_result.rpt | |
# Project Information | |
PROJECT=PROJECTNAME | |
SCH=${PROJECT}.kicad_sch | |
PCB=${PROJECT}.kicad_pcb | |
PCBBASE=$(basename ${PCB}) | |
SCHBASE=$(basename ${SCH}) | |
VERSION=A.B.X | |
PDFSCH=${SCHBASE}_${VERSION}.pdf | |
LOG=log.log | |
MECH_DIR=mechanical | |
XMLBOM=${TMP}/${SCHBASE}_${VERSION}_BOM.xml | |
BOM=${MANUFACTURING_DIR}/assembly/${SCHBASE}_${VERSION}_BOM.csv | |
LCSCBOM=${MANUFACTURING_DIR}/assembly/${SCHBASE}_${VERSION}_LCSC_BOM.csv | |
DRILL=${MANUFACTURING_DIR}/gerbers/drill.drl | |
STEP=${MECH_DIR}/${PCBBASE}_${VERSION}.step | |
CENTROID_CSV=${MANUFACTURING_DIR}/assembly/centroid.csv | |
CENTROID_GERBER=${MANUFACTURING_DIR}/assembly/centroid.gerber | |
JLC_CENTROID=${MANUFACTURING_DIR}/assembly/jlc-centroid.csv | |
IBOM=${PCBBASE}_${VERSION}_interactive_bom.html | |
FABZIP=${PCBBASE}_${VERSION}.zip | |
GENCAD=${PCBBASE}_${VERSION}.cad | |
OUTLINE=${MECH_DIR}/board-outline.svg | |
export PYTHONPATH=${KICAD_PYTHON_PATH} | |
.PHONY: all | |
all: schematic BOM manufacturing | |
.PHONY: no-drc | |
no-drc: schematic BOM ibom step gerbers board fabzip | |
.PHONY: manufacturing | |
manufacturing: ibom step drc gerbers board fabzip | |
clean: | |
-rm ${PDFSCH} ${XMLBOM} ${BOM} ${STEP} ${CENTROID_GERBER} ${CENTROID_CSV} ${JLC_CENTROID} ${IBOM} ${MANUFACTURING_DIR}/gerbers/* | |
-rm ${FABZIP} kicad-cli ${OUTLINE} | |
-rmdir ${MANUFACTURING_DIR}/gerbers ${MANUFACTURING_DIR}/assembly ${MANUFACTURING_DIR} | |
-rmdir 3D mechanical | |
drc: ${PCB} | |
${KIKIT} drc run $< | |
#${PCBNEW_DO} run_drc $< ./ >> log.log | |
erc: ${SCH} | |
${PCBNEW_DO} run_erc $< ./ >> log.log | |
# Generates schematic | |
${PDFSCH} : ${SCH} | |
${KICAD} sch export pdf --black-and-white $< -o $@ | |
# Generate python-BOM | |
${XMLBOM}: ${SCH} | |
mkdir -p ${TMP} | |
${KICAD} sch export python-bom $< -o $@ | |
${BOM}: ${XMLBOM} | |
mkdir -p ${MANUFACTURING_DIR}/assembly | |
${PYTHON} ${BOM_SCRIPT} $< $@ > $@ | |
# Complains about output needing to be a directory, work around this | |
${DRILL}: ${PCB} | |
mkdir -p ${MANUFACTURING_DIR}/gerbers | |
${KICAD} pcb export drill --excellon-units mm $< -o ./ | |
mv ${PCBBASE}.drl $@ | |
${CENTROID_CSV}: ${PCB} | |
mkdir -p ${MANUFACTURING_DIR}/assembly | |
${KICAD} pcb export pos --use-drill-file-origin --side both --format csv --units mm $< -o $@ | |
${JLC_CENTROID}: ${CENTROID_CSV} | |
#echo "Ref,Val,Package,PosX,PosY,Rot,Side" >> | |
echo "Designator,Comment,Footprint,Mid X,Mid Y,Rotation,Layer" > $@ | |
tail --lines=+2 $< >> $@ | |
${STEP}: ${PCB} | |
mkdir -p ${MECH_DIR} | |
${KICAD} pcb export step $< --drill-origin --subst-models -f -o $@ | |
gerbers: ${PCB} #drc | |
mkdir -p ${MANUFACTURING_DIR}/gerbers | |
${KICAD} pcb export gerbers --subtract-soldermask $< -o ${MANUFACTURING_DIR}/gerbers | |
${IBOM}: ${PCB} | |
${IBOM_SCRIPT} $< --dnp-field DNP --group-fields "Value,Footprint" --blacklist "X1,MH*" --include-nets --normalize-field-case --no-browser --dest-dir ./ --name-format %f_%r_interactive_bom | |
${FABZIP}: board | |
zip -rj $@ ${MANUFACTURING_DIR}/gerbers | |
# Board Outline | |
${OUTLINE}: ${PCB} | |
${KICAD} pcb export svg -l "Edge.Cuts" --black-and-white --exclude-drawing-sheet $< -o $@ | |
gencad: gerbers | |
${KICAD} pcb export gencad -l "Edge.Cuts" --black-and-white --exclude-drawing-sheet $< -o $@ | |
# Add board renders | |
# Add expanding BOMs | |
#.PHONY: jlcpcbbom | |
#jlcpcbbom: ${LCSCBOM} | |
# Add placement from spreadsheet | |
.PHONY: place | |
place: ${} | |
.PHONY: zip | |
zip: ${FABZIP} | |
.PHONY: step | |
step: ${STEP} | |
.PHONY: ibom | |
ibom: ${IBOM} | |
.PHONY: schematic | |
schematic : ${PDFSCH} | |
.PHONY: BOM | |
BOM: ${BOM} | |
.PHONY: fabzip | |
fabzip: ${FABZIP} | |
.PHONY: board | |
board: gerbers ${DRILL} ${CENTROID_CSV} ${JLC_CENTROID} ${ASSEMBLY_BOM} ${OUTLINE} | |
.PHONY: setup | |
setup: ${ASSEMBLY_BOM} ${BOM} schematic ibom step |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment