In a python script for KiCad version 7, I’m trying to create a fill around my whole PCB and then make a zone cutout that uncovers the board. I can’t figure out how to make the cutout.
It’s a follow up related to the question I posted here:
Before I make this fill I can use board.ComputeBoundingBox() to find the PCB outline, but I can’t figure out how to use this result to make the cutout.
Are you having trouble getting coordinates out of the bounding box or getting trouble creating cutout? If it’s the latter then look at Outline() of the zone that returns SHAPE_POLY_SET that has hole related methods.
Maybe Plugin howtos · Wiki · eelik-kicad / KiCad Documentation · GitLab helps. It’s been a while, I don’t remember the details, but at least you can create a polygon with a hole by drawing it manually and then inspect it in the python console. Then you can reconstruct it with new polygonal shapes.
I think I have a solution. It wasn’t the coordinates of the corners, but understanding how zones work. I didn’t understand that once you define a zone you can then create a hole with NewHole() that will have an index (probably 0 for the first hole). By setting corners using that index, you get a cutout.
Thanks for the reference. It was helpful in understanding how zones work.
I found this solution to work. It is not exactly what I want to do but it is a prototype. Assuming that the index of the hole is 0 might be a problem for more general implementation
import pcbnew
board = pcbnew.GetBoard()
zone = pcbnew.ZONE(board)
zone.SetLayer(pcbnew.F_Cu) #outline of zone
corner1 = pcbnew.VECTOR2I(pcbnew.FromMM(120), pcbnew.FromMM(120))
corner2 = pcbnew.VECTOR2I(pcbnew.FromMM(130), pcbnew.FromMM(120))
corner3 = pcbnew.VECTOR2I(pcbnew.FromMM(130), pcbnew.FromMM(130))
corner4 = pcbnew.VECTOR2I(pcbnew.FromMM(120), pcbnew.FromMM(130))
for c in [corner1, corner2, corner3, corner4]: zone.AppendCorner(c, -1)
#make a hole and define the corners
zone.NewHole()
corner1 = pcbnew.VECTOR2I(pcbnew.FromMM(122), pcbnew.FromMM(122))
corner2 = pcbnew.VECTOR2I(pcbnew.FromMM(128), pcbnew.FromMM(122))
corner3 = pcbnew.VECTOR2I(pcbnew.FromMM(128), pcbnew.FromMM(128))
corner4 = pcbnew.VECTOR2I(pcbnew.FromMM(122), pcbnew.FromMM(128))
for c in [corner1, corner2, corner3, corner4]: zone.AppendCorner(c, 0)
#add to the board
board.Add(zone)
pcbnew.Refresh()