Dear Everybody, I'm trying to make a batch to export PDF from ArcGIS Pro.
Before I export PDF I need to set definition query for each layers based on values in a table.
Then, there is the export but what I'm getting is always a blank PDF, it looks like it's not refreshing after I set the new extent.
After the script, of course, the layout show me the last extent I set....and it's correct!
Thanks in advance,
project = arcpy.mp.ArcGISProject("CURRENT")
layout = project.listLayouts("Layout")[0]
mapframe = layout.listElements("MAPFRAME_ELEMENT", "Map Frame")[0]
mapLayers = project.listMaps("Layers")[0]
fields=['field1', 'field2', 'field3', 'field4', 'field5']
search_cursor=arcpy.da.SearchCursor("theTable",fields)
for row in search_cursor:
print(u'{0}, {1}, {2}'.format(row[0], row[1], row[2]))
queryStr="MAPID="+str(row[0])
for lyr in mapLayers.listLayers():
if lyr.supports("DEFINITIONQUERY"):
lyr.definitionQuery = queryStr
layer=mapLayers.listLayers("l")[0]
print(u'{0}, {1}, {2}, {3}'.format(row[0], row[1], row[2], queryStr))
layer_extent = mapframe.getLayerExtent(layer, False, False)
mapframe.camera.setExtent(layer_extent)
layout.exportToPDF(os.path.join(r"D:\test", f"{row[1]}.pdf"))
I encountered the same issue. I would like to escalate the priority of this question.
If you need immediate assistance, I would recommend contacting Esri Technical Support to work with an analyst on this.
Thanks @George_Thompson
Fortunately, I solved the issue.
@NatashaManzuiga ,
for your case, you need to probably add the layer to the map like below like map.addLayer(layerObject or path)
Please note that you should not do that within function scope but only global scope.
I'm having this same issue. How did you resolve this?
I found that my code works as expected if executed as a python notebook in pro, but if I try to run in the python window, I get the mysterious empty layout.
The layer I would like to display on the layout is already in the map, so I don't think ElizabethJaneRoot's comment applied.