exportToPDF hangs in arcgis pro 2.8 running from toolbox .tbx

1476
13
Jump to solution
05-28-2021 08:45 AM
Labels (1)
IanAlexander
New Contributor II

I have an toolbox .tbx running a python / arcpy script that exports the layout to PDF and EPS .  This toolbox worked in 2.7 , but now hangs in 2.8 .  The lines it hangs on is:

the_layout.exportToPDF("C:\\temp\\test.pdf")

The same issue also occurs on:

the_layout.exportToPDF("C:\\temp\\now.pdf")

No exceptions are caught, the application just spins and does not return from the method call. Pressing cancel on the running toolbox does not stop this.  Only killing the application in the task manager exits this. Oddly, the PDF file is created.

In the python window, the following code works as expected and does not hang:

aprx = arcpy.mp.ArcGISProject("current")
the_layout = aprx.listLayouts("letter_portrait")[0]
the_layout.exportToPDF("C:\\temp\\now.pdf")

1 Solution

Accepted Solutions
JeffBarrette
Esri Regular Contributor

This is going to be addressed in the 2.8.2 patch.

 

Jeff - arcpy.mp and Layout teams

View solution in original post

13 Replies
JeffBarrette
Esri Regular Contributor

Ian,

I can NOT reproduce this issue using the code you have above.  Can you reproduce with other layouts in other projects?  Is there something unique about the project, the data, do you have multiple layouts with the same name, etc?

0 Kudos
IanAlexander
New Contributor II

Jeff,

       The layout creates correctly, and the code works in the python window.  It is only when it is run through a toolbox (.tbx) that it hangs on exportToPDF (after the layout has already been successfully created). There are no duplicate layout names. The toolbox can be brought into any 2.8 project, and will fail/hang.  The toolbox can be brought into any 2.7 project, and it will succeed. 

JeffBarrette
Esri Regular Contributor

Ian, I can NOT reproduce, even on 2.8 final.  Just to be clear, I've created a script tool in a toolbox (tbx) that has no parameters and runs your 3 lines of code.

Again, can you reproduce this issue with other projects / layouts?  I could be data specific.  In these cases it makes the most sense to open an Esri support instance where they have the resources to help you diagnose the problem.

 

Jeff = Layout and arcpy.mp teams

0 Kudos
IanAlexander
New Contributor II

Jeff,

      Thank you for the note.  You are correct.  When I create a simple tbx with the three line script, I am unable to get the script to hang.  Unfortunately, the PDF that is created shows the layout elements, but the map is blank / missing. 

I will work to get a concrete example that results in the hanging I am experiencing with my existing production toolbox.

 

Thank you,

Ian

JeffBarrette
Esri Regular Contributor

Ian, the map not displaying is an interesting clue.  If your steps are clear and reproducible and you can produce a project package (ppkx), you are welcome to send it directly to me (jbarrette@esri.com).

Jeff

0 Kudos
JeffBarrette
Esri Regular Contributor

Ian, we might have found the cause.  Do you have any layers with labels that use simple or advanced Python expressions?  A customer just reported they are having a similar hang as you and turning off the labeled or changing the expression engine (eg., to Arcade) allows export.

 

Jeff - Layout and arcpy.mp teams

0 Kudos
IanAlexander
New Contributor II

Jeff,

      Thank you for the note.  The labels are all Arcade expressions.  I simplified the expressions and turned off the labeling:
the_layer.showLabels = False

Unfortunately, exportToPDF still hangs.

Thank you,

Ian

JeffBarrette
Esri Regular Contributor

That is unfortunate.  I hoped we had a solution.  2 others have confirmed my findings.  The best thing to do is to somehow get a reproducible case to technical support so your situation can be evaluated.

 

Jeff

0 Kudos
IanAlexander
New Contributor II

Jeff,

       I found a work around for now.  Adding a sleep for 3 seconds prior to running the export allows the export to run correctly (sleeping for 1 second still hangs).

time.sleep(3)

 

Thank you,

Ian