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:

Image

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:

Image

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:

Image

But ECAD show violation by red highlighting:

Image

And DRC says about error, because one courtyard overlapping another one:

Image

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:

Image

2) Go to Design Rules -> Custom Rules and copy&paste this code:

  1. (version 1)
  2. (rule "TEST POINT EXCEPTION"
  3. (constraint courtyard_clearance (min -2mm))
  4. (condition "A.Reference=='TP1'")
  5. )
  6.  

  • 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)

Image

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.

Image

Note: in the project folder the new file .kicad_dru will be automatically created:

Image

KiCad Rule Exception Example Project

Schematic

Image

Board

Image

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 ?

1.07K
0
Stephen 19 days ago #

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

Cookies?