I was able to get this method to work as well. For context: I am running script tools that allow users to set and clear definition queries for multiple layers. When setting, they select a value from a drop down list and run the script which creates and applies the query with their selected value to all the relevant layers. When clearing, they simply run the script tool and all definition queries are cleared from the relevant layers.
Here is an example of the syntax I used for clearing queries. I am into an issue where it gave an error if the layer didn't already have a DQ on it, so it couldn't overwrite it. So I check for existing DQs first, if there is one, I overwrite it, if there isn't one, I create and apply one.
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.activeMap
lyrs = m.listLayers()
for lyr in lyrs:
if lyr.name in ('TEST_PT', 'TEST_LINE', 'TEST_POLY'):
cim_layer = lyr.getDefinition('V2')
if cim_layer.featureTable.definitionFilterChoices:
cim_layer.featureTable.definitionFilterChoices[0].definitionExpression = None
cim_layer.featureTable.definitionExpression = None
else:
cim_layer.featureTable.definitionExpression = None
lyr.setDefinition(cim_layer)
Doing it this way allowed me to create, apply, and clear definition queries without creating a massive list of deactivated queries for each layer. Hope this helps others.