<?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 Re: loop through a layer and select each polygon and save as jpeg in ArcMap in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/loop-through-a-layer-and-select-each-polygon-and/m-p/1012300#M59390</link>
    <description>&lt;P&gt;You just need to throw in&amp;nbsp;&lt;A href="https://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-mapping/exporttojpeg.htm" target="_blank"&gt;ExportToJPEG—Help | ArcGIS for Desktop&lt;/A&gt;&amp;nbsp;within the loop (after refreshactiveview).&lt;/P&gt;&lt;P&gt;do something like concatenate an outpath with what you have already -&amp;nbsp;&lt;SPAN class="hljs-built_in"&gt;str&lt;/SPAN&gt;(row.FID)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd recommend using the arcpy.da cursor rather than the arcpy cursor.&lt;/P&gt;&lt;P&gt;&lt;A href="https://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-data-access/searchcursor-class.htm" target="_blank"&gt;SearchCursor—Help | ArcGIS for Desktop&lt;/A&gt;&lt;/P&gt;&lt;P&gt;It will require some change of syntax, though if you plan on working with cursors again, it's best to adopt the da cursor from the onset.&lt;/P&gt;</description>
    <pubDate>Thu, 24 Dec 2020 16:56:09 GMT</pubDate>
    <dc:creator>DavidPike</dc:creator>
    <dc:date>2020-12-24T16:56:09Z</dc:date>
    <item>
      <title>loop through a layer and select each polygon and save as jpeg in ArcMap</title>
      <link>https://community.esri.com/t5/python-questions/loop-through-a-layer-and-select-each-polygon-and/m-p/1012293#M59389</link>
      <description>&lt;DIV class="votecell post-layout--left"&gt;&lt;DIV class="js-voting-container grid jc-center fd-column ai-stretch gs4 fc-black-200"&gt;&lt;DIV class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center"&gt;1&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="postcell post-layout--right"&gt;&lt;DIV class="s-prose js-post-body"&gt;&lt;P&gt;I'm a beginner in ArcPy and I want to perform some tasks using ArcPy but I am not getting results.&lt;/P&gt;&lt;P&gt;I have a layer named&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;survey&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;in my current MXD and I want to select each polygon in&lt;SPAN&gt;&amp;nbsp;surveyand export to JPEG&amp;nbsp;&lt;/SPAN&gt;and this is my script:&lt;/P&gt;&lt;PRE&gt;mxd = arcpy.mapping.MapDocument(&lt;SPAN class="hljs-string"&gt;"CURRENT"&lt;/SPAN&gt;) 
df = arcpy.mapping.ListDataFrames(mxd)[&lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;]
titleElement = arcpy.mapping.ListLayoutElements(mxd, &lt;SPAN class="hljs-string"&gt;"TEXT_ELEMENT"&lt;/SPAN&gt;)

rows = arcpy.SearchCursor(&lt;SPAN class="hljs-string"&gt;"survey selection"&lt;/SPAN&gt;)
&lt;SPAN class="hljs-keyword"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="hljs-keyword"&gt;in&lt;/SPAN&gt; rows: 
    titleElement = row.VendorFarm 
    query = &lt;SPAN class="hljs-string"&gt;'"FID"='&lt;/SPAN&gt; + &lt;SPAN class="hljs-built_in"&gt;str&lt;/SPAN&gt;(row.FID)    
    arcpy.SelectLayerByAttribute_management(&lt;SPAN class="hljs-string"&gt;"survey selection"&lt;/SPAN&gt;, &lt;SPAN class="hljs-string"&gt;"NEW_SELECTION"&lt;/SPAN&gt;, query)     
    df.zoomToSelectedFeatures()      
    arcpy.RefreshActiveView()

