3

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?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Nov 21, 2023 at 8:16
0

1 Answer 1

4

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()
answered Nov 21, 2023 at 10:40
2
  • 1
    Thank you! This worked. Allthough i had to remove the ' "excludePages" : False ' part of the code. Looking at the lyrx file was a good suggestion. Commented Nov 21, 2023 at 11:36
  • Great stuff. excludePages is probably only needed if you are setting to True. Thanks for the feedback. Commented Nov 21, 2023 at 12:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.