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:
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?
Learning python by using KiCad API will give you a lot of bad habits
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.