<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Iterate through selected attributes and export toggled layer maps in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/iterate-through-selected-attributes-and-export/m-p/1088630#M62077</link>
    <description>&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to make about 17 to 20 maps for a given location ranging from soils, topographic, wetlands, etc. I have to make these maps for about 145 different locations. So in total i will be making&amp;nbsp; about 2500 maps.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have worked extensively with data driven pages and find it works great when the location varies but the layer stays the same, e.g. the wetland layer maps for all fields. I think of this as horizontal results.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also made a scrip that will output all the maps for a give location. It will create the soil, topographic, wetland, and otherwise maps for a given location. I think of this as vertical results.&amp;nbsp;&lt;/P&gt;&lt;P&gt;import arcpy, os&lt;BR /&gt;&lt;BR /&gt;# Specify output path and final output PDF&lt;BR /&gt;outPath = r'C:\Outputs\TEST'&lt;BR /&gt;pdfPath = os.path.join(outPath, '1. WetlandSupportdocs.pdf')&lt;BR /&gt;if os.path.exists(pdfPath):&lt;BR /&gt;os.remove(pdfPath)&lt;BR /&gt;finalPdf = arcpy.mapping.PDFDocumentCreate(pdfPath)&lt;/P&gt;&lt;P&gt;# Specify the map document and the data frame&lt;BR /&gt;mxd = arcpy.mapping.MapDocument(r'C:\Geodata\Template.mxd')&lt;BR /&gt;df = arcpy.mapping.ListDataFrames(mxd, 'Layers')[0]&lt;BR /&gt;&lt;BR /&gt;#################### ASSIGN VARIABLES ###########################&lt;BR /&gt;#################################################################&lt;BR /&gt;#################################################################&lt;BR /&gt;#################################################################&lt;/P&gt;&lt;P&gt;Farm = ("2222")&lt;BR /&gt;Tract = ("1111")&lt;BR /&gt;CLU = ("1")&lt;BR /&gt;District = ("District")&lt;BR /&gt;County = ("Wyoming")&lt;BR /&gt;AssistedBy = ("Bob Conservationsit")&lt;BR /&gt;FieldOffice = ("Hamilton")&lt;BR /&gt;Customer = ("Joe Landowner")&lt;/P&gt;&lt;P&gt;#################################################################&lt;BR /&gt;#################################################################&lt;BR /&gt;#################################################################&lt;BR /&gt;#################################################################&lt;/P&gt;&lt;P&gt;LandUnits = ('Farm ' +str(Farm) + ',' + 'Tract ' +str(Tract))&lt;/P&gt;&lt;P&gt;#Change County text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","District")[0]&lt;BR /&gt;TextElement.text = District&lt;/P&gt;&lt;P&gt;#Change County text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","County")[0]&lt;BR /&gt;TextElement.text = County&lt;BR /&gt;&lt;BR /&gt;#Change AssistedBy text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","AssistedBy")[0]&lt;BR /&gt;TextElement.text = AssistedBy&lt;BR /&gt;&lt;BR /&gt;#Change Field Office text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","FieldOffice")[0]&lt;BR /&gt;TextElement.text = FieldOffice&lt;/P&gt;&lt;P&gt;#Change Customer name&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","CustomerName")[0]&lt;BR /&gt;TextElement.text = Customer&lt;/P&gt;&lt;P&gt;#Change Landunits&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","LandUnits")[0]&lt;BR /&gt;TextElement.text = LandUnits&lt;BR /&gt;&lt;BR /&gt;# Select a tract using the TRACNBR attribute and zoom to selected&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, 'clu_a_053', df)[0]&lt;BR /&gt;if CLU == "":&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", 'TRACTNBR IN ({0}) '.format(Tract))&lt;BR /&gt;df.zoomToSelectedFeatures()&lt;BR /&gt;lyr.definitionQuery = 'TRACTNBR IN ({0})'.format(Tract)&lt;BR /&gt;else:&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", 'TRACTNBR IN ({0}) AND CLUNBR IN ({1})'.format(Tract, CLU))&lt;BR /&gt;df.zoomToSelectedFeatures()&lt;BR /&gt;lyr.definitionQuery = 'TRACTNBR IN ({0})AND CLUNBR IN ({1})'.format(Tract, CLU)&lt;BR /&gt;df.zoomToSelectedFeatures()&lt;/P&gt;&lt;P&gt;arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")&lt;BR /&gt;arcpy.RefreshActiveView()&lt;/P&gt;&lt;P&gt;# Turn on visibility for each theme and export the page&lt;BR /&gt;lyrList = ['FSA Wetspots','National Wetlands Inventory','NYSDEC Wetlands','Madison County Soils','Soil Special Features','Percent Hydric Soils','Highly Erodible Land','Madison 2ft Contours','Topographic Image','DEC Unconsolidated Aquifers of NY State','EPA NYS sole source aquifers','USGS Potential Carbonate Karst Topography ','Surficial Geology','NYS Bedrock Geology ','NYS EcoRegion','NYS Important Bird Areas','Northern Long Eared Bat Location Data' ]&lt;/P&gt;&lt;P&gt;# Don't assume the layers are turned off...Turn them off first.&lt;BR /&gt;print("First, turn off all the layers")&lt;BR /&gt;for lyrName in lyrList:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;print("\tSet layer-visibility for '" + lyr.name + "' to " + str(lyr.visible))&lt;/P&gt;&lt;P&gt;print("Second, export to PDF")&lt;BR /&gt;for lyrName in lyrList:&lt;BR /&gt;print("---")&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = True&lt;BR /&gt;print("\tSet layer-visibility for '" + lyr.name + "' to " + str(lyr.visible))&lt;/P&gt;&lt;P&gt;#Change title text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]&lt;BR /&gt;TextElement.text = lyrName&lt;/P&gt;&lt;P&gt;#Change Landowner name&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","CustomerName")[0]&lt;BR /&gt;TextElement.text = 'Holmes-Acre LLC'&lt;/P&gt;&lt;P&gt;#Change Landunits&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","FarmTractNbr")[0]&lt;BR /&gt;TextElement.text = 'Farm NUB Tract 2215'&lt;BR /&gt;&lt;BR /&gt;#Export each theme to a temporary PDF and append to the final PDF&lt;BR /&gt;tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')&lt;BR /&gt;if os.path.exists(tmpPdf):&lt;BR /&gt;os.remove(tmpPdf)&lt;BR /&gt;arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;BR /&gt;print("\tPDF Exported to following path: " + tmpPdf)&lt;BR /&gt;finalPdf.appendPages(tmpPdf)&lt;BR /&gt;&lt;BR /&gt;#Turn off layer visibility and clean up for next pass through the loop&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;print("\tSet layer-visibility for '" + lyr.name + "' to " + str(lyr.visible))&lt;/P&gt;&lt;P&gt;################################### Wetland Data #################################################&lt;/P&gt;&lt;P&gt;# Turn on visibility for each theme and export the page&lt;BR /&gt;lyrListWET = ['National Wetlands Inventory','NYSDEC Wetlands']&lt;/P&gt;&lt;P&gt;# Don't assume the layers are turned off...Turn them off first.&lt;BR /&gt;print("First, turn on all the layers")&lt;/P&gt;&lt;P&gt;for lyrName in lyrListWET:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = True&lt;BR /&gt;&lt;BR /&gt;#Change title text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]&lt;BR /&gt;TextElement.text = "Wetlands"&lt;BR /&gt;&lt;BR /&gt;#Export each theme to a temporary PDF and append to the final PDF&lt;BR /&gt;tmpPdf = os.path.join(outPath, "Wetlands" + '_temp.pdf')&lt;BR /&gt;if os.path.exists(tmpPdf):&lt;BR /&gt;os.remove(tmpPdf)&lt;BR /&gt;arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;BR /&gt;print("\tPDF Exported to following path: " + tmpPdf)&lt;BR /&gt;finalPdf.appendPages(tmpPdf)&lt;BR /&gt;&lt;BR /&gt;#Turn off layer visibility and clean up for next pass through the loop&lt;BR /&gt;for lyrName in lyrListWET:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;del lyr&lt;BR /&gt;&lt;BR /&gt;################################### CIR Data #################################################&lt;/P&gt;&lt;P&gt;# Turn on visibility for each theme and export the page&lt;BR /&gt;lyrListCIR = ['CIR_doqq_flight_dates','Infrared Ortho Imagery']&lt;/P&gt;&lt;P&gt;# Don't assume the layers are turned off...Turn them off first.&lt;BR /&gt;print("First, turn on all the layers")&lt;/P&gt;&lt;P&gt;for lyrName in lyrListCIR:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = True&lt;BR /&gt;&lt;BR /&gt;#Change title text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]&lt;BR /&gt;TextElement.text = lyrName&lt;BR /&gt;&lt;BR /&gt;#Export each theme to a temporary PDF and append to the final PDF&lt;BR /&gt;tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')&lt;BR /&gt;if os.path.exists(tmpPdf):&lt;BR /&gt;os.remove(tmpPdf)&lt;BR /&gt;arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;BR /&gt;print("\tPDF Exported to following path: " + tmpPdf)&lt;BR /&gt;finalPdf.appendPages(tmpPdf)&lt;BR /&gt;&lt;BR /&gt;#Turn off layer visibility and clean up for next pass through the loop&lt;BR /&gt;for lyrName in lyrListCIR:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;del lyr&lt;/P&gt;&lt;P&gt;################################### 2008 Data ##############################################&lt;/P&gt;&lt;P&gt;# Turn on visibility for each theme and export the page&lt;BR /&gt;lyrList2008 = ['ortho_1-1_1n_ny053_2008_1','2008 Ortho Imagery']&lt;/P&gt;&lt;P&gt;# Don't assume the layers are turned off...Turn them off first.&lt;BR /&gt;print("2008 data")&lt;/P&gt;&lt;P&gt;for lyrName in lyrList2008:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = True&lt;BR /&gt;&lt;BR /&gt;#Change title text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]&lt;BR /&gt;TextElement.text = lyrName&lt;/P&gt;&lt;P&gt;#Export each theme to a temporary PDF and append to the final PDF&lt;BR /&gt;tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')&lt;BR /&gt;if os.path.exists(tmpPdf):&lt;BR /&gt;os.remove(tmpPdf)&lt;BR /&gt;arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;BR /&gt;print("\tPDF Exported to following path: " + lyr.name + tmpPdf)&lt;BR /&gt;finalPdf.appendPages(tmpPdf)&lt;BR /&gt;&lt;BR /&gt;#Turn off layer visibility and clean up for next pass through the loop&lt;BR /&gt;for lyrName in lyrList2008:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;del lyr&lt;/P&gt;&lt;P&gt;################################### 2009 Data ##############################################&lt;/P&gt;&lt;P&gt;# Turn on visibility for each theme and export the page&lt;BR /&gt;lyrList2009 = ['ortho_1-1_1n_ny053_2009_1','2009 Ortho Imagery']&lt;/P&gt;&lt;P&gt;# Don't assume the layers are turned off...Turn them off first.&lt;BR /&gt;print("2009 data")&lt;/P&gt;&lt;P&gt;for lyrName in lyrList2009:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = True&lt;BR /&gt;&lt;BR /&gt;#Change title text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]&lt;BR /&gt;TextElement.text = lyrName&lt;/P&gt;&lt;P&gt;#Export each theme to a temporary PDF and append to the final PDF&lt;BR /&gt;tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')&lt;BR /&gt;if os.path.exists(tmpPdf):&lt;BR /&gt;os.remove(tmpPdf)&lt;BR /&gt;arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;BR /&gt;print("\tPDF Exported to following path: " + lyr.name + tmpPdf)&lt;BR /&gt;finalPdf.appendPages(tmpPdf)&lt;BR /&gt;&lt;BR /&gt;#Turn off layer visibility and clean up for next pass through the loop&lt;BR /&gt;for lyrName in lyrList2009:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;del lyr&lt;/P&gt;&lt;P&gt;################################### 2011 Data ##############################################&lt;/P&gt;&lt;P&gt;# Turn on visibility for each theme and export the page&lt;BR /&gt;lyrList2011 = ['ortho_1-1_1n_ny053_2011_1','2011 Ortho Imagery']&lt;/P&gt;&lt;P&gt;# Don't assume the layers are turned off...Turn them off first.&lt;BR /&gt;print("2011 Data")&lt;/P&gt;&lt;P&gt;for lyrName in lyrList2011:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = True&lt;BR /&gt;&lt;BR /&gt;#Change title text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]&lt;BR /&gt;TextElement.text = lyrName&lt;/P&gt;&lt;P&gt;#Export each theme to a temporary PDF and append to the final PDF&lt;BR /&gt;tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')&lt;BR /&gt;if os.path.exists(tmpPdf):&lt;BR /&gt;os.remove(tmpPdf)&lt;BR /&gt;arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;BR /&gt;print("\tPDF Exported to following path: " + lyr.name + tmpPdf)&lt;BR /&gt;finalPdf.appendPages(tmpPdf)&lt;BR /&gt;&lt;BR /&gt;#Turn off layer visibility and clean up for next pass through the loop&lt;BR /&gt;for lyrName in lyrList2011:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;del lyr&lt;BR /&gt;&lt;BR /&gt;################################### 2013 Data ##############################################&lt;/P&gt;&lt;P&gt;# Turn on visibility for each theme and export the page&lt;BR /&gt;lyrList2013 = ['ortho_1-1_1n_s_ny053_2013_1','2013 Ortho Imagery']&lt;/P&gt;&lt;P&gt;# Don't assume the layers are turned off...Turn them off first.&lt;BR /&gt;print("2013 data")&lt;/P&gt;&lt;P&gt;for lyrName in lyrList2013:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = True&lt;/P&gt;&lt;P&gt;#Change title text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]&lt;BR /&gt;TextElement.text = lyrName&lt;/P&gt;&lt;P&gt;#Export each theme to a temporary PDF and append to the final PDF&lt;BR /&gt;tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')&lt;BR /&gt;if os.path.exists(tmpPdf):&lt;BR /&gt;os.remove(tmpPdf)&lt;BR /&gt;arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;BR /&gt;print("\tPDF Exported to following path: " + lyr.name + tmpPdf)&lt;BR /&gt;finalPdf.appendPages(tmpPdf)&lt;BR /&gt;&lt;BR /&gt;#Turn off layer visibility and clean up for next pass through the loop&lt;BR /&gt;for lyrName in lyrList2013:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;del lyr&lt;/P&gt;&lt;P&gt;################################### 2015 Data ##############################################&lt;/P&gt;&lt;P&gt;# Turn on visibility for each theme and export the page&lt;BR /&gt;lyrList2015 = ['ortho_1-1_hn_s_ny053_2015_1','2015 Ortho Imagery']&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# Don't assume the layers are turned off...Turn them off first.&lt;BR /&gt;print("2015 data")&lt;/P&gt;&lt;P&gt;for lyrName in lyrList2015:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = True&lt;BR /&gt;&lt;BR /&gt;#Change title text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]&lt;BR /&gt;TextElement.text = lyrName&lt;/P&gt;&lt;P&gt;#Export each theme to a temporary PDF and append to the final PDF&lt;BR /&gt;tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')&lt;BR /&gt;if os.path.exists(tmpPdf):&lt;BR /&gt;os.remove(tmpPdf)&lt;BR /&gt;arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;BR /&gt;print("\tPDF Exported to following path: " + lyr.name + tmpPdf)&lt;BR /&gt;finalPdf.appendPages(tmpPdf)&lt;BR /&gt;&lt;BR /&gt;#Turn off layer visibility and clean up for next pass through the loop&lt;BR /&gt;for lyrName in lyrList2015:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;del lyr&lt;/P&gt;&lt;P&gt;################################### 2019 Data ##############################################&lt;/P&gt;&lt;P&gt;# Turn on visibility for each theme and export the page&lt;BR /&gt;lyrList2019 = ['NAIP2019_otho_flight_lines_a_NY','2019 Ortho Imagery']&lt;/P&gt;&lt;P&gt;# Don't assume the layers are turned off...Turn them off first.&lt;BR /&gt;print("2019 data")&lt;/P&gt;&lt;P&gt;for lyrName in lyrList2019:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = True&lt;BR /&gt;&lt;BR /&gt;#Change title text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]&lt;BR /&gt;TextElement.text = lyrName&lt;/P&gt;&lt;P&gt;#Export each theme to a temporary PDF and append to the final PDF&lt;BR /&gt;tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')&lt;BR /&gt;if os.path.exists(tmpPdf):&lt;BR /&gt;os.remove(tmpPdf)&lt;BR /&gt;arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;BR /&gt;print("\tPDF Exported to following path: " + lyr.name + tmpPdf)&lt;BR /&gt;finalPdf.appendPages(tmpPdf)&lt;BR /&gt;&lt;BR /&gt;#Turn off layer visibility and clean up for next pass through the loop&lt;BR /&gt;for lyrName in lyrList2019:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;del lyr&lt;/P&gt;&lt;P&gt;finalPdf.saveAndClose()&lt;BR /&gt;del mxd, df, finalPdf&lt;/P&gt;&lt;P&gt;Is there anyway to intergrate both a vertical and horizonal result? Selecting the tracts i need maps for and iterating through making maps for each selected tract?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 12 Aug 2021 20:24:47 GMT</pubDate>
    <dc:creator>EvanSweeney</dc:creator>
    <dc:date>2021-08-12T20:24:47Z</dc:date>
    <item>
      <title>Iterate through selected attributes and export toggled layer maps</title>
      <link>https://community.esri.com/t5/python-questions/iterate-through-selected-attributes-and-export/m-p/1088630#M62077</link>
      <description>&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to make about 17 to 20 maps for a given location ranging from soils, topographic, wetlands, etc. I have to make these maps for about 145 different locations. So in total i will be making&amp;nbsp; about 2500 maps.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have worked extensively with data driven pages and find it works great when the location varies but the layer stays the same, e.g. the wetland layer maps for all fields. I think of this as horizontal results.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also made a scrip that will output all the maps for a give location. It will create the soil, topographic, wetland, and otherwise maps for a given location. I think of this as vertical results.&amp;nbsp;&lt;/P&gt;&lt;P&gt;import arcpy, os&lt;BR /&gt;&lt;BR /&gt;# Specify output path and final output PDF&lt;BR /&gt;outPath = r'C:\Outputs\TEST'&lt;BR /&gt;pdfPath = os.path.join(outPath, '1. WetlandSupportdocs.pdf')&lt;BR /&gt;if os.path.exists(pdfPath):&lt;BR /&gt;os.remove(pdfPath)&lt;BR /&gt;finalPdf = arcpy.mapping.PDFDocumentCreate(pdfPath)&lt;/P&gt;&lt;P&gt;# Specify the map document and the data frame&lt;BR /&gt;mxd = arcpy.mapping.MapDocument(r'C:\Geodata\Template.mxd')&lt;BR /&gt;df = arcpy.mapping.ListDataFrames(mxd, 'Layers')[0]&lt;BR /&gt;&lt;BR /&gt;#################### ASSIGN VARIABLES ###########################&lt;BR /&gt;#################################################################&lt;BR /&gt;#################################################################&lt;BR /&gt;#################################################################&lt;/P&gt;&lt;P&gt;Farm = ("2222")&lt;BR /&gt;Tract = ("1111")&lt;BR /&gt;CLU = ("1")&lt;BR /&gt;District = ("District")&lt;BR /&gt;County = ("Wyoming")&lt;BR /&gt;AssistedBy = ("Bob Conservationsit")&lt;BR /&gt;FieldOffice = ("Hamilton")&lt;BR /&gt;Customer = ("Joe Landowner")&lt;/P&gt;&lt;P&gt;#################################################################&lt;BR /&gt;#################################################################&lt;BR /&gt;#################################################################&lt;BR /&gt;#################################################################&lt;/P&gt;&lt;P&gt;LandUnits = ('Farm ' +str(Farm) + ',' + 'Tract ' +str(Tract))&lt;/P&gt;&lt;P&gt;#Change County text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","District")[0]&lt;BR /&gt;TextElement.text = District&lt;/P&gt;&lt;P&gt;#Change County text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","County")[0]&lt;BR /&gt;TextElement.text = County&lt;BR /&gt;&lt;BR /&gt;#Change AssistedBy text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","AssistedBy")[0]&lt;BR /&gt;TextElement.text = AssistedBy&lt;BR /&gt;&lt;BR /&gt;#Change Field Office text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","FieldOffice")[0]&lt;BR /&gt;TextElement.text = FieldOffice&lt;/P&gt;&lt;P&gt;#Change Customer name&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","CustomerName")[0]&lt;BR /&gt;TextElement.text = Customer&lt;/P&gt;&lt;P&gt;#Change Landunits&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","LandUnits")[0]&lt;BR /&gt;TextElement.text = LandUnits&lt;BR /&gt;&lt;BR /&gt;# Select a tract using the TRACNBR attribute and zoom to selected&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, 'clu_a_053', df)[0]&lt;BR /&gt;if CLU == "":&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", 'TRACTNBR IN ({0}) '.format(Tract))&lt;BR /&gt;df.zoomToSelectedFeatures()&lt;BR /&gt;lyr.definitionQuery = 'TRACTNBR IN ({0})'.format(Tract)&lt;BR /&gt;else:&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", 'TRACTNBR IN ({0}) AND CLUNBR IN ({1})'.format(Tract, CLU))&lt;BR /&gt;df.zoomToSelectedFeatures()&lt;BR /&gt;lyr.definitionQuery = 'TRACTNBR IN ({0})AND CLUNBR IN ({1})'.format(Tract, CLU)&lt;BR /&gt;df.zoomToSelectedFeatures()&lt;/P&gt;&lt;P&gt;arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")&lt;BR /&gt;arcpy.RefreshActiveView()&lt;/P&gt;&lt;P&gt;# Turn on visibility for each theme and export the page&lt;BR /&gt;lyrList = ['FSA Wetspots','National Wetlands Inventory','NYSDEC Wetlands','Madison County Soils','Soil Special Features','Percent Hydric Soils','Highly Erodible Land','Madison 2ft Contours','Topographic Image','DEC Unconsolidated Aquifers of NY State','EPA NYS sole source aquifers','USGS Potential Carbonate Karst Topography ','Surficial Geology','NYS Bedrock Geology ','NYS EcoRegion','NYS Important Bird Areas','Northern Long Eared Bat Location Data' ]&lt;/P&gt;&lt;P&gt;# Don't assume the layers are turned off...Turn them off first.&lt;BR /&gt;print("First, turn off all the layers")&lt;BR /&gt;for lyrName in lyrList:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;print("\tSet layer-visibility for '" + lyr.name + "' to " + str(lyr.visible))&lt;/P&gt;&lt;P&gt;print("Second, export to PDF")&lt;BR /&gt;for lyrName in lyrList:&lt;BR /&gt;print("---")&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = True&lt;BR /&gt;print("\tSet layer-visibility for '" + lyr.name + "' to " + str(lyr.visible))&lt;/P&gt;&lt;P&gt;#Change title text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]&lt;BR /&gt;TextElement.text = lyrName&lt;/P&gt;&lt;P&gt;#Change Landowner name&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","CustomerName")[0]&lt;BR /&gt;TextElement.text = 'Holmes-Acre LLC'&lt;/P&gt;&lt;P&gt;#Change Landunits&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","FarmTractNbr")[0]&lt;BR /&gt;TextElement.text = 'Farm NUB Tract 2215'&lt;BR /&gt;&lt;BR /&gt;#Export each theme to a temporary PDF and append to the final PDF&lt;BR /&gt;tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')&lt;BR /&gt;if os.path.exists(tmpPdf):&lt;BR /&gt;os.remove(tmpPdf)&lt;BR /&gt;arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;BR /&gt;print("\tPDF Exported to following path: " + tmpPdf)&lt;BR /&gt;finalPdf.appendPages(tmpPdf)&lt;BR /&gt;&lt;BR /&gt;#Turn off layer visibility and clean up for next pass through the loop&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;print("\tSet layer-visibility for '" + lyr.name + "' to " + str(lyr.visible))&lt;/P&gt;&lt;P&gt;################################### Wetland Data #################################################&lt;/P&gt;&lt;P&gt;# Turn on visibility for each theme and export the page&lt;BR /&gt;lyrListWET = ['National Wetlands Inventory','NYSDEC Wetlands']&lt;/P&gt;&lt;P&gt;# Don't assume the layers are turned off...Turn them off first.&lt;BR /&gt;print("First, turn on all the layers")&lt;/P&gt;&lt;P&gt;for lyrName in lyrListWET:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = True&lt;BR /&gt;&lt;BR /&gt;#Change title text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]&lt;BR /&gt;TextElement.text = "Wetlands"&lt;BR /&gt;&lt;BR /&gt;#Export each theme to a temporary PDF and append to the final PDF&lt;BR /&gt;tmpPdf = os.path.join(outPath, "Wetlands" + '_temp.pdf')&lt;BR /&gt;if os.path.exists(tmpPdf):&lt;BR /&gt;os.remove(tmpPdf)&lt;BR /&gt;arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;BR /&gt;print("\tPDF Exported to following path: " + tmpPdf)&lt;BR /&gt;finalPdf.appendPages(tmpPdf)&lt;BR /&gt;&lt;BR /&gt;#Turn off layer visibility and clean up for next pass through the loop&lt;BR /&gt;for lyrName in lyrListWET:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;del lyr&lt;BR /&gt;&lt;BR /&gt;################################### CIR Data #################################################&lt;/P&gt;&lt;P&gt;# Turn on visibility for each theme and export the page&lt;BR /&gt;lyrListCIR = ['CIR_doqq_flight_dates','Infrared Ortho Imagery']&lt;/P&gt;&lt;P&gt;# Don't assume the layers are turned off...Turn them off first.&lt;BR /&gt;print("First, turn on all the layers")&lt;/P&gt;&lt;P&gt;for lyrName in lyrListCIR:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = True&lt;BR /&gt;&lt;BR /&gt;#Change title text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]&lt;BR /&gt;TextElement.text = lyrName&lt;BR /&gt;&lt;BR /&gt;#Export each theme to a temporary PDF and append to the final PDF&lt;BR /&gt;tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')&lt;BR /&gt;if os.path.exists(tmpPdf):&lt;BR /&gt;os.remove(tmpPdf)&lt;BR /&gt;arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;BR /&gt;print("\tPDF Exported to following path: " + tmpPdf)&lt;BR /&gt;finalPdf.appendPages(tmpPdf)&lt;BR /&gt;&lt;BR /&gt;#Turn off layer visibility and clean up for next pass through the loop&lt;BR /&gt;for lyrName in lyrListCIR:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;del lyr&lt;/P&gt;&lt;P&gt;################################### 2008 Data ##############################################&lt;/P&gt;&lt;P&gt;# Turn on visibility for each theme and export the page&lt;BR /&gt;lyrList2008 = ['ortho_1-1_1n_ny053_2008_1','2008 Ortho Imagery']&lt;/P&gt;&lt;P&gt;# Don't assume the layers are turned off...Turn them off first.&lt;BR /&gt;print("2008 data")&lt;/P&gt;&lt;P&gt;for lyrName in lyrList2008:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = True&lt;BR /&gt;&lt;BR /&gt;#Change title text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]&lt;BR /&gt;TextElement.text = lyrName&lt;/P&gt;&lt;P&gt;#Export each theme to a temporary PDF and append to the final PDF&lt;BR /&gt;tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')&lt;BR /&gt;if os.path.exists(tmpPdf):&lt;BR /&gt;os.remove(tmpPdf)&lt;BR /&gt;arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;BR /&gt;print("\tPDF Exported to following path: " + lyr.name + tmpPdf)&lt;BR /&gt;finalPdf.appendPages(tmpPdf)&lt;BR /&gt;&lt;BR /&gt;#Turn off layer visibility and clean up for next pass through the loop&lt;BR /&gt;for lyrName in lyrList2008:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;del lyr&lt;/P&gt;&lt;P&gt;################################### 2009 Data ##############################################&lt;/P&gt;&lt;P&gt;# Turn on visibility for each theme and export the page&lt;BR /&gt;lyrList2009 = ['ortho_1-1_1n_ny053_2009_1','2009 Ortho Imagery']&lt;/P&gt;&lt;P&gt;# Don't assume the layers are turned off...Turn them off first.&lt;BR /&gt;print("2009 data")&lt;/P&gt;&lt;P&gt;for lyrName in lyrList2009:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = True&lt;BR /&gt;&lt;BR /&gt;#Change title text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]&lt;BR /&gt;TextElement.text = lyrName&lt;/P&gt;&lt;P&gt;#Export each theme to a temporary PDF and append to the final PDF&lt;BR /&gt;tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')&lt;BR /&gt;if os.path.exists(tmpPdf):&lt;BR /&gt;os.remove(tmpPdf)&lt;BR /&gt;arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;BR /&gt;print("\tPDF Exported to following path: " + lyr.name + tmpPdf)&lt;BR /&gt;finalPdf.appendPages(tmpPdf)&lt;BR /&gt;&lt;BR /&gt;#Turn off layer visibility and clean up for next pass through the loop&lt;BR /&gt;for lyrName in lyrList2009:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;del lyr&lt;/P&gt;&lt;P&gt;################################### 2011 Data ##############################################&lt;/P&gt;&lt;P&gt;# Turn on visibility for each theme and export the page&lt;BR /&gt;lyrList2011 = ['ortho_1-1_1n_ny053_2011_1','2011 Ortho Imagery']&lt;/P&gt;&lt;P&gt;# Don't assume the layers are turned off...Turn them off first.&lt;BR /&gt;print("2011 Data")&lt;/P&gt;&lt;P&gt;for lyrName in lyrList2011:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = True&lt;BR /&gt;&lt;BR /&gt;#Change title text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]&lt;BR /&gt;TextElement.text = lyrName&lt;/P&gt;&lt;P&gt;#Export each theme to a temporary PDF and append to the final PDF&lt;BR /&gt;tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')&lt;BR /&gt;if os.path.exists(tmpPdf):&lt;BR /&gt;os.remove(tmpPdf)&lt;BR /&gt;arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;BR /&gt;print("\tPDF Exported to following path: " + lyr.name + tmpPdf)&lt;BR /&gt;finalPdf.appendPages(tmpPdf)&lt;BR /&gt;&lt;BR /&gt;#Turn off layer visibility and clean up for next pass through the loop&lt;BR /&gt;for lyrName in lyrList2011:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;del lyr&lt;BR /&gt;&lt;BR /&gt;################################### 2013 Data ##############################################&lt;/P&gt;&lt;P&gt;# Turn on visibility for each theme and export the page&lt;BR /&gt;lyrList2013 = ['ortho_1-1_1n_s_ny053_2013_1','2013 Ortho Imagery']&lt;/P&gt;&lt;P&gt;# Don't assume the layers are turned off...Turn them off first.&lt;BR /&gt;print("2013 data")&lt;/P&gt;&lt;P&gt;for lyrName in lyrList2013:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = True&lt;/P&gt;&lt;P&gt;#Change title text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]&lt;BR /&gt;TextElement.text = lyrName&lt;/P&gt;&lt;P&gt;#Export each theme to a temporary PDF and append to the final PDF&lt;BR /&gt;tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')&lt;BR /&gt;if os.path.exists(tmpPdf):&lt;BR /&gt;os.remove(tmpPdf)&lt;BR /&gt;arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;BR /&gt;print("\tPDF Exported to following path: " + lyr.name + tmpPdf)&lt;BR /&gt;finalPdf.appendPages(tmpPdf)&lt;BR /&gt;&lt;BR /&gt;#Turn off layer visibility and clean up for next pass through the loop&lt;BR /&gt;for lyrName in lyrList2013:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;del lyr&lt;/P&gt;&lt;P&gt;################################### 2015 Data ##############################################&lt;/P&gt;&lt;P&gt;# Turn on visibility for each theme and export the page&lt;BR /&gt;lyrList2015 = ['ortho_1-1_hn_s_ny053_2015_1','2015 Ortho Imagery']&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# Don't assume the layers are turned off...Turn them off first.&lt;BR /&gt;print("2015 data")&lt;/P&gt;&lt;P&gt;for lyrName in lyrList2015:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = True&lt;BR /&gt;&lt;BR /&gt;#Change title text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]&lt;BR /&gt;TextElement.text = lyrName&lt;/P&gt;&lt;P&gt;#Export each theme to a temporary PDF and append to the final PDF&lt;BR /&gt;tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')&lt;BR /&gt;if os.path.exists(tmpPdf):&lt;BR /&gt;os.remove(tmpPdf)&lt;BR /&gt;arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;BR /&gt;print("\tPDF Exported to following path: " + lyr.name + tmpPdf)&lt;BR /&gt;finalPdf.appendPages(tmpPdf)&lt;BR /&gt;&lt;BR /&gt;#Turn off layer visibility and clean up for next pass through the loop&lt;BR /&gt;for lyrName in lyrList2015:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;del lyr&lt;/P&gt;&lt;P&gt;################################### 2019 Data ##############################################&lt;/P&gt;&lt;P&gt;# Turn on visibility for each theme and export the page&lt;BR /&gt;lyrList2019 = ['NAIP2019_otho_flight_lines_a_NY','2019 Ortho Imagery']&lt;/P&gt;&lt;P&gt;# Don't assume the layers are turned off...Turn them off first.&lt;BR /&gt;print("2019 data")&lt;/P&gt;&lt;P&gt;for lyrName in lyrList2019:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = True&lt;BR /&gt;&lt;BR /&gt;#Change title text&lt;BR /&gt;TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]&lt;BR /&gt;TextElement.text = lyrName&lt;/P&gt;&lt;P&gt;#Export each theme to a temporary PDF and append to the final PDF&lt;BR /&gt;tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')&lt;BR /&gt;if os.path.exists(tmpPdf):&lt;BR /&gt;os.remove(tmpPdf)&lt;BR /&gt;arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;BR /&gt;print("\tPDF Exported to following path: " + lyr.name + tmpPdf)&lt;BR /&gt;finalPdf.appendPages(tmpPdf)&lt;BR /&gt;&lt;BR /&gt;#Turn off layer visibility and clean up for next pass through the loop&lt;BR /&gt;for lyrName in lyrList2019:&lt;BR /&gt;lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;BR /&gt;lyr.visible = False&lt;BR /&gt;del lyr&lt;/P&gt;&lt;P&gt;finalPdf.saveAndClose()&lt;BR /&gt;del mxd, df, finalPdf&lt;/P&gt;&lt;P&gt;Is there anyway to intergrate both a vertical and horizonal result? Selecting the tracts i need maps for and iterating through making maps for each selected tract?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 20:24:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-through-selected-attributes-and-export/m-p/1088630#M62077</guid>
      <dc:creator>EvanSweeney</dc:creator>
      <dc:date>2021-08-12T20:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through selected attributes and export toggled layer maps</title>
      <link>https://community.esri.com/t5/python-questions/iterate-through-selected-attributes-and-export/m-p/1088708#M62080</link>
      <description>&lt;P&gt;If I understand your need correctly, how about getting a list of tracts and then iterating over it?&lt;/P&gt;&lt;P&gt;Convert your script into a function so you can pass dynamic variables into it and reassign the variables as needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def createMaps(tract):
    Tract = tract
    .... # rest of your code

