<?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 Programmatically select layer definition query in ArcGIS Parcel Fabric Questions</title>
    <link>https://community.esri.com/t5/arcgis-parcel-fabric-questions/programmatically-select-layer-definition-query/m-p/1114999#M500</link>
    <description>&lt;P&gt;Parcel fabric has default definition queries Taxlot_lines - (RetiredByRecord Is NULL).&amp;nbsp; I have successfully added additional definition queries to support other business needs and can manually change between them.&amp;nbsp; Is there any way to change which definition query to use with Python.&amp;nbsp; Also I create a new definition query with the layer property but would rather not delete and create them all the time.&amp;nbsp; Especially when parcel fabric comes with some already.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DeanAnderson2_0-1636399086048.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/27007i4DA7035ED341E7CF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DeanAnderson2_0-1636399086048.png" alt="DeanAnderson2_0-1636399086048.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 08 Nov 2021 19:21:19 GMT</pubDate>
    <dc:creator>DeanAnderson2</dc:creator>
    <dc:date>2021-11-08T19:21:19Z</dc:date>
    <item>
      <title>Programmatically select layer definition query</title>
      <link>https://community.esri.com/t5/arcgis-parcel-fabric-questions/programmatically-select-layer-definition-query/m-p/1114999#M500</link>
      <description>&lt;P&gt;Parcel fabric has default definition queries Taxlot_lines - (RetiredByRecord Is NULL).&amp;nbsp; I have successfully added additional definition queries to support other business needs and can manually change between them.&amp;nbsp; Is there any way to change which definition query to use with Python.&amp;nbsp; Also I create a new definition query with the layer property but would rather not delete and create them all the time.&amp;nbsp; Especially when parcel fabric comes with some already.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DeanAnderson2_0-1636399086048.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/27007i4DA7035ED341E7CF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DeanAnderson2_0-1636399086048.png" alt="DeanAnderson2_0-1636399086048.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Nov 2021 19:21:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-parcel-fabric-questions/programmatically-select-layer-definition-query/m-p/1114999#M500</guid>
      <dc:creator>DeanAnderson2</dc:creator>
      <dc:date>2021-11-08T19:21:19Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically select layer definition query</title>
      <link>https://community.esri.com/t5/arcgis-parcel-fabric-questions/programmatically-select-layer-definition-query/m-p/1115188#M506</link>
      <description>&lt;P&gt;If you know the query names, you can do something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def change_definition_query(layer, query_name):
    """Changes the definition query of a layer in ArcGIS Pro.

    layer: arcpy.mp.Layer object, the layer that the query will be assigned to
    query_name: str, the name of the query that is assigned to the layer

    The query has to exist in the layer. If it doesn't, this function throws a ValueError.
    Calling this function with query_name=None will remove the active query.
    """
    cim = lyr.getDefinition('V2')
    query = None
    if query_name is not None:
        queries = cim.featureTable.definitionFilterChoices
        try:
            query = {q.name: q.definitionExpression for q in queries}[query_name]
        except KeyError:
            raise ValueError("Query '{}' not found!".format(query_name)) from None
    cim.featureTable.definitionExpression = query
    cim.featureTable.definitionExpressionName = query_name
    layer.setDefinition(cim)


lyr = arcpy.mp.ArcGISProject("current").activeMap.listLayers("Layer")[0]
change_definition_query(lyr, "Query 1")
change_definition_query(lyr, "DistanceNotNull")
change_definition_query(lyr, None)
change_definition_query(lyr, "ThisWillThrowAnError")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Nov 2021 07:42:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-parcel-fabric-questions/programmatically-select-layer-definition-query/m-p/1115188#M506</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-11-09T07:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically select layer definition query</title>
      <link>https://community.esri.com/t5/arcgis-parcel-fabric-questions/programmatically-select-layer-definition-query/m-p/1115242#M508</link>
      <description>&lt;P&gt;That is it!&amp;nbsp; Have not used CIM before so this is a great introduction to it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Nov 2021 13:54:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-parcel-fabric-questions/programmatically-select-layer-definition-query/m-p/1115242#M508</guid>
      <dc:creator>DeanAnderson2</dc:creator>
      <dc:date>2021-11-09T13:54:34Z</dc:date>
    </item>
  </channel>
</rss>

