Code completion problem with pcbnew in python

I’m trying to make a plugin, but I can’t get object code completion when using VScode or Pycharm. But kicad’s built-in Scripting Console can do this. Does it require special configuration of the IDE, or is this a function of the Scripting Console itself?


It’s a feature of an IDE, and the KiCad shell can be said to be a kind of an IDE, too. Well, not really, but anything with code completion must have that implemented that. I don’t know the context of your other screenshot so I can’t say why it doesn’t work. For the KiCad shell it’s pretty easy because it just inspects live objects, or at least that’s how I suppose, because it’s running the code interactively while you write. Therefore in your example the module “pcbnew” is imported and “pcb” is now actually an object living in the interpreter, and the interpreter has a way to inspect it. This may be more difficult for an IDE which doesn’t run the lines you write but works as a coder’s text editor.

For 7.0:


    "": {
        "PYTHONNOUSERSITE": "1",
        "PYTHONPATH": "C:/Program Files/KiCad/7.0/bin;C:/Program Files/KiCad/7.0/bin/DLLs;C:/Program Files/KiCad/7.0/bin/Lib;C:/Program Files/KiCad/7.0/bin/Lib/site-packages",
        "PYTHONHOME": "C:/Program Files/KiCad/7.0/bin",
        "PATH": "C:/Program Files/KiCad/7.0/bin;${env:USERPROFILE}/Documents/KiCad/7.0/3rdparty/Python39/Scripts;C:/Program Files/KiCad/7.0/bin/Scripts;${env:PATH}"
    "python.envFile": "${workspaceFolder}/.vscode/.env",
    "python.analysis.typeCheckingMode": "basic",
    "python.defaultInterpreterPath": "C:/Program Files/KiCad/7.0/bin/python.exe"


PYTHONPATH="C:/Program Files/KiCad/7.0/bin;C:/Program Files/KiCad/7.0/bin/DLLs;C:/Program Files/KiCad/7.0/bin/Lib;C:/Program Files/KiCad/7.0/bin/Lib/site-packages"
PYTHONHOME="C:/Program Files/KiCad/7.0/bin"
PATH="C:/Program Files/KiCad/7.0/bin;${USERPROFILE}/Documents/KiCad/7.0/3rdparty/Python39/Scripts;C:/Program Files/KiCad/7.0/bin/Scripts;${PATH}"

Close terminals and reload windows.

1 Like

To get type info suggestions, you have to specify types for variables yourself:

You could write it shorter like this, but beware of name collisions (abs for example):

from pcbnew import *
brd: BOARD = LoadBoard("...");
1 Like

Thanks, declaring object types can make code completion work.

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