KiCad 8 python API changes and porting guides

Hello, I started looking at KiCad 8 release candidate. I expect that many plugins will break due to major API changes. I’m creating this topic for sharing findings/porting efforts.

Let me start:

  • pcbnew.PAD.GetParent() no longer returns FOOTPRINT (returns BOARD_ITEM_CONTAINER) - to call FOOTPRINT methods ( in my case it was pad.GetParent().GetOrientationDegrees()) the additional cast is required: pcbnew.Cast_to_FOOTPRINT(parent)

  • NETINFO_LIST object has no attribute AppendNet

    • I was using AppendNet for generating board objects, like this:

      board = pcbnew.CreateEmptyBoard()
      ...
      add_nets(board, netnames)
      ...
      def add_nets(board, netnames):
          net_info = board.GetNetInfo()
          net_count = board.GetNetCount()
          for i, n in enumerate(netnames):
              net = pcbnew.NETINFO_ITEM(board, n, net_count + i)
              net_info.AppendNet(net)
              board.Add(net)
      

      Looks like net_info can be ignored when using KiCad8?

  • Loading footprints does not work for me anymore. The part of my ‘generate board from scratch’ flow was adding footprints:

    def add_diode_footprint(board, footprint, request):
        library = get_footprints_dir(request)
        f = pcbnew.FootprintLoad(str(library), footprint)
        f.SetReference("D1")
        board.Add(f)
        return f
    

    which now fails with following error:

    tests/test_board_modifier.py:37: in add_diode_footprint
        f = pcbnew.FootprintLoad(str(library), footprint)
    /usr/lib/kicad-nightly/local/lib/python3.11/dist-packages/pcbnew.py:19001: in FootprintLoad
        plug = GetPluginForPath(libname)
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    libname = '/home/aws/git/kicad-kbplacer/tests/data/footprints/tests.pretty'
    
        def GetPluginForPath(libname):
    >       plugin_type = IO_MGR.GuessPluginTypeFromLibPath( libname );
    E       NameError: name 'IO_MGR' is not defined
    
    /usr/lib/kicad-nightly/local/lib/python3.11/dist-packages/pcbnew.py:18993: NameError
    

    This might be either wrong usage or perhaps bug in KiCad, did not figure out that one yet (looks more like the latter).

3 Likes

I have quick update on my IO_MGR issue.
I opened pcbnew.py and changed this:

def GetPluginForPath(libname):
    plugin_type = IO_MGR.GuessPluginTypeFromLibPath( libname );
    return IO_MGR.PluginFind(plugin_type)

to this

def GetPluginForPath(libname):
    plugin_type = PCB_IO_MGR.GuessPluginTypeFromLibPath( libname );
    return PCB_IO_MGR.PluginFind(plugin_type)

ant it works. Something went wrong with generation of this file (occurs for both ubuntu nightly and windows builds)

2 Likes

IO_MGR problem has been fixed, if plugin used pcbnew.IO_MGR then it’s called pcbnew.PCB_IO_MGR now. The pcbnew.FootprintLoad works as expected.

1 Like

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