Custom Design Rules for Footprint

I have created an edge-connector in Kicad which looks as follows:

Obviously, this violates the copper to edge clearance rule, so I wanted to create a custom rule but cannot figure out how to make it apply to just this one footprint.
In the general design-rules, I chose a copper to edge clearance of zero and added the following custom rules:

(version 1)
(rule "General copper to edge"
	(constraint edge_clearance (min 0.25mm)))

(rule "Allow connectors at the edge"
	(condition " A.Reference ==  'J201' ")
	(constraint edge_clearance (min -1mm)))

However, this does not work. I guess the reason is, that the error appears on the pad, not on the footprint. So I would need something like A.Parent.Reference == 'J201' but I am afraid that this is not a thing.
By the way: If I leave out (condition " A.Reference == 'J201' ") I do no longer get any violation in the DRC but of course also all other items are no longer being checked which is not good.

Do you have any advice how I could fix this? From the manual it says that A.Parent returns the unique identifier, but I cannot figure out what that is. I also looked at the PCB-File in a text editor but all I can find about my footprint are tedit and tstamp.

Any help would be greatly appeciated!

For some slightly related background information, see negative track/edge clearance should allow track overlapping edge.cuts while routing (#11609) · Issues · KiCad / KiCad Source Code / kicad · GitLab. (It’s for version 6.99.)

The edge/pad clearance comes from the manufacturer and they don’t like the pad going to the edge. Depending on the manufacturer, they may ask you what to do with it, or they just add clearance there. Or they interpret it as plated edge which you don’t probably want and which costs much more (like castellation). I would suggest just keeping the distance. It doesn’t really affect your component much in real life.

But if you really want to, you can use insideCourtyard for the pad, or create a named rule area inside the footprint and use insideArea.

For 6.99 @JeffYoung recently added the footprint ID (library link), but I don’t know how to use it to test if the pad belongs to a certain library footprint, for example MyLib:EdgeConnector, and I don’t know how the Reference could be used for a pad (logically it would work like the library ID).

EDIT: Jeff, the whole Footprint item looks strange to me. I can’t do something like ‘A.Footprint.Reference’, and using a footprint in a condition doesn’t seem to be very productive because setting a clearance or other constraint for a footprint is irrelevant. I should be able to find the parent footprint for an item and test a footprint’s property for that child item, but I don’t find a way to do it.

Thank you very much for the rapid answer!

Of course you are right - in this case it would be smarter to just move the footprint slightly inwards. I think I got too focused on changing the Design-Rules, thanks!

Using insideArea is stragely not working for the edge, even if I draw a massive area around the whole board. Whereas if I put the connnector close to the hole and specify hole_clearance it does work. But for now, I will just move the connector inwards :smiley:

The footprint ID sounds very interesting! I’d be happy to know more about that.

Because another case in which I would like to apply this is the following: I have one DFN footprint on a board which otherwise has only relatively large components. In this case it would be nice to have a smaller clearance only for this footprint. You may ask how this could make sense because then the whole board has to be manufactured to this specification. Which is correct in theory! Unfortunately, when ordering from a beloved, cheap chinese manufacturer, I had multiple occasions where traces where shorted even though they were within there design-rules and the claim to do flying probe tests.
I emailed the customer-support and got the following response:

The line width and spacing of this board are at the edge of our company’s process. […] Brings great difficulty to production. This kind of order production may not meet customer needs and we can also not can be made it perfect. And we suggest that if increase the space and width of the trace on next time in order to avoid the same problem happen again?

Therefore, it would be smart to have the small clearance only on one footprint and then this footprint can be specifically checked with the microscope. But of course placing an area and unsing insidearea is not that big of a deal :smiley:

I added a named rule to a footprint (inside the footprint, in the footprint editor) and placed the pads near the edge:

It’s enough that the pads (maybe their centers?) overlap with the rule area.

Here’s the rule:

(rule edgeclear
(condition "A.insideArea('fp_rulearea') && A.Type == 'Pad'")
(constraint edge_clearance(min 0mm))
)

It works.

Oh yeah, that works for me as well, thanks! Putting it on the edge is fine, but over the edge still gives an error. Do you have the same behaviour?

@eelik the expression evaluator doesn’t currently have an object type (A and B are hard-coded special cases).

So A.Footprint could return a number or a string, but it can’t return something that has properties meaning A.Footprint.whatever is a non-starter.

How then can we use the footprint’s properties for our benefit?

Use -1. Remember that the manufacturers interpret copper crossing edge as plated edge.

Oh, good to know!

I already had it at it at -1 but discovered the difference in our setup: My footprint is on the bottom layer. Therefore, I also put the area on the bottom layer and then it does not work.

Error:

No Error:

Everything else stays the same. Do you have an explanation for that?
This seems like a very strange behaviour because in my big project I have another area on B.Cu (for the clearance of my DFN footprint) which does work perfectly fine with the custom design rules.

You can use the footprint’s properties on any rule that applies directly to the footprint. For instance A.Library_ID == 'myLib:edgeConnector'.

“for our benefit” meant if there’s a way to use them in rules for pads etc., but apparently not. I still can’t create rules for some pads of footprint with certain library ID.

I’m not sure what you did, but I tested and there seems to be a bug.

The footprint is flipped, and because front layers become back layers (and vice versa), the rule area is flipped, too. The color of the rule area is changed to blue, so it is in the same layer than the pads. But the custom rule doesn’t work anymore, it doesn’t see the pad being inside the area, even though it still is.

That’s exactly what I meant. But if I put the rule area on F.Cu, the rule is correctly applied, even if the footprint is on B.Cu

I’m still not sure if we are doing the same thing. I have drawn the rule are on F.Cu in the footprint editor, and it’s not correctly applied when the footprint is flipped to B.Cu. So, what do you mean by “put the rule area on F.Cu”?

So I have the footprint always on B.Cu.
Now I draw a rule area on F.Cu over the center of the footprint like you did and the custom rule is correctly enforced - I don’t get any DRC violations. However, this is strange because the rule area is not on the same layer as the footprint…
But when I draw the rule area on B.Cu, not changing anything else, the custom rule is no longer applied and I get a DRC violation.
I tried to show these two cases in the pictures above.

To be sure, here’s what I have. Pads and the rule area on F.Cu when the footprint is in the footprint editor. When the footprint is on F.Cu, it works. When it’s flipped to B.Cu (the pads and the rule area go there), it doesn’t work.

I considered:

A.Parent_Footprint_Library_ID

for child items of footprints, but it’s pretty hard to love.

Next up was:

A.GetParentFootprintProperty( "Library_ID" )

which would be more general purpose, but is still pretty hard to get excited about.

The best thing to do would be to implement object types in the scripting language so that this would work:

A.ParentFootprint.Library_ID

But that’s above my pay-grade.

@craftyjon @twl

The object types would be cool but also complicated.

I’m not aware of a way to do this in Altium, either. You can check what refdes the pad belongs to, but not what footprint library ID, unless I’m missing some way.

How much do they pay you, anyway?

I think I’ll report the bug described above, or are you just writing a fix? :slight_smile:

But back to the original topic. @Fietsdesigner, you can also put the pads in the footprint into a named group. Then a simple rule is enough:

(rule fpgrp
(condition “A.memberOf(‘fpgrp’)”)
(constraint edge_clearance(min -1mm))
)

This has an additional benefit, namely the condition can’t be triggered by accident. A rule area condition can be triggered if an item overlaps the area for whatever reason and there are no extra checks.

I do submit the odd work-package from time to time, but for the most part $0.00.

But I made a pretty good pile from Frame and Adobe, so I don’t mind…

That sounds really good! How do I create a named group though?

Ah, now I see the difference - I did not create the named area as part of the footprint but separately: