[QGIS-Developer] Add algorithm to an existing provider?

Raymond Nijssen r.nijssen at terglobo.nl
Thu May 12 23:15:08 PDT 2022


Is there a way to add a processing algorithm to an existing provider 
using pyqgis?

I have 2 plugins and don't know if they are both installed (or which one 
will load first). The both contain processing algorithms and I want 
those to end up in the same group.

Documentation is a bit brief on this:

QgsProcessingProvider

Examples show to put the addAlgorithm() function(s) in the 
loadAlgorithms() function. Then calling

QgsApplication.processingRegistry().addProvider(provider)

adds the group (=provider?) and the algorithms are in it.



What I want to do is finding the provider if it exists already:

self.provider = QgsApplication.processingRegistry().providerById('test')
if self.provider is None:
     self.provider = RayProvider()

and then:

self.provider.addAlgorithm(TestAlgorithm2())

This doesn't work, neither when doing:

provider.refreshAlgorithms()
provider.load()
provider.loadAlgorithms()
...


I'm currently trial-and-errorring my way through this, but I hope 
someone has a hint. Even someone pointing at 2 plugins working like this 
would be very welcome!

Kind regards,
Raymond


More information about the QGIS-Developer mailing list