Select to view content in your preferred language

Retain Layer Definition Queries with Layout

742
3
08-18-2022 11:32 AM
JMitchell
Regular Contributor

Is it possible to retain definition query settings for layers on a map based on the layout?

I have a series of layouts that reference a single map that require changing the pre-defined definition query for several layers in order to match the content on the map to the desired layout mapframe extent.

The intended result can be achieved by making copies of the map itself and defining the definition queries for the layers uniquely for each copy, but then that means any change that might need to be made to the contents of the map would need to be done for each individual copy of the map.

I have specific layers on the map set up with 47 pre-defined definition queries that match up with a specific layout, so Layout 1 requires that Definition Query 1 be set for the specific layers on the map, then for Layout 2, the layers have to use Definition Query 2, etc.  However, because the definition query settings are only controlled by the map, I have to manually go through each layer and set them to use the correct definition query for the layout I am currently working with each time that I want to export to PDF.

A way to have the layouts retain the filtering settings configured on the map while working in each individual Layout would be amazing.

I do not know if this is something that is possible or can be achieved with some scripting when trying to export each Layout to PDF?

0 Kudos
3 Replies
JeffBarrette
Esri Regular Contributor

Hello JMitchell,

Have you considered using Python Map Automation?

https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/introduction-to-arcpy-mp.htm

It is an API that allows you to automate the contents of projects such as maps, layers, layouts and much more.

The devil is in the detail but here is a very generic script that exports a PDF for each unique set of DefQueries. The code obviously needs to be modified to work with your project/data and depending on your specific needs, more logic most likely needs to be added.

I hope this helps,

Jeff - Layout and arcpy.mp teams

p = arcpy.mp.ArcGISProject('current')
lyt = p.listLayouts('Yosemite National Park')[0]

#Build a list of definition queries
defQuery1 = "NAME = 'Arch Rock Entrance'"
defQuery2 = "NAME = 'Big Oak Flat Entrance'"
defQuery3 = "NAME = 'Hetch Hetchy Entrance'"
defQueryList = [defQuery1, defQuery2, defQuery3]

#Iterate through all the def queries for all the maps
#and update layer def queries IF one is present

for dq in defQueryList:
for m in p.listMaps():
for lyr in m.listLayers():
if lyr.supports("DEFINITIONQUERY"):
if lyr.definitionQuery != None:
lyr.definitionQuery = dq


#build unique outout name based on the defquery string
start = "NAME = '"
end = " Entrance'"
lytNamePath = "C:\\Temp\\" + (dq.split(start))[1].split(end)[0] + ".pdf"

#export to PDF before using the next def query
lyt.exportToPDF(lytNamePath)

0 Kudos
JeffBarrette
Esri Regular Contributor

Because the pasted code does NOT show indentation, which is critical for Python code blocks, here is a screen shot of the same code above.

Capture.PNG

0 Kudos
JMitchell
Regular Contributor

Hi Jeff,

 

I appreciate the suggestion and sample!  I will work with this and see what I can do.

 

Thanks,

0 Kudos