New API KiCad.get_board() timeouts

Hi there, I am trying to write a plugin with the 9.0 new API, and I am able to try my logic from Window command, that is, KiCad.get_board() works fine from outside the PCB editor. However it does not work from within the PCB editor. And I tried it from the KiPython console and got below error stack.

What could be wrong there? I’ve checked that “Enable KiCad API” box from preferences->Plugins. My KiCad version is 9.0.5

>>> from kipy import KiCad
>>> board = KiCad().get_board()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "D:\Program Files\KiCad\9.0\bin\Lib\site-packages\kipy\kicad.py", line 225, in get_board
    docs = self.get_open_documents(DocumentType.DOCTYPE_PCB)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Program Files\KiCad\9.0\bin\Lib\site-packages\kipy\kicad.py", line 216, in get_open_documents
    response = self._client.send(command, commands.GetOpenDocumentsResponse)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Program Files\KiCad\9.0\bin\Lib\site-packages\kipy\client.py", line 72, in send
    raise ConnectionError(f"Error receiving reply from KiCad: {e}") from None
kipy.errors.ConnectionError: Error receiving reply from KiCad: Timed out

The built-in scripting console is for the legacy SWIG API. For the new API you have no need of a built-in console, you can use an interactive REPL in any external terminal or editor / IDE.

If so can I still make it a pcbnew.ActionPlugin? And the external terminal or editor/IDE approach means I can’t have it as a PCB Editor menu item?

No, that’s an old API thing. You can still make PCB plugins, but it’s a different setup entirely. See the documentation here: For Add-on Developers | Developer Documentation | KiCad