-1

I am trying to export a map layout to PDF from ArcGIS Pro file using arcpy.mp

Export is possible but layer extent is not coming properly.

Here is my code

x = ArcGISProject("ArcGIS Pro File Path")
my_layout = x.listLayouts()[0]
print(my_layout.name)
map1 = x.listMaps()[0]
mf = my_layout.listElements("MAPFRAME_ELEMENT")[0]
my_map2 = mf.map
mf.zoomToAllLayers()
map1.defaultCamera = mf.camera

x.save()
y = my_layout.exportToPDF("Pdf File Path")

` The output is coming like this

Pls click to see

What shall I change/add in my code to get the extent of the shapefile present in the map layout?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Megastar
  • 57
  • 11

1 Answers1

1

I tested your code and I suppose that what is causing this problem is this line:

mf.zoomToAllLayers()

Try creating another project, importing your layout and running your code without the zoomToAllLayers()

If you have any layer on your map and you want to center the map on it, you can try to set the extent like this:

mf.camera.setExtent(mf.getLayerExtent(lyr, False, True))

For more information: https://gis.stackexchange.com/questions/173687/choosing-and-zooming-to-features-using-sql-query-in-arcpy-with-arcgis-pro

  • Thank you for your answer. --> mf.camera.setExtent(mf.getLayerExtent(lyr, False, True)) But with this also, its not working. I just commented --> mf.zoomToAllLayers() ANd it worked with this --> map1.defaultCamera = mf.camera – Megastar Apr 09 '21 at 05:35