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()
Solved! Go to Solution.
What version of ArcMap is installed on the machine where it is working correctly?
What version of ArcMap is installed on the machine where it is not working correctly?
>>> import arcpy >>> MXD = arcpy.mapping.MapDocument("CURRENT") >>> DF = arcpy.mapping.ListDataFrames(MXD, "Layers")[0] >>> LYR_list = arcpy.mapping.ListLayers(MXD, "*_env*",DF) >>> for lyr in LYR_list: ... lyr.visible = True ... output_PDF = r"T:\JOBS\123110494\gis_data\spatial_data\project_discipline\modeling\scripts\ZB\PDF\\" + str(lyr) + ".pdf" ... arcpy.mapping.ExportToPDF(MXD, output_PDF) ... lyr.visible = False ... MXD.save() ...
Working machine: 10.1, with SP0.
Note: I did remove the MXD.save() lines, but that shouldn't make a difference.
Joshua,
I tried running the script with only a single MXD.save() in my code, right at the end, outside of all for loops, and it worked!
-Zack
MXD = arcpy.mapping.MapDocument(MXD_file) DF = arcpy.mapping.ListDataFrames(MXD)[0] LYR_list_MXD = arcpy.mapping.ListLayers(MXD,"*_env*",DF) LYR_count = len(LYR_list_MXD) for LYR in LYR_list_MXD: LYR.visible = False MXD.save() del MXD # Turn on each layer individually and export map as new PDF for i in range(LYR_count): # now you need to reopen the MXD... MXD = arcpy.mapping.MapDocument(MXD_file) DF = arcpy.mapping.ListDataFrames(MXD)[0] LYR = arcpy.mapping.ListLayers(MXD,"*_env*",DF) LYR.visible = True output_PDF = OutputPDFFolder + "\\" + str(LYR) + ".pdf" arcpy.mapping.ExportToPDF(MXD, output_PDF) LYR.visible = False MXD.save() del MXD