1

I am using ArcGIS Pro 1.3.1 and it seems like ArcPy is not always respecting the current setting of the text property for a text element when I export its layout to PDF.

To reproduce this I have created the following test:

  1. Start ArcGIS Pro and create a New project using the Blank template in C:\Temp called TestProject
  2. INSERT a New layout using A5 from the ISO - Landscape category
  3. INSERT a Text element somewhere in the middle of the page.
  4. Leave the text as "Text" but give it a size of 72pt if you want to make it very easy to read.
  5. Save the project and close ArcGIS Pro
  6. Run the Python script below from the IDE of your choice

import arcpy

aprx = arcpy.mp.ArcGISProject("C:\Temp\TestProject\TestProject.aprx")
lyt = aprx.listLayouts("Layout")[0]

for elm in lyt.listElements("TEXT_ELEMENT"):
    elm.text = "TEST1"
lyt.exportToPDF(r"C:\Temp\TEST1.pdf")

for elm in lyt.listElements("TEXT_ELEMENT"):
    elm.text = "TEST2"
lyt.exportToPDF(r"C:\Temp\TEST2.pdf")

I would expect that this would create two PDF files with the text "TEST1" written in the one called TEST1.pdf and "TEST2" written in the one called TEST2.pdf.

Instead what I get is:

  • "TEST1" in TEST1.pdf (as expected)
  • "TEST1" in TEST2.pdf (I suspect that this is a bug)

It seems like the layout object is only allowing this text element to have its text changed once between repeated exports of a layout to PDF.

At the moment I am unable to run the same test using ArcGIS Pro 1.4 (where I am hoping it is fixed), and so I am wondering whether anyone can run it on their version of ArcGIS Pro to confirm whether they can reproduce it?


It seems to be the exportToPDF that "locks" the text value because if the second test below is run "TEST3" gets exported to TEST3.pdf OK, but TEST4.pdf gets "TEST3" instead of "TEST4".

import arcpy

aprx = arcpy.mp.ArcGISProject("C:\Temp\TestProject\TestProject.aprx")
lyt = aprx.listLayouts("Layout")[0]

for elm in lyt.listElements("TEXT_ELEMENT"):
    elm.text = "TEST1"
for elm in lyt.listElements("TEXT_ELEMENT"):
    elm.text = "TEST2"
for elm in lyt.listElements("TEXT_ELEMENT"):
    elm.text = "TEST3"
lyt.exportToPDF(r"C:\Temp\TEST3.pdf")
for elm in lyt.listElements("TEXT_ELEMENT"):
    elm.text = "TEST4"
lyt.exportToPDF(r"C:\Temp\TEST4.pdf")

As a sanity check I ran the ArcMap equivalent test below using ArcGIS Desktop 10.4.1, and that behaved as expected:

import arcpy

mxd = arcpy.mapping.MapDocument(r"C:\Temp\test.mxd")

for elm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT"):
    elm.text = "TEST1"
arcpy.mapping.ExportToPDF(mxd,r"C:\Temp\TEST1.pdf")

for elm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT"):
    elm.text = "TEST2"
arcpy.mapping.ExportToPDF(mxd,r"C:\Temp\TEST2.pdf")

Consequently, the ArcGIS Pro 1.3.1 behaviour mentioned at the beginning is looking more and more like a bug.

  • 1
    This works fine for me in Pro 1.4 (released) and Pro 2.0 (under development) – KHibma Apr 4 '17 at 14:51
  • @KHibma thanks for testing. Its odd at 1.3.1 because I extracted this test from an application that I am writing. Once I made the application slightly more complex this part started working. I'll try the test again today after the machine has been rebooted overnight to see whether it is still reproducible for me at 1.3.1. – PolyGeo Apr 4 '17 at 21:55
  • This is still reproducible at 1.3.1 even after a machine reboot so I think there must have been something astray there. – PolyGeo Apr 4 '17 at 23:08
0

From testing by @KHibma it appears that this problem is non-reproducible at ArcGIS Pro versions

1.4 (released) and ... 2.0 (under development)

Consequently, the solution appears to be to upgrade to at least 1.4.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.