1

I try to add my own Provider, to be able to use existing custom scripts in QGIS in a standalone script. I followed the explanations from here and created my own provider.

If I run the code below, I can print the natives algs (SAGA, GRASS ...).

But if I uncomment the line QgsApplication.processingRegistry().addProvider(provider), I have a Python error (exit code -1073740791 (0xC0000409)).

from qgis.core import *
from qgis import *

app = QgsApplication([], False) app.initQgis()

sys.path.append('C:\Program Files\QGIS 3.28.1\apps\qgis\python\plugins') import processing from processing.core.Processing import * Processing.initialize()

DEFINE MY CUSTOM PROVIDER

sys.path.append('C:\Users\Georges\AppData\Roaming\QGIS\QGIS3\profiles\default\processing\scripts') from _provider import MyProvider provider = MyProvider()

ADD MY CUSTOM PROVIDER

QgsApplication.processingRegistry().addProvider(provider)

for alg in QgsApplication.processingRegistry().algorithms(): print("{}:{} --> {}".format(alg.provider().name(), alg.name(), alg.displayName()))

My custom provider is just near my custom scripts, and like that:

from qgis.core import QgsProcessingProvider

import Commune_test_model_v4

class MyProvider(QgsProcessingProvider):

def loadAlgorithms(self, *args, **kwargs):
    self.addAlgorithm(Commune_test_model_v4())

def id(self, *args, **kwargs):
    """Used for identifying the provider.

    This string should be a unique, short, character only string,
    eg "qgis" or "gdal". This string should not be localised.
    """
    return 'my_provider'

def name(self, *args, **kwargs):
    """
    This string should be as short as possible (e.g. "Lastools", not
    "Lastools version 1.0.1 64-bit") and localised.
    """
    return self.tr('My Provider')

def icon(self):
    """Should return a QIcon which is used for your provider inside
    the Processing toolbox.
    """
    return QgsProcessingProvider.icon(self)

Please can you help me?

Lilium
  • 1,057
  • 1
  • 6
  • 17
Georgie
  • 11
  • 3

1 Answers1

0

In my custom provider, instead of:

import MyClass

I do:

from MyFile import MyClass

It works, exactly as described in the great example of gacarrillor.

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
Georgie
  • 11
  • 3