Solved! Go to Solution.
import arcpy fc = r"C:\Temp\Test.gdb\SrcR" field = "NAME" # Field of interest values = [row[0] for row in arcpy.da.SearchCursor(fc, (field))] uniqueValues = sorted(set(values)) mxd = arcpy.mapping.MapDocument(r"C:\Temp\defQuery.mxd") for value in uniqueValues: queryStr = "\"" + field + "\" = '" + str(value) + "'" df = arcpy.mapping.ListDataFrames(mxd, "Regional")[0] for lyr in arcpy.mapping.ListLayers(mxd, "", df): if lyr.name == "SrcR": lyr.definitionQuery = queryStr arcpy.mapping.ExportToPDF(mxd, r"C:\Temp" + "\\" + value + ".pdf") # Output individual PDF pages del mxd
import arcpy fc = r"D:\test.gdb\srcR" # FC with field of interest field = "Abbr" # Field of interest values = [row[0] for row in arcpy.da.SearchCursor(fc, (field))] uniqueValues = sorted(set(values)) i = iter(uniqueValues) value = i.next() for value in uniqueValues: queryStr = 'str(field)' + "=" + 'str(value)' mxd = arcpy.mapping.MapDocument(r"D:\test.mxd") # MXD to analyse df = arcpy.mapping.ListDataFrames(mxd, "Regional")[0] for lyr in arcpy.mapping.ListLayers(mxd, "Regional", df)[0]: if lyr.name == r"D:\test.gdb\srcR" or lyr.name == r"D:\test.gdb\srcM" or lyr.name == r"D:\test.gdb\srcC": # Three FC with common field that definition query wll apply to lyr.definitionQuery = queryStr arcpy.RefreshActiveView() arcpy.mapping.ExportToPDF(mxd, r"D:\Temp\value.pdf") # Output individual PDF pages value = i.next() del mxd
import arcpy fc = r"C:\Temp\Test.gdb\SrcR" field = "NAME" # Field of interest values = [row[0] for row in arcpy.da.SearchCursor(fc, (field))] uniqueValues = sorted(set(values)) mxd = arcpy.mapping.MapDocument(r"C:\Temp\defQuery.mxd") for value in uniqueValues: queryStr = "\"" + field + "\" = '" + str(value) + "'" df = arcpy.mapping.ListDataFrames(mxd, "Regional")[0] for lyr in arcpy.mapping.ListLayers(mxd, "", df): if lyr.name == "SrcR": lyr.definitionQuery = queryStr arcpy.mapping.ExportToPDF(mxd, r"C:\Temp" + "\\" + value + ".pdf") # Output individual PDF pages del mxd
arcpy.mapping.ExportToPDF(mxd, r"C:\Temp" + "\\" + value + ".pdf", layers_attributes="LAYERS_AND_ATTRIBUTES")