How to read KiCAD pick&place position file using pandas in Python
If you’ve exported a KiCAD pick & place position file using the GUI or the command line:
kicad_export_pos_to_file.sh
kicad-cli pcb export pos MyPCB.kicad_pcb --units mm -o MyPCB.pos
you can read it from within your Python script using pandas.read_table(...)
like this:
read_pos_with_pandas.py
import pandas as pd
pos = pd.read_table('KKS-Microcontroller-Board-R2.2.pos', delim_whitespace=True, names=["Ref", "Val", "Package", "PosX", "PosY", "Rot","Side"], comment="#")
Optionally, you can also index pos
by the Ref
column (which contains values such as C12
, D1
or U5
):
set_index_example.py
pos.set_index("Ref", inplace=True)
You can also pack all that into a function:
read_kicad_pos_file.py
def read_kicad_pos_file(filename):
pos = pd.read_table(filename, delim_whitespace=True, names=["Ref", "Val", "Package", "PosX", "PosY", "Rot","Side"], comment="#")
pos.set_index("Ref", inplace=True)
return pos
If you’ve used .set_index()
, you can access a component such as C13
using
example_lookup.txt
pos.loc["C13"]
Example output:
example_output.txt
Val 100nF_25V
Package C_0603_1608Metric
PosX 187.1472
PosY -101.8243
Rot 180.0
Side top
Name: C1, dtype: object
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow