Hi I get an error message: PgmOrNull

PGM_BASE * PgmOrNull ()
similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from a script, not from a kicad appl More…
Hi I get an error message:


It doesn’t matter how I write the code whether with a period, which would be wrong according to Python, or right without a period. See below pictures.


What should I do with the below so that I don’t get the error message and my plugin is registered?
And unfortunately, that’s not how it works :hot_face:

And unfortunately, that’s not how it works

You will not be able to call register() of an action plugin outside of pcbnew. It’s intended to be called from within pcbnew only.

Why are you trying to do that? Most likely you don’t need to. If you are trying to debug your plugin then you need to have an alternate entry point in your script.

Hello, I’m learning Python, I took an existing script and first removed all the obvious errors that the PyCharm editor showed me. I also used the KiCad help to customize the script. Unfortunately, this only works up to this point. Can you show me how to call the registry via pcbnew as code?

I don’t know even if I proceed exactly as in this guide I get this error message.
https://dev-docs.kicad.org/en/python/pcbnew/

Learning python by using KiCad API will give you a lot of bad habits :smiley:
That’s not to say it’s the worst way to learn, building something useful is a very good incentive. But you need to have a concrete problem that you want to solve.

The reason KiCad API will give you bad habits is because it’s not built with python in mind, it’s just a wrapper of KiCad’s c++ internals. Understanding how it works (and how it breaks) often requires reading c++ source code.

Back to your issue: you dont need to call register() yourself, pcbnew calls it internally when it initializes it’s plugin subsystem. In other words that method will never work when launched in your python IDE.

You should organize your code in such a way that debugging your script doesn’t execute register() at all. It can be done if you have a separate module with your logic in it which can be executed both from plugin Run() and from a script designed to work from CLI.

Another way to debug if you don’t want to split your code into separate module is to run directly from pcbnew. You can use wx.MessageBox() and wx.LogInfo() statements to track the state of your application, similar to how you would use print in a script.

One more thing, I noticed that you put your script in a subfolder of scripting, in that case it needs to be a python package and have a __init__.py file. See complex plugin example in the docs you linked.

Otherwise your plugin will not show up in pcbnew.

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