How to write custom KiCad rule exception? Simple example of courtyard overlap resolve
The Altium Designer can simplify 3D body to the 2D rectangular shape and monitor clearance between components, so most of AD engineers doesn't use Courtyard (=component outline) layer. Moreover, in AD you can easily set rule exceptions for each of specific violation:
And KiCad, on the contrary, uses Courtyard to detect components collisions and many users encounter with the Courtyard overlap error, that means components placed too close and you should also handle it by writing simple rule exception:
Problem
Here is the typical problem, where you actually know, that that components (in this case just test point) shouldn't affect any problem in the real PCB:
But ECAD show violation by red highlighting:
And DRC says about error, because one courtyard overlapping another one:
Very bad practice to fully turn off courtyard overlap rule or just leave things like that and have some violations (errors and warnings) in released board project.
Solution
1) Press File -> Board Setup:
2) Go to Design Rules -> Custom Rules and copy&paste this code:
(version 1) (rule "TEST POINT EXCEPTION" (condition "A.Reference=='TP1'") )
- The first line is required for internal KiCad architecture
- Each Rule starts with rule and any name
- Constraint set what you need and set specific value
- Choose condition, the most useful is just specify component, that you can do by designator (reference)
Check before code errors and try again perform DRC, and even though the test point is still in the same place, it's now thrown into an exception.
Note: in the project folder the new file .kicad_dru will be automatically created:
KiCad Rule Exception Example Project
Schematic
Board
Download
CadLab
https://cadlab.io/project/26993/master/files
Directly from Server
CustomRuleKiCad.zip
Conclusions
- The released board must be 100% DRC clean (0 errors, 0 warnings)
As you can see writing custom rule exception it's not a big deal ?
Great tip, just came across your site (now bookmarked) amazing and very helpful content, thanks for sharing. I’d love to see more KiCad articles