2

I am trying to switch visibility preset using python but I cannot find any relevant method in the documentation . Does anyone knows how I can do it? The VisibilityPresetCollection class is accessible using the following code QgsProject.instance().visibilityPresetCollection().enter image description here

2
def to_print():
    layers= iface.mapCanvas().layers()
    for layer in layers:
        iface.legendInterface().setLayerVisible(layer, False)

    layer_list = QgsProject.instance().visibilityPresetCollection().presetVisibleLayers(u'to_print')
    for layer in layer_list:
        iface.legendInterface().setLayerVisible(QgsMapLayerRegistry.instance().mapLayer(layer), True)



def to_work():
    layers= iface.mapCanvas().layers()
    for layer in layers:
        iface.legendInterface().setLayerVisible(layer, False)

    layer_list = QgsProject.instance().visibilityPresetCollection().presetVisibleLayers(u'to_work')
    for layer in layer_list:
        iface.legendInterface().setLayerVisible(QgsMapLayerRegistry.instance().mapLayer(layer), True)

Here you go! i think this will work for you.

At first you hide every layer, then extract the layers of the selected preset and set them to visible one-by-one though the loop

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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