2

I have code that exports several maps. For a set of maps, I want to make sure one layer used in a previous map is turned off. I don't want to remove it completely.

Anyone know what I am doing wrong?

aprx = arcpy.mp.ArcGISProject("CURRENT")  
m = aprx.listMaps("Map")[0]  
lyt = aprx.listLayouts("Layout")[0]

for elm in lyt.listElements("MAPFRAME_ELEMENT", "Layer"):
        elm.visible = False
2
  • What does happen when you run it? No layers or all layers turn off? Nothing at all? Errors, or something else?
    – Midavalo
    Nov 30, 2023 at 1:18
  • @Midavlo Nothing at all. It finishes but the layer does not turn off
    – Mariah.H
    Nov 30, 2023 at 1:27

1 Answer 1

7

I expect that your for loop never runs, because there is no layout element that matches your "Layer" wildcard.

You should be getting your layers from the map, not from the layout. Use m.listLayers("wildcard") for this.

Eg,

aprx = arcpy.mp.ArcGISProject("CURRENT")  
m = aprx.listMaps("Map")[0]  
layer = m.listLayers("my_layer_name")[0]
layer.visible = False
0

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.