arcpy batch to export PDF - problem of refresh mapframe in layout

398
3
03-10-2021 03:03 AM
Labels (2)
NatashaManzuiga
Occasional Contributor

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"))

 

 

 

 

 

Tags (3)
3 Replies
ElizabetJaneRoot
New Contributor II

I encountered the same issue. I would like to escalate the priority of this question.

0 Kudos
George_Thompson
Esri Frequent Contributor

If you need immediate assistance, I would recommend contacting Esri Technical Support to work with an analyst on this.

--- George T.
0 Kudos
ElizabetJaneRoot
New Contributor II

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.

0 Kudos