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?

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()
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.
    – Julia
    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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.