From c519262e29de328161b7bf0328e77a65078bc75f Mon Sep 17 00:00:00 2001 From: Josef Gajdusek Date: Wed, 20 Mar 2024 21:37:48 +0100 Subject: [PATCH] Add an option to entirely skip components with missing LCSC field This is useful since JLCPCB tries to be "smart" and assign (wrong or unneeded) components even when the LCSC field is empty in the BoM. --- kikit/fab/jlcpcb.py | 9 ++++++--- kikit/fab_ui.py | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/kikit/fab/jlcpcb.py b/kikit/fab/jlcpcb.py index 5fee1e7e..0242fdaa 100644 --- a/kikit/fab/jlcpcb.py +++ b/kikit/fab/jlcpcb.py @@ -9,7 +9,7 @@ from kikit.common import * from kikit.export import gerberImpl -def collectBom(components, lscsFields, ignore): +def collectBom(components, lscsFields, ignore, skip_missing): bom = {} for c in components: if getUnit(c) != 1: @@ -21,6 +21,8 @@ def collectBom(components, lscsFields, ignore): continue if getField(c, "JLCPCB_IGNORE") is not None and getField(c, "JLCPCB_IGNORE") != "": continue + if skip_missing and (getField(c, "LCSC") is None or getField(c, "LCSC") == ""): + continue if hasattr(c, "in_bom") and not c.in_bom: continue if hasattr(c, "on_board") and not c.on_board: @@ -56,7 +58,8 @@ def bomToCsv(bomData, filename): writer.writerow([value, ",".join(refChunk), footprint, lcsc]) def exportJlcpcb(board, outputdir, assembly, schematic, ignore, field, - corrections, correctionpatterns, missingerror, nametemplate, drc): + corrections, correctionpatterns, missingerror, nametemplate, drc, + skip_missing): """ Prepare fabrication files for JLCPCB including their assembly service """ @@ -87,7 +90,7 @@ def exportJlcpcb(board, outputdir, assembly, schematic, ignore, field, correctionFields = [x.strip() for x in corrections.split(",")] components = extractComponents(schematic) ordercodeFields = [x.strip() for x in field.split(",")] - bom = collectBom(components, ordercodeFields, refsToIgnore) + bom = collectBom(components, ordercodeFields, refsToIgnore, skip_missing) bom_refs = set(x for xs in bom.values() for x in xs) bom_components = [c for c in components if getReference(c) in bom_refs] diff --git a/kikit/fab_ui.py b/kikit/fab_ui.py index 6fd2f9d0..69b8782c 100644 --- a/kikit/fab_ui.py +++ b/kikit/fab_ui.py @@ -31,6 +31,7 @@ def fabCommand(f): help="Comma separated list of component fields with the correction value. First existing field is used") @click.option("--correctionpatterns", type=click.Path(dir_okay=False)) @click.option("--missingError/--missingWarn", help="If a non-ignored component misses LCSC field, fail") +@click.option("--skip-missing", is_flag=True, help="Skip components with missing or empty LCSC field") def jlcpcb(**kwargs): """ Prepare fabrication files for JLCPCB including their assembly service