AnsweredAssumed Answered

ArcGIS Pro - Modifying Layer Definition query via ArcPY

Question asked by jan.rykr on Oct 8, 2019
Latest reply on Feb 25, 2020 by bixb0012

Let's say I need to add a new statement to an existing Def query to all layers in a group which would like like something like this:

aprx ="CURRENT")
m = aprx.listMaps("Map")[0]
for lyr in m.listLayers():
if lyr.supports ("longname"):
parent = lyr.longName.split('\\')

if parent [0] == "Group":
print (lyr.longName)
  if lyr.supports("DEFINITIONQUERY"):
   oldDefQuery = lyr.definitionQuery
   lyr.definitionQuery = None
   newDefQuery = oldDefQuery + " CODE = 0"
   lyr.definitionQuery = newDefQuery


What happens after running the script is that the old definition query becomes inactive and the newly created query is added and becomes active. However they both remain the same query name and seem to clash with each other so that no feature pass through the query (don't mind the fieldnames):

There seem to be no detailed explanation on the definitionQuery property at Layer—ArcPy | ArcGIS Desktop 

So the questions are: 

  • How to achieve this to work properly:
    • Modify the existing one? - This used to work in ArcMAP
    • Remove the initial query completely and place a new modified query?
  • Is there any documentation on how to control the functions in the definition query tab on layer properties via Arcpy?? 


Thanks heaps!