Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

arcpy visible not working

$
0
0
I have a script that adds .lyr files to an MXD.

A loop then iterates through the layers in the MXD and turns them all OFF, using the lyr.visible = False function. This part of my code works.

I then want to iterate through the list again, turn on the first layer, export the map as a PDF, turn off the layer, then move onto the next layer. This is the part that doesn't work. The layers do not turn on again. The PDFs export, but they are all blank.

I've seen this question asked before, but the solutions listed don't seem to be working for me.

I've posted the code below.

Code:

LYR_list_MXD = arcpy.mapping.ListLayers(MXD,"*_env*",DF)

for LYR in LYR_list_MXD:
        LYR.visible = False

MXD.save()

# Turn on each layer individually and export map as new PDF

for LYR in LYR_list_MXD:
        LYR.visible = True
        output_PDF = OutputPDFFolder + "\\" + str(LYR) + ".pdf"
        arcpy.mapping.ExportToPDF(MXD, output_PDF)
        LYR.visible = False
        MXD.save()

Any suggestions would be greatly appreciated.

Thanks

-Zack

Viewing all articles
Browse latest Browse all 2485

Trending Articles