I am trying to create a map book that show the same extent with different layers displayed in ArcGIS 10.8 and ArcPy (I'm also on Windows 10 and a government computer which I cannot add programs to). I am not a coder, I'm a soil conservationist. I am using this code from Making Map Book of pages with same area shown but different layers turned on/off but find that it creates the maps with all layers minus 1. Meaning the first map in my example code will have all three layers displayed, the second will have two layers displayed, and the last will have one layer displayed.
Since I'm making 18 maps at once, this is basically crashing my program each time and is not producing what I am looking for. I would like to toggle the layer on, export the map, and toggle the layer off. At which point it would move on to the next layer on, export map, layer off again. And so on for all 18 layers.
Any ideas how to fix my issue?
import arcpy, os #Specify output path and final output PDF outPath = r'C:\Users\Outputs' finalPdf = arcpy.mapping.PDFDocumentCreate(outPath + 'WetlandSupportdocs.pdf') #Specify the map document and the data frame mxd = arcpy.mapping.MapDocument(r'C:\Users\Outputs\test2.mxd') df = arcpy.mapping.ListDataFrames(mxd, 'Layers') #Select a tract using the TRACTNBR attribute and zoom to selected cluLayer = arcpy.mapping.ListLayers(mxd, 'clu_a_ny067', df) arcpy.SelectLayerByAttribute_management(cluLayer, "NEW_SELECTION", '"TRACTNBR" IN (1470)') df.zoomToSelectedFeatures() #Turn on visibility for each theme and export the page lyrList = ['soilmu_a_ny067', 'hydric_percent_a_ny067', 'soilsf_p_ny067'] for lyrName in lyrList: lyr = arcpy.mapping.ListLayers(mxd, lyrName, df) lyr.visible = True #Export each theme to a temporary PDF and append to the final PDF tmpPdf = outPath + lyrName + '_temp.pdf' if os.path.exists(tmpPdf): os.remove(tmpPdf) arcpy.mapping.ExportToPDF(mxd, tmpPdf) finalPdf.appendPages(tmpPdf) #Turn off layer visibility and clean up for next pass through the loop lyr.visible = False del lyr, tmpPdf del mxd, df, finalPdf