<?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: setting layer definition query issue in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/setting-layer-definition-query-issue/m-p/772891#M710</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mike,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A couple of things.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Firstly you can continue to set the definition query on a layer by using the layer.SetDefinition call. It is saved and it will filter the layer records.&amp;nbsp; &amp;nbsp; Test this by using the API to set an expression similar to 'OBJECTID &amp;gt; 5' and open the attribute table for that layer and see that not all your records are displayed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is a bug in the DefinitionQuery tab on the Layer properties dialog which is not correctly displaying&amp;nbsp;the definition query when you use the 'SetDefinition' call.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This dialog (which changed at V2.3 to allow multiple definition queries)&amp;nbsp; now uses the DefinitionFilter properties as you suspected.&amp;nbsp; &amp;nbsp;You can access the CIM definition for the layer to set theses properties.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the code snippet which will assign a new filter and make it the default&amp;nbsp; &amp;nbsp;- this can replace your call to SetDefinition if you require.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;// must run on the MCT - use QueuedTask.Run&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// get the CIM layer definition&lt;BR /&gt; var layerDef = fLayer.GetDefinition() as CIMFeatureLayer;&lt;BR /&gt; // get the table for the layer&lt;BR /&gt; var featureTable = layerDef.FeatureTable;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// get the current set of definition filters&lt;BR /&gt; var filters = featureTable.DefinitionFilterChoices?.ToList();&lt;BR /&gt; // they might be null, so create a new list&lt;BR /&gt; if (filters == null)&lt;BR /&gt;&amp;nbsp; &amp;nbsp;filters = new List&amp;lt;CIMDefinitionFilter&amp;gt;();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// create a new filter&lt;BR /&gt; var filter = new CIMDefinitionFilter();&lt;BR /&gt; filter.Name = "my filter";&lt;BR /&gt; filter.DefinitionExpression = newExpression;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// add to the&amp;nbsp;list&lt;BR /&gt; filters.Add(filter);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// assign filters back to the CIMDisplayTable&lt;BR /&gt; featureTable.DefinitionFilterChoices = filters.ToArray();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// also set DefinitionExpression, DefinitionExpressionName&lt;BR /&gt; // - these define the active definition filter&lt;BR /&gt; featureTable.DefinitionExpression = filter.DefinitionExpression;&lt;BR /&gt; featureTable.DefinitionExpressionName = filter.Name;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// write back to the CIM layer definition&lt;BR /&gt; fLayer.SetDefinition(layerDef);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for pointing out the bug with the SetDefinition call and the layer properties dialog.&amp;nbsp; We will be addressing this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We will also work on updating the images in the sample to reflect the changes made to the dialog.&amp;nbsp; And updating the sample to reflect the changes made at V2.3 to use DefinitionFilters.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Narelle&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 28 Jan 2019 19:35:58 GMT</pubDate>
    <dc:creator>NarelleChedzey</dc:creator>
    <dc:date>2019-01-28T19:35:58Z</dc:date>
    <item>
      <title>setting layer definition query issue</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/setting-layer-definition-query-issue/m-p/772889#M708</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;trying to set a definition query I typically do something like:&lt;/P&gt;&lt;P&gt;lyr.SetDefinitionQuery("ProjNum = 'S100075'");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now however we seem&amp;nbsp;to have a collection.&amp;nbsp; When I set the query like above it seems to work although the definition query is empty.&amp;nbsp; Is there another method in the SDK&amp;nbsp;to create a "New definition query" to handle this? I would imagine each definition query would have a name property, definition&amp;nbsp;property,&amp;nbsp;an is active property.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I look forward to your response as my code a lot of these calls.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Jan 2019 20:36:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/setting-layer-definition-query-issue/m-p/772889#M708</guid>
      <dc:creator>mikeharol</dc:creator>
      <dc:date>2019-01-25T20:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: setting layer definition query issue</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/setting-layer-definition-query-issue/m-p/772890#M709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So I thought I could be clearer on my question since there has been no response.&amp;nbsp; I am working with the new SDK 2.3.&amp;nbsp; I have looked at the new sample QueryBuilderControl.&amp;nbsp; The screenshots show the old definition control which is confusing.&amp;nbsp; It did provide some insight into the CIMDefinitionFilter.&amp;nbsp;&lt;BR /&gt;DefinitionFilter {ArcGIS.Core.CIM.CIMDefinitionFilter} ArcGIS.Core.CIM.CIMDefinitionFilter&lt;BR /&gt;DefinitionFilterChoices {ArcGIS.Core.CIM.CIMDefinitionFilter[0]} ArcGIS.Core.CIM.CIMDefinitionFilter[]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not able to figure out how to put this information in my feature layer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 26 Jan 2019 18:21:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/setting-layer-definition-query-issue/m-p/772890#M709</guid>
      <dc:creator>mikeharol</dc:creator>
      <dc:date>2019-01-26T18:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: setting layer definition query issue</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/setting-layer-definition-query-issue/m-p/772891#M710</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mike,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A couple of things.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Firstly you can continue to set the definition query on a layer by using the layer.SetDefinition call. It is saved and it will filter the layer records.&amp;nbsp; &amp;nbsp; Test this by using the API to set an expression similar to 'OBJECTID &amp;gt; 5' and open the attribute table for that layer and see that not all your records are displayed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is a bug in the DefinitionQuery tab on the Layer properties dialog which is not correctly displaying&amp;nbsp;the definition query when you use the 'SetDefinition' call.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This dialog (which changed at V2.3 to allow multiple definition queries)&amp;nbsp; now uses the DefinitionFilter properties as you suspected.&amp;nbsp; &amp;nbsp;You can access the CIM definition for the layer to set theses properties.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the code snippet which will assign a new filter and make it the default&amp;nbsp; &amp;nbsp;- this can replace your call to SetDefinition if you require.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;// must run on the MCT - use QueuedTask.Run&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// get the CIM layer definition&lt;BR /&gt; var layerDef = fLayer.GetDefinition() as CIMFeatureLayer;&lt;BR /&gt; // get the table for the layer&lt;BR /&gt; var featureTable = layerDef.FeatureTable;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// get the current set of definition filters&lt;BR /&gt; var filters = featureTable.DefinitionFilterChoices?.ToList();&lt;BR /&gt; // they might be null, so create a new list&lt;BR /&gt; if (filters == null)&lt;BR /&gt;&amp;nbsp; &amp;nbsp;filters = new List&amp;lt;CIMDefinitionFilter&amp;gt;();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// create a new filter&lt;BR /&gt; var filter = new CIMDefinitionFilter();&lt;BR /&gt; filter.Name = "my filter";&lt;BR /&gt; filter.DefinitionExpression = newExpression;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// add to the&amp;nbsp;list&lt;BR /&gt; filters.Add(filter);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// assign filters back to the CIMDisplayTable&lt;BR /&gt; featureTable.DefinitionFilterChoices = filters.ToArray();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// also set DefinitionExpression, DefinitionExpressionName&lt;BR /&gt; // - these define the active definition filter&lt;BR /&gt; featureTable.DefinitionExpression = filter.DefinitionExpression;&lt;BR /&gt; featureTable.DefinitionExpressionName = filter.Name;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// write back to the CIM layer definition&lt;BR /&gt; fLayer.SetDefinition(layerDef);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for pointing out the bug with the SetDefinition call and the layer properties dialog.&amp;nbsp; We will be addressing this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We will also work on updating the images in the sample to reflect the changes made to the dialog.&amp;nbsp; And updating the sample to reflect the changes made at V2.3 to use DefinitionFilters.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Narelle&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jan 2019 19:35:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/setting-layer-definition-query-issue/m-p/772891#M710</guid>
      <dc:creator>NarelleChedzey</dc:creator>
      <dc:date>2019-01-28T19:35:58Z</dc:date>
    </item>
    <item>
      <title>Re: setting layer definition query issue</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/setting-layer-definition-query-issue/m-p/772892#M711</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So the code worked great, I will need to modify as you can see it keeps&lt;/P&gt;&lt;P&gt;adding to the query in my situation I will start from a new&lt;/P&gt;&lt;P&gt;List();  Easy enough.  I will look forward to the fix.&lt;/P&gt;&lt;P&gt;For clarity, it looks to me that the last SetDefinition(layerDef) plays a&lt;/P&gt;&lt;P&gt;role in what the active definition is.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jan 2019 22:09:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/setting-layer-definition-query-issue/m-p/772892#M711</guid>
      <dc:creator>mikeharol</dc:creator>
      <dc:date>2019-01-28T22:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: setting layer definition query issue</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/setting-layer-definition-query-issue/m-p/772893#M712</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks that did the trick.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jan 2019 22:10:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/setting-layer-definition-query-issue/m-p/772893#M712</guid>
      <dc:creator>mikeharol</dc:creator>
      <dc:date>2019-01-28T22:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: setting layer definition query issue</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/setting-layer-definition-query-issue/m-p/772894#M713</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So I refactored a little sticking it in a method and creating a &lt;SPAN&gt;&amp;nbsp;new List&amp;lt;CIMDefinitionFilter&amp;gt;();&lt;/SPAN&gt;, here is&amp;nbsp;the code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;private void SetLayerDefinition(FeatureLayer fLayer, string defExpression)&lt;BR /&gt;{&lt;BR /&gt;var layerDef = fLayer.GetDefinition() as CIMFeatureLayer;&lt;BR /&gt;var featureTable = layerDef.FeatureTable;&lt;BR /&gt;//var filters = featureTable.DefinitionFilterChoices?.ToList();&lt;BR /&gt;//if (filters == null)&lt;BR /&gt;// filters = new List&amp;lt;CIMDefinitionFilter&amp;gt;();&lt;/P&gt;&lt;P&gt;var filters = new List&amp;lt;CIMDefinitionFilter&amp;gt;();&lt;/P&gt;&lt;P&gt;var filter = new CIMDefinitionFilter&lt;BR /&gt;{&lt;BR /&gt;Name = "my filter",&lt;BR /&gt;DefinitionExpression = defExpression&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;filters.Add(filter);&lt;BR /&gt;featureTable.DefinitionFilterChoices = filters.ToArray();&lt;BR /&gt;featureTable.DefinitionExpression = filter.DefinitionExpression;&lt;BR /&gt;featureTable.DefinitionExpressionName = filter.Name;&lt;/P&gt;&lt;P&gt;// write back to the CIM layer definition&lt;BR /&gt;fLayer.SetDefinition(layerDef);&lt;BR /&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jan 2019 22:23:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/setting-layer-definition-query-issue/m-p/772894#M713</guid>
      <dc:creator>mikeharol</dc:creator>
      <dc:date>2019-01-28T22:23:00Z</dc:date>
    </item>
  </channel>
</rss>

