exportToPDF missing elements

480
2
Jump to solution
06-28-2021 10:19 AM
AliciaShyu
Occasional Contributor

I wrote a script that exports a title page and a map series. When I run the script manually in PyCharm, the title page exports correctly.

When I set up the script to run in windows task scheduler, the title page exports without the map frame (see image below)

Title Page.png

 

Has anyone come across this and is there a way to fix it?

Here's the code that exports the title page and map series.

proProject = "\\\\Scripts\\Python\\MapBook\\MapBook.aprx"
PDFDir = "\\\\Scripts\\Python\\MapBook\\Output"
p = arcpy.mp.ArcGISProject(proProject)

    try:
        # Export new title page to pdf
        TitleFile = PDFDir + "\\TitlePage.pdf"
        tLayout = p.listLayouts("TitlePage")[0]
        tLayout.exportToPDF(TitleFile)
        print("Exported new title page " + "\n" + arcpy.GetMessages())
        mylog.write("Exported new title page" +"\n")
    except:
        message = arcpy.GetMessages()
        print(message)
        mylog.write("Error exporting new title page" + message + "\n")
        arcpy.AddMessage(message)
        mylog.write("Processing Aborted...." + "\n")
        sys.exit("Processing Aborted..")

    try:
        # Export new map book pages to pdf
        MBfile = PDFDir + "\\MapPages.pdf"
        mbLayout = p.listLayouts("MapPages")[0]
        mapSeries = mbLayout.mapSeries
        if mapSeries.enabled:
            mapSeries = mbLayout.mapSeries
            mapSeries.refresh()
            mapSeries.exportToPDF(MBfile)
        print("Exported new map pages" + "\n" + arcpy.GetMessages())
        mylog.write("Exported new new map pages" +"\n")
    except:
        message = arcpy.GetMessages()
        print(message)
        mylog.write("Error exporting new map pages" + message + "\n")
        arcpy.AddMessage(message)
        mylog.write("Processing Aborted...." + "\n")
        sys.exit("Processing Aborted..")

 

0 Kudos
1 Solution

Accepted Solutions
AliciaShyu
Occasional Contributor

The issue was that the grid was in a database outside of the Pro project. Once the grid was moved to Pro project, the script ran correctly in task scheduler.

View solution in original post

2 Replies
jcarlson
MVP Notable Contributor

I've not come across this, but it would be helpful if we could see some of the code being run.

- Josh Carlson
Kendall County GIS
0 Kudos
AliciaShyu
Occasional Contributor

The issue was that the grid was in a database outside of the Pro project. Once the grid was moved to Pro project, the script ran correctly in task scheduler.