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