whereclause = 'if you need one to choose specfic tracts'
createMaps(x[0]) for x in arcpy.da.SearchCursor(yourfc, 'tractfield', whereclause)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 00:09:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-through-selected-attributes-and-export/m-p/1088708#M62080</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-08-13T00:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through selected attributes and export toggled layer maps</title>
      <link>https://community.esri.com/t5/python-questions/iterate-through-selected-attributes-and-export/m-p/1089070#M62083</link>
      <description>&lt;P&gt;Hi Jeff, I'm not much of a coder. Actually, I'm not a coder at all. I'm a conservationist. But I have tried to incorporate this code as indicated above and keep getting a syntax error on the 'for'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="EvanSweeney_0-1628895814545.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/20875iA4C207A3AFB7463A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="EvanSweeney_0-1628895814545.png" alt="EvanSweeney_0-1628895814545.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think this might be the solution i am looking for, i just dont know how to incorporate it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 23:04:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-through-selected-attributes-and-export/m-p/1089070#M62083</guid>
      <dc:creator>EvanSweeney</dc:creator>
      <dc:date>2021-08-13T23:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through selected attributes and export toggled layer maps</title>
      <link>https://community.esri.com/t5/python-questions/iterate-through-selected-attributes-and-export/m-p/1089073#M62084</link>
      <description>&lt;P&gt;No worries.&amp;nbsp; I didn't want to copy/ paste the whole code again but give this a try.&amp;nbsp; You might need to check the indents and make sure that they are correct since they get moved when the code copied/pasted from here without it being formatted. I see you also need/passed a second field, clu number so I provided the long form of the iteration to show passing the two values (check out lines 22 &amp;amp; 23). Hi from Wyoming the state, hope this helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os

