<?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: Definition Query in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/definition-query/m-p/565763#M44302</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think you've just about got it. Try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;lyr.definitionQuery = '"CellSiteID" = \'%s\'' % pageName&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;The value in a definition query needs to be surrounded by single quotes. The backslashes tell Python to use the next character as part of the string.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 19 Apr 2012 12:50:16 GMT</pubDate>
    <dc:creator>BruceNielsen</dc:creator>
    <dc:date>2012-04-19T12:50:16Z</dc:date>
    <item>
      <title>Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/definition-query/m-p/565762#M44301</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I know this probably the upteenth time a question like this has been asked, but my non-programming mind can't seem to wrap its head around it..&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using data driven pages to plot towersites in an area.&amp;nbsp; Each page goes to a new site based on it's SiteID.&amp;nbsp; I only want the map to show the site that I'm currently on.&amp;nbsp; Presently, it shows all of the sites, some of which are very close to the current one.&amp;nbsp; I ran through a stand alone script and it went through fine without any errors, but it didn't return the definition query, so the exported png still had all the sites on each map.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;what am I doing wrong?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[HTML]# Workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy.mapping&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument("C:\GIS Data\Schuylkill\Validations.mxd")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mapLyr = arcpy.mapping.ListLayers(mxd, "Cell_Sites")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;carryElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT","Carriers")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# activate data driven pages&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ddp = mxd.dataDrivenPages&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pageNum = ddp.currentPageID&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print pageNum&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;contents = range(1,ddp.pageCount)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print contents&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# set active view to first ddp, then iterate through each page&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;while pageNum in contents:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "we got to the while statement"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # single out the one you are working on&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pageName = mxd.dataDrivenPages.pageRow.CellSiteID&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exporter = mxd.dataDrivenPages.pageRow.LDTProvider&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd, "Sites")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CurrentSite = arcpy.mapping.ListLayers(mxd, "Cell_Sites", df)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CurrentField = "CellSiteID"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management("F:\GIS Data\Schuylkill County\Schuylkill MasterData.gdb\Validations\Cell_Sites", "IndexSites")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == CurrentSite:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.definitionQuery = '"CellSiteID" = %s' % pageName[/HTML]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There is more after this, but for space conservation, I only pasted up to the def. query&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As an aside, if you get me to where I need to be with this, and it works, I'll happily name a variable after you in my next script! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Apr 2012 12:32:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/definition-query/m-p/565762#M44301</guid>
      <dc:creator>StephenKruzik</dc:creator>
      <dc:date>2012-04-19T12:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/definition-query/m-p/565763#M44302</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think you've just about got it. Try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;lyr.definitionQuery = '"CellSiteID" = \'%s\'' % pageName&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;The value in a definition query needs to be surrounded by single quotes. The backslashes tell Python to use the next character as part of the string.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Apr 2012 12:50:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/definition-query/m-p/565763#M44302</guid>
      <dc:creator>BruceNielsen</dc:creator>
      <dc:date>2012-04-19T12:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/definition-query/m-p/565764#M44303</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Or you can also do it with double quotes.&amp;nbsp; Either way, you'll need to use an escape character.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
