Python script to export layout to JPG

1390
5
Jump to solution
11-05-2021 08:22 AM
LindaSlattery
New Contributor III

I am trying to find a script that exports my layout in ArcPro to a JPG once a week. Most of what I have found when searching has been for map series. Can anyone assist? Thanks!

1 Solution

Accepted Solutions
DominicRoberge2
Occasional Contributor II

Hi Linda

would this works for you?

import arcpy

docPath = r"D:\FOLDER"
docName = r"AGSPRODOC.aprx"
p = arcpy.mp.ArcGISProject(docPath+"\\"+docName)
# ge a list of all layouts in your map dox
lLayout = p.listLayouts()
for l in lLayout:
    print(l.name)
    #You could add an if statement to print ONLY a specific layout
    l.exportToJPEG(docPath+"\\"+l.name+"jpg")

print("Process Completed")

View solution in original post

5 Replies
JoeBorgione
MVP Esteemed Contributor

This help page seems to imply you can just export a single layout to just about whatever image format you like. The arcpy.mp module does takes a little getting used to.

That should just about do it....
DominicRoberge2
Occasional Contributor II

Hi Linda

would this works for you?

import arcpy

docPath = r"D:\FOLDER"
docName = r"AGSPRODOC.aprx"
p = arcpy.mp.ArcGISProject(docPath+"\\"+docName)
# ge a list of all layouts in your map dox
lLayout = p.listLayouts()
for l in lLayout:
    print(l.name)
    #You could add an if statement to print ONLY a specific layout
    l.exportToJPEG(docPath+"\\"+l.name+"jpg")

print("Process Completed")
LindaSlattery
New Contributor III

@DominicRoberge2 , this works great! Thank you! However, one thing it is not doing is including my dynamic text that I have in the layout. I have a date/time exported and a record count. Any idea how to get the print command to include those?

0 Kudos
DominicRoberge2
Occasional Contributor II

hummm I am not sure. it's working for me (see image below). Can you try to add a new dynamic txt for the count just for fun.

 

 

DominicRoberge2_0-1636383498020.png

 

LindaSlattery
New Contributor III

Thanks! That worked!!! Much appreciated! 

0 Kudos