Select to view content in your preferred language

Refresh Map during export layout as PDF using python script

327
6
07-20-2024 11:15 AM
MohamedHassan17
New Contributor II

I have a python script that querying some values and appending them to Layout. I'm applying symbology, labeling, and definition query. the script running well, but when exporting to PDF the symbology and labeling don't appears.

Although when I zoom in or out from the layout all appears.

the first image from the map (with labeling &symbology)
the second image from the layout (without labeling &symbology)

First ImageFirst Image

 

 

 

 

 

second imagesecond image

 

 

 

 

 

 

0 Kudos
6 Replies
RhettZufelt
MVP Notable Contributor

Are you saving the map after the updates, symbology, etc. but before the PDF export?

R_

0 Kudos
TonyAlmeida
Occasional Contributor III

 

Maybe add,

time.sleep(4) ensures that all changes have time to be fully applied before exporting to PDF.

import arcpy
import time

# Define your project and layout
aprx = arcpy.mp.ArcGISProject("CURRENT")
layout = aprx.listLayouts()[0]

# Define your map frame and map
map_frame = layout.listElements("MAPFRAME_ELEMENT")[0]
map_view = map_frame.map
layer = map_view.listLayers()[0]  # Modify as per your layer

# Refresh the map view
map_frame.camera.setExtent(map_frame.camera.getExtent())  # Trigger a refresh by resetting the extent

# Wait for a moment to ensure all changes are applied
time.sleep(4)

# Export to PDF
output_pdf = r"path_to_your_output.pdf"
layout.exportToPDF(output_pdf)

 

0 Kudos
MohamedHassan17
New Contributor II

Yes, I did but not working.

0 Kudos
TonyAlmeida
Occasional Contributor III

Maybe increase the sleep time.

0 Kudos
MohamedHassan17
New Contributor II

the issue still occurred.

0 Kudos
TonyAlmeida
Occasional Contributor III

Maybe convert labels to annotation using, arcpy.cartography.ConvertLabelsToAnnotation, before the export.

0 Kudos