1 Welcome to KiClearance

This Python program converts a given table of voltage distances into KiCad design rules.

_images/overview.png

1.1 Installation

Install KiClearance directly from pyPI:

pip install kiclearance

1.2 Usage

Create a table (clearance.ods/xls/csv) in your KiCad project directory with voltage clearances defined by your requirements (e.g. standards). Use this template as a guide: clearance.ods.

Add the net classes to each connection in the circuit diagram.

_images/net_class_directive_labels.png

Add the same net classes in the net classes of the PCB editor: KiCad PCB Editor: File -> Board Setup -> Design Rules -> Net classes

_images/board_setup.png

Navigate to the project folder with the KiCad project and the clearance.ods/.xls/.csv file. Open a terminal and execute :

python -m kiclearance

Now a file yourprojectname.kicad_dru is generated, which contains the rule sets.

Open your Kicad project, the rule sets are now stored and you can start the routing.

1.3 Tips and tricks

If two network classes are assigned to a connection by mistake, this is displayed as an error in the Electrical Rules Checker (Inspect -> Electrical Rules Checker).

KiCad works through the rules from bottom to top: Once an applicable rule has been found, kiCad will not search for further rules. Keep this in mind when adding your own rules.

1.4 Example

A complete example can be found here.

1.5 Troubleshooting

This program has so far been tested only on linux.

2 KiClearance function documentation

Generate clearance rules for kicad from a human-readable table.

kiclearance.kiclearance.look_for_clearance_table_file(folder: str, clearance_table_file_name: str | None = None)

Try to find the clearance table file in the given folder.

This file has either the default name ‘clearance’ or a name given by the user. The file has to be: .ods, .xls or .xlsx.

Parameters:
  • folder (str) – folder name to look for the clearance table file

  • clearance_table_file_name (str) – clearance table file name

kiclearance.kiclearance.look_for_kicad_project(folder: str, kicad_project_name: str | None = None)

Try to find the kicad project automatically if no project_name is given.

This is done by searching for kicad_pro files. :param folder: folder of the kicad project :type folder: str :param kicad_project_name: Kicad project name, optional :type kicad_project_name: str

kiclearance.kiclearance.parse_excel_table(clearance_table_file: str)

Parse clearance data from the given clearance table file.

Data will be stored in the following format: List of lists: [[Net_1, Net_2, distance], [Net_1, Net_3, distance], …]

Parameters:

clearance_table_file (str) – clearance table file (.xls, .ods, .csv)

kiclearance.kiclearance.usage()

For terminal usage.

kiclearance.kiclearance.write_design_rule_file(clearance_table_data, folder, kicad_project_name: str, factor_inner_layers: float, min_track_distance: float)

Write the rules to the design rule file (your_project.kicad_dru).

A reduction factor for the inner layers can be applied, as there is less pollution, typically inner clearance can be reduced.

Parameters:
  • clearance_table_data (str) – clearance table data

  • kicad_project_name (str) – kicad project name

  • factor_inner_layers (float) – distance factor for inner layers distance. Default is 0.5

  • min_track_distance (float) – minimum track distance in mm

  • folder (str) – directory