[Qgis-user] Using QgsProcessingParameterMultipleLayers with a filter

Lpjf Carto lpjf.carto at gmail.com
Fri Dec 4 05:37:22 PST 2020


Hello,
I am having trouble using the QgsProcessingParameterMultipleLayers function:
I want to use this function in a graphic model with the "Multiple Sources"
parameter, by automatically checking the boxes that meet a filter criterion
on layers' name.
For this, I create a list containing the names of the filtered layers:
"Class Modle (QgsProcessingAlgorithm):

    def initAlgorithm (self, config = None):
        layers = QgsProject.instance (). mapLayers ()
        list = []
        for layer in layers.values ():
            if '_GUF' in layer.name ():
                list.append (layer.name ())
        self.addParameter (QgsProcessingParameterMultipleLayers
('testfiltre', 'test', layerType = QgsProcessing.TypeVectorPolygon,
defaultValue = list [:])) "

The defaultValue parameter is populated with the content of the filtered
list.

This code works well when I use it in a script created from the Processing
Toolbox on Qgis version 3.14.16-Pi on Windows 10.
On the other hand, I tested it on an earlier version (Qgis version
3.10.10-A Coruña and Qgis version 3.4.7-Madeira), and it does not work on
these versions:
No error message appears, but at runtime the layers matching the filter
criteria are not selected.
Why is the defaultValue = list parameter not taken into account on Qgis
versions prior to 3.14.16?
Is there a workaround?
Or maybe this is not the good way to do what I want?

Thank you.
Regards,
Julien
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20201204/7dee5c3e/attachment.html>


More information about the Qgis-user mailing list