Error: BOARD object has no attribute GetNetsByNetcode

I am trying to start python scripting in KiCad Pcbnew, but I seem to be unable to correctly get the BOARD object.

Here is my code, borrowed from

import pcbnew

start with the board object

board = pcbnew.GetBoard()

print ‘xxx’

returns a dictionary netcode:netinfo_item

netcodes = board.GetNetsByNetcode()
for netcode, net in netcodes.items():
print(‘netcode {}, name {}’.format(netcode, net.GetNetname()))

The ‘xxx’ gets printed, then

AttributeError: ‘BOARD’ object has no attribute ‘GetNetsByNetcode’

GetNetsByNetcode IS an attribute of BOARD class, according to

Can anyone please tell me what I am doing wrong here?


What version of KiCad are you using? For questions like this, it is best to paste the information from Help. There’s a button “copy” for exactly this purpose.

Edit to add: that documentation is for the nightly. It can be slightly different for other versions such as Stable. The best reference for what is available in your version is within python Scripting Console using the dir(pcbnew.GetBoard()) command.

Many thanks for your reply, Greg.

I am using version 4.0.7 of KiCad.

I might have also added that I am using execfile() to run a .py file, rather than entering the code directly into the interpreter.

I tried the dir() command that you suggested and there is no GetNetsByNetcode attribute listed there.

I tried replacing the GetNetsByNetcode attribute with one that IS listed, namely GetNetCount, and IT WORKED!

Thank you, very much, for that.

Perhaps now I can move on to my next hurdle.

Best Regards,

Great! Post any questions you have. I’ve got decent experience with pcbnew python (LayerViewSet, KiCommand, and KiPadCheck).