&lt;SPAN class="hljs-keyword"&gt;del&lt;/SPAN&gt; rows 
&lt;SPAN class="hljs-keyword"&gt;del&lt;/SPAN&gt; row&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 24 Dec 2020 16:07:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-through-a-layer-and-select-each-polygon-and/m-p/1012293#M59389</guid>
      <dc:creator>Official4</dc:creator>
      <dc:date>2020-12-24T16:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: loop through a layer and select each polygon and save as jpeg in ArcMap</title>
      <link>https://community.esri.com/t5/python-questions/loop-through-a-layer-and-select-each-polygon-and/m-p/1012300#M59390</link>
      <description>&lt;P&gt;You just need to throw in&amp;nbsp;&lt;A href="https://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-mapping/exporttojpeg.htm" target="_blank"&gt;ExportToJPEG—Help | ArcGIS for Desktop&lt;/A&gt;&amp;nbsp;within the loop (after refreshactiveview).&lt;/P&gt;&lt;P&gt;do something like concatenate an outpath with what you have already -&amp;nbsp;&lt;SPAN class="hljs-built_in"&gt;str&lt;/SPAN&gt;(row.FID)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd recommend using the arcpy.da cursor rather than the arcpy cursor.&lt;/P&gt;&lt;P&gt;&lt;A href="https://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-data-access/searchcursor-class.htm" target="_blank"&gt;SearchCursor—Help | ArcGIS for Desktop&lt;/A&gt;&lt;/P&gt;&lt;P&gt;It will require some change of syntax, though if you plan on working with cursors again, it's best to adopt the da cursor from the onset.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Dec 2020 16:56:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-through-a-layer-and-select-each-polygon-and/m-p/1012300#M59390</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2020-12-24T16:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: loop through a layer and select each polygon and save as jpeg in ArcMap</title>
      <link>https://community.esri.com/t5/python-questions/loop-through-a-layer-and-select-each-polygon-and/m-p/1012803#M59396</link>
      <description>&lt;P&gt;As &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/167692"&gt;@DavidPike&lt;/a&gt; suggests, you should use the da.SearchCursor.&amp;nbsp; I noticed that you are attempting to access and set a map title using &lt;A title="ListLayoutElements" href="https://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/listlayoutelements.htm" target="_self"&gt;ListLayoutElements&lt;/A&gt; .&amp;nbsp; This will return a list, and you will need to access the proper text element.&amp;nbsp; It might be easier if you use the dynamic map "Title" as this property can be accessed and changed.&amp;nbsp; Here's a code snippet which illustrates these ideas.&amp;nbsp; Since it looks like you are using shape files, you may need to make some changes.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]

feature = 'survey selection'
fields = ['OID@', 'VendorFarm'] # OID@ is ObjectID token (see search cursor help)
jpgPath = r"C:\Path\For\JPGs" # save location for jpgs

# clear any existing selections
arcpy.SelectLayerByAttribute_management(feature, "CLEAR_SELECTION")

with arcpy.da.SearchCursor(feature, fields) as cursor:
    for FID, VendorFarm in cursor: # unpack each row by assigning to field name variables
        mxd.title = VendorFarm
        query = '"FID" = {}'.format(str(FID))
        arcpy.SelectLayerByAttribute_management(feature, "NEW_SELECTION", query)
        df.zoomToSelectedFeatures()
        arcpy.RefreshActiveView()

        jpg = "{}\\{}.jpg".format(jpgPath, VendorFarm) # assuming VendorFarm is valid filename
        arcpy.mapping.ExportToJPEG (mxd, jpg)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you need to use the ListLayoutElements, I would suggest that your map's text elements be named as this will help you find the correct element.&amp;nbsp; Just a rough code snippet to illustrate:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;titleElement = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT")

for t in titleElement:
    if t.name == 'MapTitle'
        t.text = 'Some New Text'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2020 02:16:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-through-a-layer-and-select-each-polygon-and/m-p/1012803#M59396</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2020-12-30T02:16:09Z</dc:date>
    </item>
  </channel>
</rss>

