I am seeing something very unexpected from ArcGIS Pro 1.4.1 when exporting what should be the same PDF from the same ArcPy script and same data using two methods.
- When I run the script from IDLE the title of the map looks like below:
- When I run the same script from an ArcGIS Pro project pane by placing it behind a Python Script Tool (that has no parameters set for test purposes) it looks like below:
The single text element that is displaying CALTON HILLS and SURFACE GEOLOGY in both cases is having its contents set by the line of code below:
elm.text = '<FNT name="Arial" size="24">{0}
<FNT size="14">\n{1} GEOLOGY</FNT></FNT>'.format(mapName,geologyType)
(note that in the text above there is a \n
joining the two lines that is not getting rendered within the question - the Python code is all on one line)
where elm
is a text element object from lyt.listElements("TEXT_ELEMENT")
, mapName
is set to "CALTON HILLS" and geologyType
is set to "SURFACE GEOLOGY".
Where might these three additional characters be coming from, and why would they only manifest themselves when the same script is run on the same data from the ArcGIS Pro custom tool?
My script saves a copy of the APRX used to create the PDF immediately after the PDF is created. The three additional characters are visible in the text element when it is examined in the copy of the APRX, but not in the APRX that is opened at the beginning of the script. Consequently, it does not appear to be the ExportToPDF
that is causing it.
A similar symptom is seen in another place on the same map where different text elements that are putting out longitude/latitude values at the corners of the map face have an A
with a circumflex accent inserted before the degree symbol.
The problem only emerged after a custom font was installed on my machine to support some geological labels like the one circled in red below:
# -*- coding: <encoding name> -*-
. More details here:docs.python.org/3/howto/unicode.html – Aaron♦ May 16 '17 at 3:47sys.version_info[0]
at the beginning of the script so that I can be certain of that. The first line of the script is# -*- coding: utf-8 -*-
so unless the Python script tool ignores that while IDLE does not, or vice versa, the two ways should be running with the same coding set. – PolyGeo♦ May 16 '17 at 4:39# -*- coding: latin-1 -*-
and# -*- coding: Latin-1 -*-
at the top of my script but it gave an I/O Error of Invalid encoding 'Latin-1'. Saving as UTF-8. Consequently, I seem only able to use# -*- coding: utf-8 -*-
. Another machine should become available soon for me to retest and see if it suggests a reinstall of the fonts on my machine may be called for. – PolyGeo♦ May 17 '17 at 0:25