Select to view content in your preferred language

Delete definitionQuery different from 2.83 to 2.9

656
2
04-05-2022 09:24 AM
DeanAnderson2
Occasional Contributor II

Been using 2.8 for a bit and have had no problem clearing definition queries with the following code.  If TurnQueryOn is true it sets the definition query. If it is false it sets definition query to None.  

 if TurnQueryOn:  
                RecordWhereClause = "CreatedByRecord = " + "'" + RecordNumber + "'"
                for FilterLayer in FilterLayers:
                    mapFilterLyr = Map.listLayers(FilterLayer)[0]
                    if mapFilterLyr.isFeatureLayer:
                        mapFilterLyr.definitionQuery = RecordWhereClause                                        
            else:
                for FilterLayer in FilterLayers:  
                    mapFilterLyr = Map.listLayers(FilterLayer)[0]
                    if mapFilterLyr.isFeatureLayer:
                        mapFilterLyr.definitionQuery = None

I just upgraded to 2.9 (I still have a machine 2.83 so was able to double check).  But the definition queries are no longer being deleted but just turns them to "inactive".   

DeanAnderson2_0-1649175706326.png

Is there something I am doing wrong?  (I have seen other posts for this in the past and they appear to operate the same as mine does in 2.83.) 

 

0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

2.9 Layer—ArcGIS Pro | Documentation

2.8 Layer—ArcGIS Pro | Documentation

differences in the descriptions can be compared between the two


... sort of retired...
0 Kudos
DeanAnderson2
Occasional Contributor II

Sorry found some code elsewhere.  The following will remove all definition queries from a layer.  In this case the layer is called "Anno0200Scale" as follows: 

import arcpy

aprx = arcpy.mp.ArcGISProject("CURRENT")
Map = aprx.activeMap
Lyr = Map.listLayers("Anno0200Scale")[0]


Lyr_cim = Lyr.getDefinition('V2')

fTab = Lyr_cim.featureTable
fTab.definitionFilterChoices = None

Lyr.setDefinition(Lyr_cim)

I am not sure if this is the best way to do it but it does it.  Please let me know if there are better ways. 

 

Thanks