Hi, I am looking for examples how to use displayfilters in arcpy. Found only answers about definitionqueries...
Thanks for your help, Christoph
Doesn't seem like there is a direct way to control Display Filter from arcpy.
However, you may find this post helpful Solved: Controlling Pro Display Filters with arcpy - Esri Community
Ta,
AB
Hi AB, thanks, but I saw this already. I need the full layer defined and only want to filter the visibility of certan features. With the definitionquery it would be possible with serveral workarounds ... displayfilter would be very usefull to manage by arcpy.
Best Regards, Christoph
You can get and set them via the CIM.
# get the layer
aprx = arcpy.mp.ArcGISProject("current")
layer = aprx.activeMap.listLayers("LayerName")[0]
# get the layer's cim
cim = layer.getDefinition("V3")
# create a new display filter
new_filter = arcpy.cim.CIMVectorLayers.CIMDisplayFilter()
new_filter.whereClause = "Your query here"
# set the CIM's displayFilters attribute and apply the CIM to the layer
cim.displayFilters = [new_filter]
layer.setDefinition(cim)
# to remove all filters:
cim.displayFilters = []
layer.setDefinition(cim)
Prepare a layer with display queries and get it's CIM to play around with the relevant attributes:
The CIMVectorLayers are undocumented, at least from the ArcPy perspective. One can consult the ArcGIS Pro SDK documentation to read about that part of the CIM model, so I don't consider CIMVectorLayers completed undocumented. And, I have definitely used completely undocumented portions of ArcPy and other Esri APIs, so I support people sharing such solutions as long as they note the undocumented aspect of the solution.
I initially marked this response as a solution; however, I found using CIMVectorLayers quite buggy when testing the approach. The behaviors were inconsistent enough that I unmark it.