I made a script that export the SLD stile from the layers in my QGIS project, but... I'm attempting to get the name of the group in which the layer is stored, to use it as a variable for creating a folder to store the sld. How can I do this?

import processing
layers = self.iface.mapCanvas().layers()

for layer in layers:
    name = layer.name()
    pathsld = 'C:/Style/SLD/'+str(name)+'.sld'  

1 Answer 1


You can get the current group of the layer by making each layer selected in turn.

layers = iface.mapCanvas().layers()
layer_tree_view = iface.layerTreeView()
for layer in layers:

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.