I am trying to automate a process in ArcGIS pro using python. In this process I create several maps using a map series. I use a page query to filter my data based on the map series page name.
I can't figure out how to turn on the page query using python.
Is there any way to use page queries with a python function?
1 Answer 1
Use Python CIM access as described below. A handy way to see what you want to update is to set it manually, then export the layer to lyrx and open the lyrx in a notepad to view the JSON.
## access your aprx
aprx = arcpy.mp.ArcGISProject("CURRENT")
## access the layout
layout = aprx.listLayouts("Layout Name")[0] # update your layout name
## access the mapframe
mapframe = layout.listElements ("MAPFRAME_ELEMENT", "MapFrame Name")[0] # update your mapframe name
## access the layer to update Page Query for
lyr = mapframe.map.listLayers("Layer Name")[0] # update your layer name
## get the CIM definition (like JSON)
lyr_cim = lyr.getDefinition('V3')
## update the pageDefinition
lyr_cim.pageDefinition = {"type" : "CIMPageDefinition","pageFieldName" : "FIELD NAME", "excludePages" : False} # update FIELD NAME, set excludePages to True or False
## update the lyr CIM definition
lyr.setDefinition(lyr_cim)
## save your aprx
aprx.save()
-
1Thank you! This worked. Allthough i had to remove the ' "excludePages" : False ' part of the code. Looking at the lyrx file was a good suggestion.Julia– Julia2023年11月21日 11:36:46 +00:00Commented Nov 21, 2023 at 11:36
-
Great stuff. excludePages is probably only needed if you are setting to True. Thanks for the feedback.Clubdebambos– Clubdebambos2023年11月21日 12:19:08 +00:00Commented Nov 21, 2023 at 12:19
Explore related questions
See similar questions with these tags.