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
 )
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Aug 20, 2021 at 21:53
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
...
answered Aug 21, 2021 at 3:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.