-
Notifications
You must be signed in to change notification settings - Fork 0
/
Batch_Def_Query_To_Group.py
35 lines (26 loc) · 1.19 KB
/
Batch_Def_Query_To_Group.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Created by Austin Beck | [email protected]
# Intended to be run in ArcGIS Pro Python Window (could change aprx.activemap if you want to run this in Notebook instead)
#------------USER INPUTS-----------------------------------------------------
group_layer_name = '' # Name of group that all layers will have def query applied to
query = "" #SQL query within double quotes. ex: "DFIRM_PANEL = '38089C0189F'"
#------------DO NOT EDIT BELOW THIS LINE---------------------------------------------
import arcpy
# Create project object
aprx = arcpy.mp.ArcGISProject("CURRENT")
# Create object for current map
map = aprx.activeMap
# reset variable
group_layer = None
# Check to ensure group_layer_name is in active map
for lyr in map.listLayers():
if lyr.isGroupLayer and lyr.name == group_layer_name:
group_layer = lyr
break
# Apply the definition query to each layer within the group
if group_layer:
for lyr in group_layer.listLayers():
if lyr.supports("DEFINITIONQUERY"):
lyr.definitionQuery = query
# Print the layer name and the applied definition query
print(f"Applied definition query to layer '{lyr.name}': {query}")
print('Done')