Deleting zones via the Python API

I want to delete all zones of a board via the Python API. My attempts so far:

import pcbmerge
board = pcbnew.LoadBoard('myboard.kicad_pcb')
for i in range(board.GetAreaCount()):
    board.Delete(board.GetArea(i)) # doesn't work
    board.Remove(board.GetArea(i)) # doesn't work
    board.RemoveNative(board.GetArea(i)) # doesn't work

Thanks in advance!

board.Remove(board.GetArea(i)) should work.
Did you save the board after that?

Edit: actually that will work for 1 zone, but you can’t remove items from the list and expect indexes to remain the same. Either get all zone objects and remove them after or repeatedly remove area #0 until there are no more.

1 Like

Thank you! The following code worked as suggested:

import pcbmerge
board = pcbnew.LoadBoard('myboard.kicad_pcb')
for i in range(board.GetAreaCount()):
    board.Remove(board.GetArea(0))

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