2

I am writing a Python script that I will add in to my processing toolbox. I have got the script working so now just a case of setting my Inputs and Outputs. I am struggling with one, I am trying to set it so the user can enter multiple layers as one of the inputs just like how it is set up on the Merge Vector Layer tool below.

enter image description here

I have been trying the following two bits of code to try and set this up but it's a bit of a guess really.

How do I correctly format these?

self.addParameter(
            QgsProcessingParameterMultipleLayers(
                name,
                description,
                QgsProcessing.TypeVectorAnyGeometry
            )
        )

Map = self.parameterAsLayerList(
            parameters,
            name,
            context
        )

1
  • What's the question here :)? I think you've nailed it with the code snippets you posted. That's the way of adding such a parameter to a processing script as well as to read it. Commented Aug 21, 2021 at 2:26

1 Answer 1

4

A simple example of usage is below. Don't forget to import the QgsProcessingParameterMultipleLayers class.

...
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterMultipleLayers(
            'LAYERS',
            self.tr("Input layers"),
            QgsProcessing.TypeVectorAnyGeometry))

 
    def processAlgorithm(self, parameters, context, feedback):
        layers = self.parameterAsLayerList(parameters, 'LAYERS', context)
        for layer in layers:
            #do something with layer
...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.