<?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: Creating Data Driven Pages Based on Selection in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/creating-data-driven-pages-based-on-selection/m-p/627758#M48900</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;OK I made the changes you suggested and also changed my data sources to a local drive whereas before it was a remote connection. I also changed the SearchCursor method to specify the OBJECTID field, and also modified the "SelectLayerByAttribute" query to simply search for OBJECTID = 1 just to see if I could get it working. Here is the code I am now running:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;========================================================================================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;env.workspace = "E:\GasLeaksProject\2012\GasLeaks.gdb"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Layer = arcpy.mapping.ListLayers(mxd, "ImplausibleReads", df)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Create a search cursor, iterate through the Implausible Reads Feature, getting and zooming to respective extents and exporting layout to JPEG.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;rows = arcpy.SearchCursor("E:/GasLeaksProject/2012/GasLeaks.gdb/Gas_Selection", "", "", "OBJECTID")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;currentState = " "&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Iterate through the rows in the cursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for row in rows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; [INDENT]if currentState != row.OBJECTID:[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT][INDENT] currentState = row.OBJECTID&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.SelectLayerByAttribute_management (Layer, "NEW_SELECTION", ' "OBJECTID" = 1 ' )&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; df.zoomToSelectedFeatures()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.RefreshActiveView()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.mapping.ExportToJPEG(mxd, r"E:\GasLeaksProject\JPEG\OBJECTID" + str(currentState) + ".jpeg", df_export_width=1500, df_export_height=1200, resolution=300, jpeg_quality=70)[/INDENT][/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;del mxd&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;========================================================================================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This works and exports the extent of the feature with OBJECTID = 1, but then continues exporting the same feature only with a larger extent. When I try adding the "currentState" variable to the SelectLayerByAttribute line, it does not work, and returns &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;type 'exceptions.SyntaxError'&amp;gt;: invalid syntax (JPEG.py, line 20)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (Script).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm oging to continue playing around with it to see if I can get it working.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 28 Jun 2012 15:04:02 GMT</pubDate>
    <dc:creator>MarcCusumano</dc:creator>
    <dc:date>2012-06-28T15:04:02Z</dc:date>
    <item>
      <title>Creating Data Driven Pages Based on Selection</title>
      <link>https://community.esri.com/t5/python-questions/creating-data-driven-pages-based-on-selection/m-p/627751#M48893</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am working on creating an automated process that exports data driven pages to JPEG images based on a set of joins and spatial queries inside of a map document. All of the features and tables I am working with are in an SDE environment and cannot be modified. I am going through the process manually first before I begin trying to automate everything in Python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am stuck at the point where I need to create data driven pages based on a current selection. I have setup a join from a feature to a table keeping only matching features, and then performed a spatial query on those matching features with another feature to arrive at a final selection of 771 records out of 989. The next step is to build data-driven pages based only on these selected features, and not on the entire feature. I have gone through the documentation and have not come up with anything. Again, ideally I would not be creating a new feature, but it is looking like I may have to in a temporary workspace before setting up the map book.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Jun 2012 14:15:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-data-driven-pages-based-on-selection/m-p/627751#M48893</guid>
      <dc:creator>MarcCusumano</dc:creator>
      <dc:date>2012-06-21T14:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Data Driven Pages Based on Selection</title>
      <link>https://community.esri.com/t5/python-questions/creating-data-driven-pages-based-on-selection/m-p/627752#M48894</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;There is an option when exporting DDP to use only the selected set.&amp;nbsp; So I would enable DDP on all features of the index layer, then create my selection, then export.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the UI, go to File --&amp;gt; ExportMap --&amp;gt; Select PDF --&amp;gt; Pages Tab - check Selection (optionally you can show selection)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In arcpy, the parameters are:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;exportToPDF (out_pdf, &lt;/SPAN&gt;&lt;STRONG&gt;{page_range_type}, &lt;/STRONG&gt;&lt;SPAN&gt;{page_range_string}, {multiple_files}, {resolution}, {image_quality}, {colorspace}, {compress_vectors}, {image_compression}, {picture_symbol}, {convert_markers}, {embed_fonts}, {layers_attributes}, {georef_info}, {jpeg_compression_quality}, &lt;/SPAN&gt;&lt;STRONG&gt;{show_selection_symbology})&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Set&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; page_range_type = "SELECTION",&amp;nbsp;&amp;nbsp; optionally, set&amp;nbsp;&amp;nbsp;&amp;nbsp; show_selection_symbology=True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Jun 2012 13:35:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-data-driven-pages-based-on-selection/m-p/627752#M48894</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2012-06-22T13:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Data Driven Pages Based on Selection</title>
      <link>https://community.esri.com/t5/python-questions/creating-data-driven-pages-based-on-selection/m-p/627753#M48895</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't think my original response addresses the main concern (you want to go to JPEG, not PDF). Here is another shot at it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Again, build your DDP using the complete set of features and then build your selection.&amp;nbsp; Next, use the .selectedPages property on the DDP object to process only the pages of interest.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Look at code examples 1 and 3 in the arcpy.mapping DDP object help topic.&amp;nbsp; In example 1, change PNG to JPEG and use the selected pages optoin from example 3.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope this helps,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Jun 2012 13:54:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-data-driven-pages-based-on-selection/m-p/627753#M48895</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2012-06-25T13:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Data Driven Pages Based on Selection</title>
      <link>https://community.esri.com/t5/python-questions/creating-data-driven-pages-based-on-selection/m-p/627754#M48896</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you Jeff, that will make the process a lot cleaner. I am trying to automate this, so that when data is dumped into a feature class the script will create the data driven pages automatically and export to JPEG. Is there a way to build data driven pages without doing it manually through ArcMap?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Jun 2012 17:53:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-data-driven-pages-based-on-selection/m-p/627754#M48896</guid>
      <dc:creator>MarcCusumano</dc:creator>
      <dc:date>2012-06-25T17:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Data Driven Pages Based on Selection</title>
      <link>https://community.esri.com/t5/python-questions/creating-data-driven-pages-based-on-selection/m-p/627755#M48897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;We are not able to build DDP outside of ArcMap.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Jun 2012 13:48:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-data-driven-pages-based-on-selection/m-p/627755#M48897</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2012-06-26T13:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Data Driven Pages Based on Selection</title>
      <link>https://community.esri.com/t5/python-questions/creating-data-driven-pages-based-on-selection/m-p/627756#M48898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That is what I figured. I will need to come up with a way to do this without using DDP. Here is what I have so far (this is solely to emulate the DDP functionality inside ArcMap for now; once it is working I will modify it to work from a standalone Python script).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"ImplausibleReads" is the layer I am trying to export as DDP, which is built on the "GAS_SELECTION" feature class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-size:1;"&gt;import arcpy&lt;BR /&gt;from arcpy import env&lt;BR /&gt;env.workspace = "H:\SP1G0\Gas Leaks\GasLeaks.gdb"&lt;BR /&gt;&lt;BR /&gt;mxd = arcpy.mapping.MapDocument(mxd = "CURRENT")&lt;BR /&gt;df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]&lt;BR /&gt;Layer = (mxd, "ImplausibleReads", df)[0]&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;# Create a search cursor&lt;BR /&gt;&lt;BR /&gt;rows = arcpy.SearchCursor("Gas_Selection")&lt;BR /&gt;&lt;BR /&gt;currentState = " "&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; # Iterate, select and zoom to each row in the cursor and export to JPEG&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt;for row in rows:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [INDENT]if currentState != row.OBJECTID:[/INDENT]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [INDENT][INDENT]currentState = row.OBJECTID[/INDENT][/INDENT]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [INDENT][INDENT]arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION", ' "OBJECTID" = currentState ' )[/INDENT][/INDENT]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [INDENT][INDENT]df.zoomToSelectedFeatures()[/INDENT][/INDENT]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [INDENT][INDENT]arcpy.RefreshActiveView()[/INDENT][/INDENT]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [INDENT][INDENT]arcpy.mapping.ExportToJPEG(mxd, r"H:\SP1G0\Gas Leaks\JPEG\Connection_Obj__" + str(currentState) + ".jpeg", df_export_width=1500, df_export_height=1200, resolution=300, jpeg_quality=70)[/INDENT][/INDENT]&lt;BR /&gt;del mxd&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This results in an error "&amp;lt;type 'exceptions.RuntimeError'&amp;gt;: Object: Error in executing tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (Script)."&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Jun 2012 10:41:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-data-driven-pages-based-on-selection/m-p/627756#M48898</guid>
      <dc:creator>MarcCusumano</dc:creator>
      <dc:date>2012-06-27T10:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Data Driven Pages Based on Selection</title>
      <link>https://community.esri.com/t5/python-questions/creating-data-driven-pages-based-on-selection/m-p/627757#M48899</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;My motto has always been, "why do it in the UI, when you can do it with arcpy".&amp;nbsp; Everything you can do with DDP, you can do with arcpy.mapping plus a whole lot more.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Couple of things:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1) Curious why mxd = arcpy.mapping.MapDocument(mxd = "CURRENT") works.&amp;nbsp; The parameter name is mxd_path (but that doesn't work).&amp;nbsp; I personally use .MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2) Your Layer variable doesn't look right.&amp;nbsp; Try, Layer = arcpy.mapping.ListLayers(mxd, "ImplausibleReads", df)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Jun 2012 14:45:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-data-driven-pages-based-on-selection/m-p/627757#M48899</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2012-06-27T14:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Data Driven Pages Based on Selection</title>
      <link>https://community.esri.com/t5/python-questions/creating-data-driven-pages-based-on-selection/m-p/627758#M48900</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;OK I made the changes you suggested and also changed my data sources to a local drive whereas before it was a remote connection. I also changed the SearchCursor method to specify the OBJECTID field, and also modified the "SelectLayerByAttribute" query to simply search for OBJECTID = 1 just to see if I could get it working. Here is the code I am now running:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;========================================================================================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;env.workspace = "E:\GasLeaksProject\2012\GasLeaks.gdb"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Layer = arcpy.mapping.ListLayers(mxd, "ImplausibleReads", df)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Create a search cursor, iterate through the Implausible Reads Feature, getting and zooming to respective extents and exporting layout to JPEG.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;rows = arcpy.SearchCursor("E:/GasLeaksProject/2012/GasLeaks.gdb/Gas_Selection", "", "", "OBJECTID")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;currentState = " "&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Iterate through the rows in the cursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for row in rows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; [INDENT]if currentState != row.OBJECTID:[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT][INDENT] currentState = row.OBJECTID&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.SelectLayerByAttribute_management (Layer, "NEW_SELECTION", ' "OBJECTID" = 1 ' )&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; df.zoomToSelectedFeatures()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.RefreshActiveView()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.mapping.ExportToJPEG(mxd, r"E:\GasLeaksProject\JPEG\OBJECTID" + str(currentState) + ".jpeg", df_export_width=1500, df_export_height=1200, resolution=300, jpeg_quality=70)[/INDENT][/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;del mxd&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;========================================================================================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This works and exports the extent of the feature with OBJECTID = 1, but then continues exporting the same feature only with a larger extent. When I try adding the "currentState" variable to the SelectLayerByAttribute line, it does not work, and returns &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;type 'exceptions.SyntaxError'&amp;gt;: invalid syntax (JPEG.py, line 20)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (Script).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm oging to continue playing around with it to see if I can get it working.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Jun 2012 15:04:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-data-driven-pages-based-on-selection/m-p/627758#M48900</guid>
      <dc:creator>MarcCusumano</dc:creator>
      <dc:date>2012-06-28T15:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Data Driven Pages Based on Selection</title>
      <link>https://community.esri.com/t5/python-questions/creating-data-driven-pages-based-on-selection/m-p/627759#M48901</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Great news! I got the script working. Here is the final code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;====================================================================================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-size:1;"&gt;import arcpy&lt;BR /&gt;from arcpy import env&lt;BR /&gt;env.workspace = "E:\GasLeaksProject\2012\GasLeaks.gdb"&lt;BR /&gt;&lt;BR /&gt;mxd = arcpy.mapping.MapDocument("CURRENT")&lt;BR /&gt;df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]&lt;BR /&gt;Layer = arcpy.mapping.ListLayers(mxd, "ImplausibleReads", df)[0]&lt;BR /&gt;#arcpy.MakeFeatureLayer_management("Gas_Selection", "ImplausibleRead")&lt;BR /&gt;&lt;BR /&gt;# Create a search cursor, iterate through the Implausible Reads Feature, getting and zooming to respective extents and exporting layout to JPEG.&lt;BR /&gt;rows = arcpy.SearchCursor("E:/GasLeaksProject/2012/GasLeaks.gdb/Gas_Selection", "", "", "OBJECTID")&lt;BR /&gt;&lt;BR /&gt;#rows = arcpy.GetCount_management("Gas_Selection")&lt;BR /&gt;currentState = " "&lt;BR /&gt;&lt;BR /&gt;# Iterate through the rows in the cursor&lt;BR /&gt;for row in rows:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [INDENT] if currentState != row.OBJECTID:[/INDENT]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [INDENT][INDENT] currentState = row.OBJECTID&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where_clause = "\"OBJECTID\"=" + str(currentState)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management (Layer, "NEW_SELECTION",&amp;nbsp; where_clause )&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.zoomToSelectedFeatures()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.scale = 6914&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management (Layer, "CLEAR_SELECTION",&amp;nbsp; "" )&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToJPEG(mxd, r"E:\GasLeaksProject\JPEG\OBJECTID" + str(currentState) + ".jpeg", df_export_width=1500, df_export_height=1200, resolution=300, jpeg_quality=70)[/INDENT][/INDENT]&lt;BR /&gt;del mxd&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;====================================================================================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Jun 2012 16:57:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-data-driven-pages-based-on-selection/m-p/627759#M48901</guid>
      <dc:creator>MarcCusumano</dc:creator>
      <dc:date>2012-06-28T16:57:43Z</dc:date>
    </item>
  </channel>
</rss>