lyr.definitionQuery = "\"CellSiteID\" = '%s'" % pageName
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:22:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/definition-query/m-p/565764#M44303</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2021-12-12T00:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/definition-query/m-p/565765#M44304</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;thanks all!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;it's working now.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and for anyone interested, since I know I'm going to constantly forget how many ",',/ I need, and where, I saved a python module that has the syntax pre-set.&amp;nbsp; It's just a single function, so cut and paste as needed.&amp;nbsp; All you need is the field, operator, and value. Feel free to use if it helps&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[HTML]def DQ(name, operator, value):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sql = "\"" + name + "\"" + operator + "'" +&amp;nbsp; value + "'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return sql[/HTML]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;just note that the value field is defined for a string, not an integer.&amp;nbsp; If you use this querying integers, you'll need to get rid of the 2 single quotes at the end.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Apr 2012 17:28:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/definition-query/m-p/565765#M44304</guid>
      <dc:creator>StephenKruzik</dc:creator>
      <dc:date>2012-04-23T17:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/definition-query/m-p/565766#M44305</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I saved a python module that has the syntax pre-set&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;What a neat idea! Your function can be easily tweaked up to work with all data sources (mdb's use brackets) using the arcpy [URL=&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/000v/000v0000004n000000.htm]AddFieldDelimiters[/URL" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/000v/000v0000004n000000.htm]AddFieldDelimiters[/URL&lt;/A&gt;&lt;SPAN&gt;] function. I also added a tweak to add quotes around strings and handle IS NULL constructions:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def BuildQuery(table, field, operator, value=None):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Generate a valid ArcGIS query expression
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; arguments
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; table - input feature class or table view
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; field - field name (string)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; operator - SQL operators ("=","&amp;lt;&amp;gt;", etc)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "IS NULL" and "IS NOT NULL" are supported
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value - query value (optional)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; examples
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;gt;&amp;gt;&amp;gt; BuildQuery("x.dat","FIELD1","=", "spam")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; u'"FIELD1" = \'spam\''
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;gt;&amp;gt;&amp;gt; BuildQuery("x.dat","FIELD1","&amp;gt;",42)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; u'"FIELD1" &amp;gt; 42'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BuildQuery(r"E:\tables.mdb\table1","PwsID","IS NOT NULL")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; u'[PwsID] IS NOT NULL'
&amp;nbsp;&amp;nbsp;&amp;nbsp; """
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Use correct field delimeter (depends on table type)
&amp;nbsp;&amp;nbsp;&amp;nbsp; # For 9.3, use "gp" instead of "arcpy" in the following line
&amp;nbsp;&amp;nbsp;&amp;nbsp; qfield=arcpy.AddFieldDelimiters(table,field)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # tweak value delimeter for different data types
&amp;nbsp;&amp;nbsp;&amp;nbsp; if type(value) == type("string"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # add single quotes around string values
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; qvalue = "'" + value + "'"
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif value == None:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # drop value when not specified (used for IS NULL, etc)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; qvalue = ""
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # numeric values are fine unmodified
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; qvalue = value
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; sql = "%s %s %s" % (qfield,operator,qvalue)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return sql.strip()
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A few helpful references for the good of the order&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Arc 10.0 help: &lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s50000002t000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;&lt;BR /&gt;Building a query expression &lt;/A&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000001r000000" rel="nofollow noopener noreferrer" target="_blank"&gt;Specifying a query in Python&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ArcGIS &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/forums/79-Map-Automation" rel="nofollow noopener noreferrer" target="_blank"&gt;Map Automation forum&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:22:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/definition-query/m-p/565766#M44305</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-12T00:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/definition-query/m-p/565767#M44306</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;ok, so I thought I had this, but after running through it I discovered a problem and can not for the life of me figure out what's wrong.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The definition query itself is running through fine, but it doesn't produce anything.&amp;nbsp; There is no change to the featurelcass.&amp;nbsp; After lots and lots of digging, I figured out it's within the defquery section of Arcpy itself.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I turned on Python's debugger, and when it gets to the def. query, it throws me an "AttributeError: 'unicode' object has no attribute '_arc_object'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm really unsure what it's looking for.&amp;nbsp; If I change it to string, it gives the same error, just with 'str' instead of unicode.&amp;nbsp; Is my featureclass not being referenced properly, does it not like variables within the query?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;here's the snippet that I'm running through...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[HTML]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;while pageNum in contents:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pageName = mxd.dataDrivenPages.pageRow.CellSiteID # data driven page name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exporter = mxd.dataDrivenPages.pageRow.LDTProvider # which carrier you are on right now&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd, "Sites")[0] # there's 2 data frames, so call the 1st one&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CurrentSite = arcpy.mapping.ListLayers(mxd,"*Cell_Sites*",df) # get the list of current layers&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; LayerSite = CurrentSite[0] # pull Current site out of the list as its own layer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CurrentField = "CellSiteID" # field used to isolate the F.class&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Othercarriers = arcpy.MakeFeatureLayer_management("F:\GIS Data\Schuylkill County\Schuylkill MasterData.gdb\Validations\Cell_Sites", "IndexSites")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sql = dquery.DQ(CurrentField,"=",pageName)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; check = LayerSite.supports("DEFINITIONQUERY")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print check&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; LayerSite.definitionQuery = str(sql)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()[/HTML]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;the variable for sql is using the function I defined in my previous post (though I definitely like the newer, more robust version).&amp;nbsp; Some other baseinfo: I have a featureclass called "Cell_Sites".&amp;nbsp; The CellsiteID is the field driving the dd pages.&amp;nbsp; For each map, I only want the current cell site displayed on the map, and no others.&amp;nbsp; Any help is greatly appreciated.&amp;nbsp; I'm at my wits end here.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Apr 2012 14:20:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/definition-query/m-p/565767#M44306</guid>
      <dc:creator>StephenKruzik</dc:creator>
      <dc:date>2012-04-30T14:20:37Z</dc:date>
    </item>
    <item>
      <title>Re: Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/definition-query/m-p/565768#M44307</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&amp;nbsp; If I change it to string, it gives the same error, just with 'str' instead of unicode. &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Unless you're using international characters, string and unicode are really the same thing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What's the contents of the sql variable? The best way to get an exact story is to use repr:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-family:&amp;quot;Courier New&amp;quot;;"&gt;print repr(sql)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Apr 2012 14:36:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/definition-query/m-p/565768#M44307</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2012-04-30T14:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/definition-query/m-p/565769#M44308</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;when using print repr(sql),&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[HTML]&amp;gt;&amp;gt;&amp;gt; print repr(sql)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;u'"CellSiteID"=\'1202\''&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; [/HTML]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;in the Python Shell window.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;so the variables are definitely calling correctly, as that's what I expect to see.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;that line is then getting passed on to the definition query itself.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 May 2012 10:38:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/definition-query/m-p/565769#M44308</guid>
      <dc:creator>StephenKruzik</dc:creator>
      <dc:date>2012-05-01T10:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/definition-query/m-p/565770#M44309</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I highly recommend putting spaces in there.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2012 15:00:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/definition-query/m-p/565770#M44309</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2012-05-02T15:00:55Z</dc:date>
    </item>
    <item>
      <title>Re: Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/definition-query/m-p/565771#M44310</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;no dice.&amp;nbsp; It's still throwing the same error.&amp;nbsp; I have to believe it was simply syntax, then it would have still put it in, and just throw up a "failed to draw: invalid sql reference" error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I actually tried up to this point with ArcMap open.&amp;nbsp; I changed the mxd to CURRENT, and when I got to the def query, again, it went through without giving any errors, but when I click on the featureclass, the def. query box is empty as though nothing happened.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is actually why I went into the python debugger and stepped through the Arcpy module itself.&amp;nbsp; That is where I found the "AttributeError: object has no attribute '_arc_object'"&amp;nbsp; error being called.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2012 17:06:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/definition-query/m-p/565771#M44310</guid>
      <dc:creator>StephenKruzik</dc:creator>
      <dc:date>2012-05-02T17:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: Definition Query</title>
      <link>https://community.esri.com/t5/python-questions/definition-query/m-p/565772#M44311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&amp;nbsp; That is where I found the "AttributeError: object has no attribute '_arc_object'"&amp;nbsp; error being called.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Looking at the error message, I'm wondering if it's recognizing your layer LayerSite - though you'd think it would fail on your check&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;check = LayerSite.supports("DEFINITIONQUERY")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Might want to run this one by support.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2012 17:26:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/definition-query/m-p/565772#M44311</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2012-05-02T17:26:21Z</dc:date>
    </item>
  </channel>
</rss>