def createMaps(tract, cluNmbr):
    # Specify output path and final output PDF
    outPath = r'C:\Outputs\TEST'
    pdfPath = os.path.join(outPath, '1. WetlandSupportdocs.pdf')
    if os.path.exists(pdfPath):
        os.remove(pdfPath)
    finalPdf = arcpy.mapping.PDFDocumentCreate(pdfPath)

    # Specify the map document and the data frame
    mxd = arcpy.mapping.MapDocument(r'C:\Geodata\Template.mxd')
    df = arcpy.mapping.ListDataFrames(mxd, 'Layers')[0]

    #################### ASSIGN VARIABLES ###########################
    #################################################################
    #################################################################
    #################################################################

    # I assume these are the variables that you want to change dynamically so assign incoming parameters to the variable
    Farm = ("2222")
    Tract = tract
    CLU = cluNmbr
    District = ("District")
    County = ("Wyoming")
    AssistedBy = ("Bob Conservationsit")
    FieldOffice = ("Hamilton")
    Customer = ("Joe Landowner")

    #################################################################
    #################################################################
    #################################################################
    #################################################################

    LandUnits = ('Farm ' +str(Farm) + ',' + 'Tract ' +str(Tract))

    #Change County text
    TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","District")[0]
    TextElement.text = District

    #Change County text
    TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","County")[0]
    TextElement.text = County

    #Change AssistedBy text
    TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","AssistedBy")[0]
    TextElement.text = AssistedBy

    #Change Field Office text
    TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","FieldOffice")[0]
    TextElement.text = FieldOffice

    #Change Customer name
    TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","CustomerName")[0]
    TextElement.text = Customer

    #Change Landunits
    TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","LandUnits")[0]
    TextElement.text = LandUnits

    # Select a tract using the TRACNBR attribute and zoom to selected
    lyr = arcpy.mapping.ListLayers(mxd, 'clu_a_053', df)[0]
    if CLU == "":
        arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", 'TRACTNBR IN ({0}) '.format(Tract))
        df.zoomToSelectedFeatures()
        lyr.definitionQuery = 'TRACTNBR IN ({0})'.format(Tract)
    else:
        arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", 'TRACTNBR IN ({0}) AND CLUNBR IN ({1})'.format(Tract, CLU))
        df.zoomToSelectedFeatures()
        lyr.definitionQuery = 'TRACTNBR IN ({0})AND CLUNBR IN ({1})'.format(Tract, CLU)
        df.zoomToSelectedFeatures()

        arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")
        arcpy.RefreshActiveView()

    # Turn on visibility for each theme and export the page
    lyrList = ['FSA Wetspots','National Wetlands Inventory','NYSDEC Wetlands','Madison County Soils','Soil Special Features','Percent Hydric Soils','Highly Erodible Land','Madison 2ft Contours','Topographic Image','DEC Unconsolidated Aquifers of NY State','EPA NYS sole source aquifers','USGS Potential Carbonate Karst Topography ','Surficial Geology','NYS Bedrock Geology ','NYS EcoRegion','NYS Important Bird Areas','Northern Long Eared Bat Location Data' ]

    # Don't assume the layers are turned off...Turn them off first.
    print("First, turn off all the layers")
    for lyrName in lyrList:
        lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
        lyr.visible = False
        print("\tSet layer-visibility for '" + lyr.name + "' to " + str(lyr.visible))

    print("Second, export to PDF")
    for lyrName in lyrList:
        print("---")
        lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
        lyr.visible = True
        print("\tSet layer-visibility for '" + lyr.name + "' to " + str(lyr.visible))

    #Change title text
    TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]
    TextElement.text = lyrName

    #Change Landowner name
    TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","CustomerName")[0]
    TextElement.text = 'Holmes-Acre LLC'

    #Change Landunits
    TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","FarmTractNbr")[0]
    TextElement.text = 'Farm NUB Tract 2215'

    #Export each theme to a temporary PDF and append to the final PDF
    tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')
    if os.path.exists(tmpPdf):
        os.remove(tmpPdf)

    arcpy.mapping.ExportToPDF(mxd, tmpPdf)
    print("\tPDF Exported to following path: " + tmpPdf)
    finalPdf.appendPages(tmpPdf)

    #Turn off layer visibility and clean up for next pass through the loop
    lyr.visible = False
    print("\tSet layer-visibility for '" + lyr.name + "' to " + str(lyr.visible))

    ################################### Wetland Data #################################################

    # Turn on visibility for each theme and export the page
    lyrListWET = ['National Wetlands Inventory','NYSDEC Wetlands']

    # Don't assume the layers are turned off...Turn them off first.
    print("First, turn on all the layers")

    for lyrName in lyrListWET:
        lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
    lyr.visible = True

    #Change title text
    TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]
    TextElement.text = "Wetlands"

    #Export each theme to a temporary PDF and append to the final PDF
    tmpPdf = os.path.join(outPath, "Wetlands" + '_temp.pdf')
    if os.path.exists(tmpPdf):
        os.remove(tmpPdf)
    arcpy.mapping.ExportToPDF(mxd, tmpPdf)
    print("\tPDF Exported to following path: " + tmpPdf)
    finalPdf.appendPages(tmpPdf)

    #Turn off layer visibility and clean up for next pass through the loop
    for lyrName in lyrListWET:
        lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
    lyr.visible = False
    del lyr

    ################################### CIR Data #################################################

    # Turn on visibility for each theme and export the page
    lyrListCIR = ['CIR_doqq_flight_dates','Infrared Ortho Imagery']

    # Don't assume the layers are turned off...Turn them off first.
    print("First, turn on all the layers")

    for lyrName in lyrListCIR:
        lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
    lyr.visible = True

    #Change title text
    TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]
    TextElement.text = lyrName

    #Export each theme to a temporary PDF and append to the final PDF
    tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')
    if os.path.exists(tmpPdf):
        os.remove(tmpPdf)
    arcpy.mapping.ExportToPDF(mxd, tmpPdf)
    print("\tPDF Exported to following path: " + tmpPdf)
    finalPdf.appendPages(tmpPdf)

    #Turn off layer visibility and clean up for next pass through the loop
    for lyrName in lyrListCIR:
        lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
    lyr.visible = False
    del lyr

    ################################### 2008 Data ##############################################

    # Turn on visibility for each theme and export the page
    lyrList2008 = ['ortho_1-1_1n_ny053_2008_1','2008 Ortho Imagery']

    # Don't assume the layers are turned off...Turn them off first.
    print("2008 data")

    for lyrName in lyrList2008:
        lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
    lyr.visible = True

    #Change title text
    TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]
    TextElement.text = lyrName

    #Export each theme to a temporary PDF and append to the final PDF
    tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')
    if os.path.exists(tmpPdf):
        os.remove(tmpPdf)
    arcpy.mapping.ExportToPDF(mxd, tmpPdf)
    print("\tPDF Exported to following path: " + lyr.name + tmpPdf)
    finalPdf.appendPages(tmpPdf)

    #Turn off layer visibility and clean up for next pass through the loop
    for lyrName in lyrList2008:
        lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
    lyr.visible = False
    del lyr

    ################################### 2009 Data ##############################################

    # Turn on visibility for each theme and export the page
    lyrList2009 = ['ortho_1-1_1n_ny053_2009_1','2009 Ortho Imagery']

    # Don't assume the layers are turned off...Turn them off first.
    print("2009 data")

    for lyrName in lyrList2009:
        lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
    lyr.visible = True

    #Change title text
    TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]
    TextElement.text = lyrName

    #Export each theme to a temporary PDF and append to the final PDF
    tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')
    if os.path.exists(tmpPdf):
        os.remove(tmpPdf)
    arcpy.mapping.ExportToPDF(mxd, tmpPdf)
    print("\tPDF Exported to following path: " + lyr.name + tmpPdf)
    finalPdf.appendPages(tmpPdf)

    #Turn off layer visibility and clean up for next pass through the loop
    for lyrName in lyrList2009:
        lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
    lyr.visible = False
    del lyr

    ################################### 2011 Data ##############################################

    # Turn on visibility for each theme and export the page
    lyrList2011 = ['ortho_1-1_1n_ny053_2011_1','2011 Ortho Imagery']

    # Don't assume the layers are turned off...Turn them off first.
    print("2011 Data")

    for lyrName in lyrList2011:
        lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
    lyr.visible = True

    #Change title text
    TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]
    TextElement.text = lyrName

    #Export each theme to a temporary PDF and append to the final PDF
    tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')
    if os.path.exists(tmpPdf):
        os.remove(tmpPdf)
    arcpy.mapping.ExportToPDF(mxd, tmpPdf)
    print("\tPDF Exported to following path: " + lyr.name + tmpPdf)
    finalPdf.appendPages(tmpPdf)

    #Turn off layer visibility and clean up for next pass through the loop
    for lyrName in lyrList2011:
        lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
    lyr.visible = False
    del lyr

    ################################### 2013 Data ##############################################

    # Turn on visibility for each theme and export the page
    lyrList2013 = ['ortho_1-1_1n_s_ny053_2013_1','2013 Ortho Imagery']

    # Don't assume the layers are turned off...Turn them off first.
    print("2013 data")

    for lyrName in lyrList2013:
        lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
    lyr.visible = True

    #Change title text
    TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]
    TextElement.text = lyrName

    #Export each theme to a temporary PDF and append to the final PDF
    tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')
    if os.path.exists(tmpPdf):
        os.remove(tmpPdf)
    arcpy.mapping.ExportToPDF(mxd, tmpPdf)
    print("\tPDF Exported to following path: " + lyr.name + tmpPdf)
    finalPdf.appendPages(tmpPdf)

    #Turn off layer visibility and clean up for next pass through the loop
    for lyrName in lyrList2013:
        lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
    lyr.visible = False
    del lyr

    ################################### 2015 Data ##############################################

    # Turn on visibility for each theme and export the page
    lyrList2015 = ['ortho_1-1_hn_s_ny053_2015_1','2015 Ortho Imagery']


    # Don't assume the layers are turned off...Turn them off first.
    print("2015 data")

    for lyrName in lyrList2015:
        lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
    lyr.visible = True

    #Change title text
    TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]
    TextElement.text = lyrName

    #Export each theme to a temporary PDF and append to the final PDF
    tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')
    if os.path.exists(tmpPdf):
        os.remove(tmpPdf)
    arcpy.mapping.ExportToPDF(mxd, tmpPdf)
    print("\tPDF Exported to following path: " + lyr.name + tmpPdf)
    finalPdf.appendPages(tmpPdf)

    #Turn off layer visibility and clean up for next pass through the loop
    for lyrName in lyrList2015:
        lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
    lyr.visible = False
    del lyr

    ################################### 2019 Data ##############################################

    # Turn on visibility for each theme and export the page
    lyrList2019 = ['NAIP2019_otho_flight_lines_a_NY','2019 Ortho Imagery']

    # Don't assume the layers are turned off...Turn them off first.
    print("2019 data")

    for lyrName in lyrList2019:
        lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
    lyr.visible = True

    #Change title text
    TextElement = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","TextTitle")[0]
    TextElement.text = lyrName

    #Export each theme to a temporary PDF and append to the final PDF
    tmpPdf = os.path.join(outPath, lyrName + '_temp.pdf')
    if os.path.exists(tmpPdf):
        os.remove(tmpPdf)
    arcpy.mapping.ExportToPDF(mxd, tmpPdf)
    print("\tPDF Exported to following path: " + lyr.name + tmpPdf)
    finalPdf.appendPages(tmpPdf)

    #Turn off layer visibility and clean up for next pass through the loop
    for lyrName in lyrList2019:
        lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
    lyr.visible = False
    del lyr

    finalPdf.saveAndClose()
    del mxd, df, finalPdf

