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:
- Start ArcGIS Pro and create a New project using the Blank template in C:\Temp called TestProject
- INSERT a New layout using A5 from the ISO - Landscape category
- INSERT a Text element somewhere in the middle of the page.
- Leave the text as "Text" but give it a size of 72pt if you want to make it very easy to read.
- Save the project and close ArcGIS Pro
- 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.