Accessing nets of current board

Hallo, I’m just starting to learn Python just to add some features I need in KiCAD. Investigating the very poor docs of the Python official API I start guessing how to access the netlist of the current board.
It seems that there’s not a reference to such data in the board objject (but I’m not very good in Python to assert this assumption). My final goal is to add a net on a already existing board without the need to exploit the board file.
Hope this thread is the correct one for such a request.

import pcbnew
board = pcbnew.GetBoard()
modules = board.GetModules()
nets = set()
# iterate thourh all footprints
for mod in modules:
    # get all pads of a footprint
    pads = mod.Pads()
    # add pads nets to the set
    nets.update([pad.GetNetname() for pad in pads])

Thnx. Your hint is enlighting . Is it possibile to set NetName in pad ?

You do have access to http://docs.kicad.org/doxygen-python/namespacepcbnew.html?

Every member of BOARD_CONNECTED_ITEM has the option to get the net it is connected and to set the net it is connected to. If the net already exist it is just a matter of setting the net code. If the net does not exist you’d first need to create the net. I don’t know how one creates a net. But I’d look into the WireIt action plugin code.

In general action plugins are a good source of code examples

1 Like

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