<?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: Help with layer file definition query in arcpy.mapping in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/help-with-layer-file-definition-query-in-arcpy/m-p/743788#M57499</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is it just the JPEGs that aren't displaying the layer correctly? Step through using mxd = arcpy.mapping.MapDocument("CURRENT"), if you haven't already. Try exporting to pdf or one of the other formats too and see if you get the same results.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 20 Aug 2013 19:31:35 GMT</pubDate>
    <dc:creator>MattSayler</dc:creator>
    <dc:date>2013-08-20T19:31:35Z</dc:date>
    <item>
      <title>Help with layer file definition query in arcpy.mapping</title>
      <link>https://community.esri.com/t5/python-questions/help-with-layer-file-definition-query-in-arcpy/m-p/743784#M57495</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Everything seems to work just fine with the code below except that no features draw in the layer that is being queried.&amp;nbsp; All I want to do is create a jpeg for each record in my geodatabase feature class of point locations.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there something wrong with my query syntax?&amp;nbsp; I cannot figure it out!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy, sys, traceback
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Working..."
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxdPath = r"Z:\GISpublic\GerryG\WaterResources\WaterSampleSiteAutoMap\WaterSampleSiteAutoMap2.mxd"
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(mxdPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr = arcpy.mapping.ListLayers(mxd, "WaterSampleSiteMaster", df)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; print lyr.dataSource
&amp;nbsp;&amp;nbsp;&amp;nbsp; theAttribute = "SiteID"
&amp;nbsp;&amp;nbsp;&amp;nbsp; #GetAListOfEachAttribute
&amp;nbsp;&amp;nbsp;&amp;nbsp; listOfAttributes = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Start cursor"
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.SearchCursor(lyr.dataSource)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; listOfAttributes.append(row.getValue(theAttribute))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if elm.name == 'gbglabeler':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elm = elm
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print elm.name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for item in listOfAttributes:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #GBGquery = "\""&amp;nbsp; + theAttribute + "\" = " + "'" + item + "'"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GBGquery = '"SiteID" =' + '\''+ item + '\''
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print&amp;nbsp; "Working on: ",item
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print GBGquery
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.definitionQuery = GBGquery
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elm.text = "Site: " + item
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outputjpg = "Z:\GISpublic\GerryG\WaterResources\WaterSampleSiteAutoMap\SiteMaps\\" + item + ".jpg"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToJPEG (mxd, outputjpg)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "done"
except arcpy.ExecuteError: 
&amp;nbsp;&amp;nbsp;&amp;nbsp; msgs = arcpy.GetMessages(2) 
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError(msgs)&amp;nbsp; 
#If the error is with the script, or with python, find error and report it to the screen...
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; tb = sys.exc_info()[2]
&amp;nbsp;&amp;nbsp;&amp;nbsp; tbinfo = traceback.format_tb(tb)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
&amp;nbsp;&amp;nbsp;&amp;nbsp; msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError(pymsg)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError(msgs)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Aug 2013 18:20:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-layer-file-definition-query-in-arcpy/m-p/743784#M57495</guid>
      <dc:creator>GerryGabrisch</dc:creator>
      <dc:date>2013-08-20T18:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: Help with layer file definition query in arcpy.mapping</title>
      <link>https://community.esri.com/t5/python-questions/help-with-layer-file-definition-query-in-arcpy/m-p/743785#M57496</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Long time no see!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Starting with the basics, is SiteID a text field (does the value need the single quotes)? Is the query working if you manually assign it to the layer?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Since it's running without error, I suspect this won't help, but you could also try using the Add Field Delimeters method for the field name:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;GBGquery = arcpy.AddFieldDelimiters(lyr, theAttribute) + " = '" + item + "'"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Aug 2013 18:52:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-layer-file-definition-query-in-arcpy/m-p/743785#M57496</guid>
      <dc:creator>MattSayler</dc:creator>
      <dc:date>2013-08-20T18:52:16Z</dc:date>
    </item>
    <item>
      <title>Re: Help with layer file definition query in arcpy.mapping</title>
      <link>https://community.esri.com/t5/python-questions/help-with-layer-file-definition-query-in-arcpy/m-p/743786#M57497</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the reply, Matt.&amp;nbsp; I hope you are doing well.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, SiteID is an attribute storing text.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried the field delimeter but that just returned the same text string as the brute force way and nothing showed on the output jpeg.&amp;nbsp; Any other thoughts?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Aug 2013 19:08:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-layer-file-definition-query-in-arcpy/m-p/743786#M57497</guid>
      <dc:creator>GerryGabrisch</dc:creator>
      <dc:date>2013-08-20T19:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: Help with layer file definition query in arcpy.mapping</title>
      <link>https://community.esri.com/t5/python-questions/help-with-layer-file-definition-query-in-arcpy/m-p/743787#M57498</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hmmm, Must have been some hang up between Arcpy, Komodo, ArcGIS or Citrix.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried to save the original mxd, got an error that the file location folder was in use.&amp;nbsp; After shutting ArcMap and Komodo down the original code worked fine.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Aug 2013 19:18:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-layer-file-definition-query-in-arcpy/m-p/743787#M57498</guid>
      <dc:creator>GerryGabrisch</dc:creator>
      <dc:date>2013-08-20T19:18:48Z</dc:date>
    </item>
    <item>
      <title>Re: Help with layer file definition query in arcpy.mapping</title>
      <link>https://community.esri.com/t5/python-questions/help-with-layer-file-definition-query-in-arcpy/m-p/743788#M57499</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is it just the JPEGs that aren't displaying the layer correctly? Step through using mxd = arcpy.mapping.MapDocument("CURRENT"), if you haven't already. Try exporting to pdf or one of the other formats too and see if you get the same results.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Aug 2013 19:31:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-layer-file-definition-query-in-arcpy/m-p/743788#M57499</guid>
      <dc:creator>MattSayler</dc:creator>
      <dc:date>2013-08-20T19:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: Help with layer file definition query in arcpy.mapping</title>
      <link>https://community.esri.com/t5/python-questions/help-with-layer-file-definition-query-in-arcpy/m-p/743789#M57500</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hmmm, Must have been some hang up between Arcpy, Komodo, ArcGIS or Citrix.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;I tried to save the original mxd, got an error that the file location folder was in use.&amp;nbsp; After shutting ArcMap and Komodo down the original code worked fine.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Excellent!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Aug 2013 19:32:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-layer-file-definition-query-in-arcpy/m-p/743789#M57500</guid>
      <dc:creator>MattSayler</dc:creator>
      <dc:date>2013-08-20T19:32:25Z</dc:date>
    </item>
  </channel>
</rss>