with arcpy.da.SearchCursor('clu_layer', ['tractfield', 'cluNmbr'], 'whereclause') as sCur:
    for row in sCur:
        createMaps(row[0], row[1])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 23:27:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-through-selected-attributes-and-export/m-p/1089073#M62084</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-08-13T23:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through selected attributes and export toggled layer maps</title>
      <link>https://community.esri.com/t5/python-questions/iterate-through-selected-attributes-and-export/m-p/1089081#M62085</link>
      <description>&lt;P&gt;Hi From NY,&lt;/P&gt;&lt;P&gt;That is closer. I keep getting a runtime error "RuntimeError: cannot open 'clu_layer"&lt;/P&gt;&lt;P&gt;For this forum, this wasn't the actual layer name, but the correct layer name still comes up with the error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="EvanSweeney_0-1628899617592.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/20876i2F43AC1DEE0F23CC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="EvanSweeney_0-1628899617592.png" alt="EvanSweeney_0-1628899617592.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Aug 2021 00:07:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-through-selected-attributes-and-export/m-p/1089081#M62085</guid>
      <dc:creator>EvanSweeney</dc:creator>
      <dc:date>2021-08-14T00:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through selected attributes and export toggled layer maps</title>
      <link>https://community.esri.com/t5/python-questions/iterate-through-selected-attributes-and-export/m-p/1089083#M62086</link>
      <description>&lt;P&gt;There are a few ways to solve that-&amp;nbsp; You can use arcmap (copy from the location at the top of the catalog) /pro (click on the fc in the catalog and look for the Copy Path in the menu ribbon) to copy the path of the featureclass that you want and use the path, assign it to a variable and use the variable, or you can use arcpy.env.workspace and pass the fc name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;clu_layer = r'path to the fc'

