Creating a new plugin

Hallo, I’m trying to write a new plugin . Since I’m a newbie in Python a decided to start from a working plugin and mimic its structure to avoid issues.
To build the main dialog I’m using wxFormBuilder.

Unluckly the code seems not to work and I’m not understanding why. There’s a way to check where the error is instead trying to load it on KiCAD? The code should just add it’s icon on tools menu and open its dialog when triggered (but fails).

The plugin code can be found attached here: (11.7 KB)

and/or on my github repository:

I found the error:

the variable: _version_ declared in and recalled in in the following line:

from addnet.addnet_plugin import __version__

Cannot be shared in this way for some reason. I just moved it’s declaration inside to make it work but I would really like to understand how to reference a variable between modules.

Best regards,

1 Like

You need to use relative imports everywhere

from .addnet_plugin import blah

Also don’t name variables that are meant to be shared with double underscores in front, such variables have special meaning to be super private, which is not really enforced but at least that’s the convention.

ohhh thnx. Need to read that damn Python manual :wink:

I stumbled on a bug that’s already been reported:

and signed as fixed (from almost 3 years) but apparently in my case the class NETINFO_ITEM is still not usable trough Python:

import pcbnew
board = pcbnew.GetBoard()
net = NETINFO_ITEM(board, "NEWNET")
Traceback (most recent call last): File "<input>", line 1, in <module>
NameError: name 'NETINFO_ITEM' is not defined

Someone else tried this? I’m running KiCAD 5.1.4 on Windows 10 Pro

Try pcbnew.NETINFO_ITEM instead. It is included in the pcbnew module, so you need to put the pcbnew namespace in front of it.

Yes I did … and it seems to work but I still have problem trying to set a pad with the newly created net.
It seems that after setting the new net to the pad it become unstable and if I try to select it after the assigment pcbnew closes (probably an exception or something).
The repository has been updated with the last commit (crashing).

Ok probably I found the way … I needed to add the net to the board prior setting it to the pad.

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