In the following script, it outputs the maps correctly but the legend keeps repeating itself between the first few county legends? I've attached an example for Sulfate by town-range and you can see the legend shows Arsenic by county.
# Make Web Display Current Map Set
# make sure only WI_Counties layer on
import sys
import arcpy
import os
import arcpy.mp as Map
# set these control parameters for the map production:
xDate = "January - 2025" # current data set being displayed (above legend on layout)
xPrint = "no" # "yes"/"no" for print control
xFormat = "pdf" # can be either pdf or png; reset the map document to a borderless png version if appropriate
xRes = 300
pdfBook = "Viewer_MapBook_January_2025" #enter name of mapbook; disabled when format set to png
xDir=r"C:\Projects\Well Water Quality Viewer\make_web\Display_Maps" #dir for the output files
aprxFile=r"C:\Projects\Well Water Quality Viewer\make_web\Display_Maps\Display_Maps\Display_Maps.aprx" #mxd document
# set maps to a list of desired maps (in the order requested for mapbook)
maps = ['Alkalinity-Co','Arsenic-Co','Arsenic-Max-Co','Atrazine Family-Co','Bacteria-Co','Chloride-Co',
'Conductivity-Co','Copper-Co','Iron-Co','Lead-Co','Manganese-Co','Nitrate-Co','Nitrate Exceedence-Co',
'pH-Co','Saturation Index-Co','Sulfate-Co','Total Hardness-Co',
'Alkalinity-TR','Arsenic-TR','Arsenic-Max-TR','Atrazine Family-TR','Bacteria-TR','Chloride-TR',
'Conductivity-TR','Copper-TR','Iron-TR','Lead-TR','Manganese-TR','Nitrate-TR','Nitrate Exceedence-TR',
'pH-TR','Saturation Index-TR','Sulfate-TR','Total Hardness-TR',
'Alkalinity-S','Arsenic-S','Arsenic-Max-S','Atrazine Family-S','Bacteria-S','Chloride-S',
'Conductivity-S','Copper-S','Iron-S','Lead-S','Manganese-S','Nitrate-S','Nitrate Exceedence-S',
'pH-S','Saturation Index-S','Sulfate-S','Total Hardness-S']
# ---------------------------------------------------------------
arcpy.env.overwriteOutput = True
aprx = Map.ArcGISProject(aprxFile)
layout = aprx.listLayouts('PW_WEB_MAPPER')[0]
ms = layout.mapSeries
noteSet = layout.listElements("TEXT_ELEMENT", "Data_Set")[0]
noteSet.text = xDate
legendList = aprx.listMaps("Layers")[0]
dfList = aprx.listMaps("Layers")[0]
if xFormat != "pdf":
xPrint = "no"
if xPrint == "no":
mapPrint = "N"
else:
mapPrint = "P"
if xFormat != "pdf":
pdfBook = "no"
if pdfBook != "no":
pdfDoc = Map.PDFDocumentCreate(os.path.join(xDir, pdfBook)+".pdf")
#main loop
for xmap in maps:
curLayer = dfList.listLayers(xmap)[0]
#curLegend = legendList.listLayers(xmap)[0]
curLayer.visible = True
#curLegend.visible = True
Xport = os.path.join(xDir, xmap)
if xFormat == "pdf":
layout.exportToPDF(Xport,resolution=xRes)
if pdfBook != "no":
pdfDoc.appendPages(Xport+".pdf")
else:
layout.exportToPNG(Xport,resolution=xRes)
if mapPrint == "P":
Map.PrintMap(aprx)
print ("Exported: ", xmap)
curLayer.visible = False
curLegend.visible = False
if pdfBook != "no":
pdfDoc.saveAndClose()
del pdfDoc
del aprx
print ("Script Complete")
Hello, I can't identify the issue from the picture that is attached. What is "repeating itself"?
Jeff - arcpy.mp team