Repository: wokwi/kicad-jlcpcb-bom-plugin Branch: master Commit: 1afb7abf6763 Files: 3 Total size: 5.1 KB Directory structure: gitextract_kh3hp7cg/ ├── README.md ├── bom_csv_jlcpcb.py └── kicad_pos_to_cpl.py ================================================ FILE CONTENTS ================================================ ================================================ FILE: README.md ================================================ # KiCad JLCPCB BOM Plugin Export a JLCPCB Compatible BOM directly from your KiCad schematic! ## Installation This script requires **Python 3**. If you need a Python 2 version, please get [kicad-jlcpcb-bom-plugin version 1.0.0](https://github.com/wokwi/kicad-jlcpcb-bom-plugin/releases/tag/1.0.0) instead. The script has been tested with KiCad 5.1.4. 1. Copy `bom_csv_jlcpcb.py` to your KiCad installation folder under the `bin/scripting/plugins` directory 2. In Eschema (the Schematics editor) go to "Tools" -> "Generate Bill of Materials", press the "+" button at the bottom of the screen, and choose the plugin file you have just copied. When asked for a nickname, go with the default, "bom_csv_jlcpcb". ## Usage Instructions for exporting JLCPCB BOM from KiCad's Eschema: 1. Go to "Tools" -> "Generate Bill of Materials" 2. Choose "bom_csv_jlcpcb" from the "BOM plugins" list on the left 3. Make sure the command line starts with "python**3**" instead of "python" (unless your default python version is 3) 4. Make sure the command line ends with "%O.csv" (otherwise, change "%O" into "%O.csv") 5. Click on "Generate". The BOM file should be created inside your project's directory, as a CSV file. ## Custom Fields You can customize the script's output by adding the following fields to your components: 1. "LCSC Part" - Add this field to include an LCSC Part number in the generated BOM. e.g.: C2286 for a red LED. 2. "JLCPCB BOM" - Set this field to 0 (or "False") to omit the component from the generated BOM. ## Generating a JLCPCB CPL File You can use the `kicad_pos_to_cpl.py` script to convert a KiCad Footprint Position (.pos) file into a CPL file compatible with JLCPCB SMT Assembly service. The `.pos` file can be generated from Pcbnew, by going into "File" -> "Fabrication Outputs" -> "Footprint Position (.pos) File..." and choosing the following options: * Format: CSV * Units: Millimeters * Files: Separate files for front and back Also, make sure to uncheck "Include footprints with SMD pads even if not marked Surface Mount". ================================================ FILE: bom_csv_jlcpcb.py ================================================ # # Example python script to generate a BOM from a KiCad generic netlist # # Example: Sorted and Grouped CSV BOM # """ @package Generate a CSV BOM for use with JLCSMT service. Components are sorted by ref and grouped by value with same footprint Fields are (if exist). LCSC Part numbers are copied from the "LCSC Part" field, if exists. It is possible to hide components from the BOM by setting the "JLCPCB BOM" field to "0" or "false". Output fields: 'Comment', 'Designator', 'Footprint', 'LCSC Part #' Command line: python "pathToFile/bom_csv_jlcsmt.py" "%I" "%O.csv" """ import kicad_netlist_reader import csv import sys net = kicad_netlist_reader.netlist(sys.argv[1]) with open(sys.argv[2], 'w', newline='') as f: out = csv.writer(f) out.writerow(['Comment', 'Designator', 'Footprint', 'LCSC Part #']) for group in net.groupComponents(): refs = [] lcsc_pn = "" for component in group: if component.getField('JLCPCB BOM') in ['0', 'false', 'False', 'FALSE']: continue refs.append(component.getRef()) lcsc_pn = component.getField("LCSC Part") or lcsc_pn c = component if len(refs) == 0: continue footprint = c.getFootprint().split(':') if len(footprint) > 1: footprint = footprint[1] else: footprint = footprint[0] # Fill in the component groups common data out.writerow([c.getValue() + " " + c.getDescription(), ",".join(refs), footprint, lcsc_pn]) f.close() ================================================ FILE: kicad_pos_to_cpl.py ================================================ #!/usr/bin/env python3 # coding=utf8 # Converts a KiCad Footprint Position (.pos) File into JLCPCB compatible CPL file # Copyright (C) 2019, Uri Shaked. Released under the MIT license. # # Usage: kicad_pos_to_cpl.py [overrides.json] # # The overrides file is a JSON file that contains a single object. The key of that object # is the reference of the part of override, and the value is the amount of degrees to # add to the part's rotation. For instance, to rotate U1 by 90 degrees, and Q1 by 180 # degrees, put the following value in the overrides.json file: # { "U1": 90, "Q1": 180 } import sys import csv import json from collections import OrderedDict overrides = {} if len(sys.argv) == 4: with open(sys.argv[3], 'r') as overrides_file: overrides = json.load(overrides_file) with open(sys.argv[1], 'r') as in_file, open(sys.argv[2], 'w', newline='') as out_file: reader = csv.DictReader(in_file) ordered_fieldnames = OrderedDict([('Designator',None),('Mid X',None),('Mid Y',None),('Layer',None),('Rotation',None)]) writer = csv.DictWriter(out_file, fieldnames=ordered_fieldnames) writer.writeheader() for row in reader: angle_adjustment = overrides.get(row['Ref'], 0) writer.writerow({ 'Designator': row['Ref'], 'Mid X': row['PosX'] + 'mm', 'Mid Y': row['PosY'] + 'mm', 'Layer': row['Side'].capitalize(), 'Rotation': (360 + int(float(row['Rot']) + angle_adjustment)) % 360 })