Arcpy.mp export layout missing the full view of the scale bar

717
3
Jump to solution
01-28-2023 10:21 PM
DongmeiChen
New Contributor II

Hello, 

I hope to get some help to export a layout using arcpy.mp with a full view of the scale bar and WITHOUT any manual steps. This is what the export should look like: 

MapExample.jpg

 But what I can get without manually saving a copy of the project looks like this:

Map.jpg

 It looks like the initial view of the layout when I open the ArcGIS Pro project and when the scale bar is not fully shown. There is a step to zoom-to-layer before the layout export.

aprx = arcpy.mp.ArcGISProject(path + "\\IllegalCampsMap.aprx")
lyt = aprx.listLayouts("Map*")[0]
mf = lyt.listElements("mapframe_element", "*")[0]
m = aprx.listMaps("Map")[0]
lyr = m.listLayers("Campsite")[0]
mf.camera.setExtent(mf.getLayerExtent(lyr, False, True))
lyt.exportToJPEG(path+"\\"+lyt.name+".jpg")

If I save the project manually after the zoom-to-layer with a different name, the export looks okay.

 aprx = arcpy.mp.ArcGISProject(path + "\\IllegalCampsView.aprx")
lyt = aprx.listLayouts("Map*")[0]
lyt.exportToJPEG(path+"\\"+lyt.name+".jpg")

I am trying to avoid the manual save step. I did try some workarounds including saving as a different project. Can anyone help explain the reason why I can't export the full layout view and offer a solution? Any feedback is much appreciated!!

 

0 Kudos
1 Solution

Accepted Solutions
DongmeiChen
New Contributor II

The solution is to set an extent for the point location before zooming to the layer.  

View solution in original post

0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

From here

Solved: Zoom to layer on the map view arcpy.mp - Esri Community

and the link with the discussion of the extent property

ArcGISProject—ArcGIS Pro | Documentation


... sort of retired...
0 Kudos
DongmeiChen
New Contributor II

Thanks for the follow-up, Dan. I read that post before posting the question and thought there might be solutions that have not been posted since the old post mentioned some potential changes in ArcGIS Pro 3.0 @JeffBarrette I am still exploring arcpy.mp and curious about the possible workaround mentioned last year by Jeff to create a map frame that is the same size of a layout. How do I do that? But this solution won't export the layout elements, right? I am only interested in running scripts/codes outside of the application. 

0 Kudos
DongmeiChen
New Contributor II

The solution is to set an extent for the point location before zooming to the layer.  

0 Kudos