Filling Zones (copper pours) inside the Python API

I’m writing a Python script to generate gerbers, drill files, BOM and position file from a layout. It’s similar in function to [1] but generates additional types of files for PCBA. In his comments for [1], John mentions he doesn’t know how to fill zones through the Python API. According to [2], this was impossible in 2015.

[3] teaches us how to get a list of zones in a board (zone=board.GetArea(idx)), but not how to fill them.

Is it possible to fill zones inside the Python API in 2019?

[1] https://github.com/johnbeard/kiplot
[2] Python Scripting 'Filled Zones'
[3]

The forum tells me that new users can put at most two links in a post, so here’s the missing link for [3]: https://github.com/KiCad/kicad-source-mirror/blob/master/pcbnew/python/examples/listPcb.py

import pcbnew
board = pcbnew.GetBoard()
filler = pcbnew.ZONE_FILLER(board)
zones = board.Zones()
filler.Fill(zones)

2 Likes

Seth, thank you! This works like a charm. I tried making a list of zones and passing that to ZONE_FILLER, but it would fail with a SWIG error. Thank you for giving the the right answer so quickly!

Ari.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.