<?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: Use python to apply a definition query to an existing Layerfile. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/use-python-to-apply-a-definition-query-to-an/m-p/87101#M6806</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think this should do the trick.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The attached tool (removed: see attachment in post below) is already setup to be used in a model or on its own.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy

#Get parameters
lyrName = arcpy.GetParameterAsText(0)
defQuery = arcpy.GetParameterAsText(1)

lyr = arcpy.mapping.Layer(lyrName)
lyr.definitionQuery = defQuery

#Refresh ActiveView
arcpy.RefreshActiveView() 
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 23:19:58 GMT</pubDate>
    <dc:creator>BenjaminGale</dc:creator>
    <dc:date>2021-12-10T23:19:58Z</dc:date>
    <item>
      <title>Use python to apply a definition query to an existing Layerfile.</title>
      <link>https://community.esri.com/t5/python-questions/use-python-to-apply-a-definition-query-to-an/m-p/87100#M6805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I will start with I know nothing about python, other than I need it now.&amp;nbsp; I have created a simple model that uploads a xyz file to a sql table with a survey id, creates an event theme, saves that to a .lyr file, and applies symbology.&amp;nbsp; However, I need one more thing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need some python code that will allow me to apply a definition query to query a single survey id and i need to be able to make it a parameter with the model.&amp;nbsp; Can anyone help out with this?&amp;nbsp; Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 May 2012 10:12:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-python-to-apply-a-definition-query-to-an/m-p/87100#M6805</guid>
      <dc:creator>GregDreaper</dc:creator>
      <dc:date>2012-05-15T10:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: Use python to apply a definition query to an existing Layerfile.</title>
      <link>https://community.esri.com/t5/python-questions/use-python-to-apply-a-definition-query-to-an/m-p/87101#M6806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think this should do the trick.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The attached tool (removed: see attachment in post below) is already setup to be used in a model or on its own.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy

#Get parameters
lyrName = arcpy.GetParameterAsText(0)
defQuery = arcpy.GetParameterAsText(1)

lyr = arcpy.mapping.Layer(lyrName)
lyr.definitionQuery = defQuery

#Refresh ActiveView
arcpy.RefreshActiveView() 
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:19:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-python-to-apply-a-definition-query-to-an/m-p/87101#M6806</guid>
      <dc:creator>BenjaminGale</dc:creator>
      <dc:date>2021-12-10T23:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: Use python to apply a definition query to an existing Layerfile.</title>
      <link>https://community.esri.com/t5/python-questions/use-python-to-apply-a-definition-query-to-an/m-p/87102#M6807</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Perfect.&amp;nbsp; Exactly what I needed.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 May 2012 16:36:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-python-to-apply-a-definition-query-to-an/m-p/87102#M6807</guid>
      <dc:creator>GregDreaper</dc:creator>
      <dc:date>2012-05-15T16:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: Use python to apply a definition query to an existing Layerfile.</title>
      <link>https://community.esri.com/t5/python-questions/use-python-to-apply-a-definition-query-to-an/m-p/87103#M6808</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;As much was I thought this was going to work, it does not on layers that are not within a mxd or arcmap data frame.&amp;nbsp; It runs, but it does not update the layer file.&amp;nbsp; Can you help?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 May 2012 09:48:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-python-to-apply-a-definition-query-to-an/m-p/87103#M6808</guid>
      <dc:creator>GregDreaper</dc:creator>
      <dc:date>2012-05-16T09:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: Use python to apply a definition query to an existing Layerfile.</title>
      <link>https://community.esri.com/t5/python-questions/use-python-to-apply-a-definition-query-to-an/m-p/87104#M6809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Should be fixed now. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
#==========================
# DEFINITION QUERY
#==========================
# Benjamin Gale - May 2012
#==========================

import arcpy

#Get parameters
lyrName = arcpy.GetParameterAsText(0)
defQuery = arcpy.GetParameterAsText(1)

lyr = arcpy.mapping.Layer(lyrName)
lyr.definitionQuery = defQuery

#Refresh ActiveView
arcpy.RefreshActiveView()
#Save layer (will only occur if the layer is a .lyr file)
lyr.save()
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:20:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-python-to-apply-a-definition-query-to-an/m-p/87104#M6809</guid>
      <dc:creator>BenjaminGale</dc:creator>
      <dc:date>2021-12-10T23:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: Use python to apply a definition query to an existing Layerfile.</title>
      <link>https://community.esri.com/t5/python-questions/use-python-to-apply-a-definition-query-to-an/m-p/87105#M6810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Awesome!&amp;nbsp; Thanks Buddy!&amp;nbsp; You have made lives easier.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 May 2012 15:21:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-python-to-apply-a-definition-query-to-an/m-p/87105#M6810</guid>
      <dc:creator>GregDreaper</dc:creator>
      <dc:date>2012-05-16T15:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: Use python to apply a definition query to an existing Layerfile.</title>
      <link>https://community.esri.com/t5/python-questions/use-python-to-apply-a-definition-query-to-an/m-p/87106#M6811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;OK, so everything works great from Catalog or toolbox.&amp;nbsp; However when I publish to ArcGIS server I get this error, " Geoprocessing service initialization failed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Invalid parameter: Tool - Survey Loader Tool v2 : Parameter - Input : Data Type - Multiple Value."&amp;nbsp; I assume the ASCII 3D to Feature Class input parameter is causing this.&amp;nbsp; Does anyone know a work around?&amp;nbsp; Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 May 2012 15:38:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-python-to-apply-a-definition-query-to-an/m-p/87106#M6811</guid>
      <dc:creator>GregDreaper</dc:creator>
      <dc:date>2012-05-16T15:38:28Z</dc:date>
    </item>
  </channel>
</rss>

