<?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: Python script using definition query, zoom to feature, and export to PDF. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-script-using-definition-query-zoom-to/m-p/405961#M31947</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you post your code on here rather than a zip file please?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 30 Oct 2020 11:40:44 GMT</pubDate>
    <dc:creator>DavidPike</dc:creator>
    <dc:date>2020-10-30T11:40:44Z</dc:date>
    <item>
      <title>Python script using definition query, zoom to feature, and export to PDF.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-using-definition-query-zoom-to/m-p/405960#M31946</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am having an issue with getting this script to work. I wrote this a while ago and when I first wrote it, it worked perfectly. Now I am trying to use it again and I can't get it to work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need a PDF zoomed to each feature (Parcel), only showing one&amp;nbsp;parcel at a time. The script should make a definition query for each parcel ID, zoom to that parcel, and export the map as a PDF. Everything works&amp;nbsp;except it won't zoom in properly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone figure out why this might be?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have attached the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Erin&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;from arcpy.mapping import *&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;mapDoc = arcpy.mapping.MapDocument(r"C:\Users\CulpE\Desktop\Parcels.mxd")&lt;BR /&gt;dataFrames = ListDataFrames(mapDoc)&lt;BR /&gt;dataFrame = dataFrames[0]&lt;BR /&gt;adjParcel = r"C:\Users\CulpE\Desktop\parcels.shp"&lt;BR /&gt;parcel_layer = "Parcel"&lt;BR /&gt;lyrs = arcpy.mapping.ListLayers(mapDoc, '', dataFrame)&lt;/P&gt;&lt;P&gt;fieldList = ['PROP_ID']&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for lyr in lyrs:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;if lyr.name == parcel_layer:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;with arcpy.da.SearchCursor(lyr, fieldList) as cursor:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for row in cursor:&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;&amp;nbsp;lyr.definitionQuery = "PROP_ID ='" + str(row[0]) + "'"&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;&amp;nbsp;print "PROP_ID='" + str(row[0]) + "'"&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;&amp;nbsp;ext = lyr.getExtent()&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;&amp;nbsp;dataFrame.extent = ext&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;&amp;nbsp;dataFrame.scale *= 1.5&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;&amp;nbsp;ExportToPDF (mapDoc, r"C:\Users\CulpE\Desktop\Parcel_" + str(row[0]) + ".pdf", "PAGE_LAYOUT")&lt;BR /&gt; &lt;BR /&gt;del mapDoc&lt;BR /&gt;print "Closed map document"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 18:14:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-using-definition-query-zoom-to/m-p/405960#M31946</guid>
      <dc:creator>ErinCulp</dc:creator>
      <dc:date>2020-10-29T18:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: Python script using definition query, zoom to feature, and export to PDF.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-using-definition-query-zoom-to/m-p/405961#M31947</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you post your code on here rather than a zip file please?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Oct 2020 11:40:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-using-definition-query-zoom-to/m-p/405961#M31947</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2020-10-30T11:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: Python script using definition query, zoom to feature, and export to PDF.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-using-definition-query-zoom-to/m-p/405962#M31948</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I updated the post with the script.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Oct 2020 14:36:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-using-definition-query-zoom-to/m-p/405962#M31948</guid>
      <dc:creator>ErinCulp</dc:creator>
      <dc:date>2020-10-30T14:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: Python script using definition query, zoom to feature, and export to PDF.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-using-definition-query-zoom-to/m-p/405963#M31949</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Had a gander, always helps to debug with some print statements as you go along to identify what's happening as it runs.&amp;nbsp; Also print the objects being returned to check on them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I' not sure on this definition query:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #3d3d3d; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; overflow-wrap: break-word; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;lyr.definitionQuery = "PROP_ID ='" + str(row[0]) + "'"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #3d3d3d; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; overflow-wrap: break-word; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;I think it should be (if PROP_ID field is a string?):&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #3d3d3d; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; overflow-wrap: break-word; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;"'" + "PROP_ID = " + "'" + str(row[0]) + "'" + "'"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; overflow-wrap: break-word; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; padding: 0px; margin: 0px;"&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #3d3d3d; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; overflow-wrap: break-word; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;should be (if PROP_ID field is a number?):&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; overflow-wrap: break-word; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; padding: 0px; margin: 0px;"&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #3d3d3d; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; overflow-wrap: break-word; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;'"' + "PROP_ID = " + str(row[0])&amp;nbsp; + "'"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #3d3d3d; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; overflow-wrap: break-word; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;my brain has given up on me, but basically the query should be formed to look like this string i.e. when printed it still retains a single quote surrounding it:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #3d3d3d; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; overflow-wrap: break-word; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;definition_query = 'PROP_ID = 265FG'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #3d3d3d; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; overflow-wrap: break-word; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;or if PROP_ID field is a number:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #3d3d3d; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; overflow-wrap: break-word; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;definition_query = 'PROP_ID = 265'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #3d3d3d; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; overflow-wrap: break-word; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;I'd recommend forming definition_query as a variable, print it to make sure it looks OK, then assign it to lyr.definitionQuery.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;also NB PROP_ID would also be quoted in the SQL query if a shapefile just to add some fun to the mix.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Oct 2020 22:08:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-using-definition-query-zoom-to/m-p/405963#M31949</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2020-10-30T22:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: Python script using definition query, zoom to feature, and export to PDF.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-using-definition-query-zoom-to/m-p/405964#M31950</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Does the script zoom in on any parcels and just has an issue with certain parcels?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Oct 2020 22:13:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-using-definition-query-zoom-to/m-p/405964#M31950</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2020-10-30T22:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: Python script using definition query, zoom to feature, and export to PDF.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-using-definition-query-zoom-to/m-p/405965#M31951</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;nbsp;No, it seems to zoom out to all parcels for half of the. and then zooms to the same parcel for the other half.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Nov 2020 17:59:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-using-definition-query-zoom-to/m-p/405965#M31951</guid>
      <dc:creator>ErinCulp</dc:creator>
      <dc:date>2020-11-02T17:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: Python script using definition query, zoom to feature, and export to PDF.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-using-definition-query-zoom-to/m-p/405966#M31952</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much! I will try this!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Nov 2020 17:59:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-using-definition-query-zoom-to/m-p/405966#M31952</guid>
      <dc:creator>ErinCulp</dc:creator>
      <dc:date>2020-11-02T17:59:36Z</dc:date>
    </item>
  </channel>
</rss>