with arcpy.da.SearchCursor(clu_layer, [fields]...)

# or 
with arcpy.da.SearchCursor(r'path to the fc', [fields]...)

# or using the workspace
arcpy.env.workspace = your directory or geodatabase containing the fc
with arcpy.da.SearchCursor('fcname in quotes', [fields]...)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Aug 2021 00:35:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-through-selected-attributes-and-export/m-p/1089083#M62086</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-08-14T00:35:19Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through selected attributes and export toggled layer maps</title>
      <link>https://community.esri.com/t5/python-questions/iterate-through-selected-attributes-and-export/m-p/1089084#M62087</link>
      <description>&lt;P&gt;Tried all three. Still getting the same error of not being able to open. But it's8:30 pm here so i think i have put in a solid 14 hour day. Thanks Jeff. Ill try again on monday.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Aug 2021 00:32:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-through-selected-attributes-and-export/m-p/1089084#M62087</guid>
      <dc:creator>EvanSweeney</dc:creator>
      <dc:date>2021-08-14T00:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through selected attributes and export toggled layer maps</title>
      <link>https://community.esri.com/t5/python-questions/iterate-through-selected-attributes-and-export/m-p/1096475#M62275</link>
      <description>&lt;P&gt;Just an FYI, i found the easiest solution was to forgo the variables option and just create an SQL for my search parameters. i.e.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;SQL =  "TRACTNBR IN (1234) AND CLUNBR IN ( 12)",
       "TRACTNBR IN (6789) AND CLUNBR IN ( 4,5,6,14,20)",
       "TRACTNBR IN (3456) AND CLUNBR IN ( 1)",]


##  Run for loop through each SQL statement  ##
for SQL in SQL:
         MAKE ALL THE MAPS!&lt;/LI-CODE&gt;&lt;P&gt;&amp;gt;&lt;/P&gt;&lt;P&gt;It works pretty well until I run&amp;nbsp;into a new problem that ill be posing to those who know better. The code gets hung up on Fields that dont exist (i.e.&amp;nbsp;"TRACTNBR IN (1234) AND CLUNBR IN (17)" is the 250th loop in the code. The code stalls and eventually comes out with "RESTART: SHELL". I know i can go through and remove the offending the SQL, but i would rather add in something to help skip those errors. Ill likely be translating this for other teams to use so i dont want to bother pulling out bad fld numbers.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 16:47:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-through-selected-attributes-and-export/m-p/1096475#M62275</guid>
      <dc:creator>EvanSweeney</dc:creator>
      <dc:date>2021-09-08T16:47:40Z</dc:date>
    </item>
  </channel>
</rss>

