4

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.

  1. When I run the script from IDLE the title of the map looks like below:

enter image description here

  1. 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:

enter image description here

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 \njoining 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.

enter image description here

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:

enter image description here

  • 1
    It's not an argument between ASCII and Unicode is it? Inserting a unicode char into an ASCII string will create two characters... but I was under the impression that ArcGIS element strings were already unicode so perhaps the problem occurs in the processor between a python ASCII string into unicode Esri string. – Michael Stimson May 16 '17 at 3:18
  • @MichaelMiles-Stimson The problem only emerged after a custom font was added to the machine to support some geological symbols. I'll add some info about this into my question. – PolyGeo May 16 '17 at 3:26
  • I believe ArcGIS Pro uses Python 3. Your IDLE python.exe may be running 2.7. You can change the encoding in Python 3 via # -*- coding: <encoding name> -*-. More details here:docs.python.org/3/howto/unicode.html – Aaron May 16 '17 at 3:47
  • 2
    @Aaron Both ways should be running Python 3.5.2 and I print out sys.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
  • 1
    @MichaelMiles-Stimson I tried using # -*- 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
2

I was unable to track what caused this but I was able to resolve it by doing the following.

Instead of a single text element with:

elm.text = '<FNT name="Arial" size="24">{0}\n<FNT size="14">\n{1} GEOLOGY</FNT></FNT>'.format(mapName,geologyType)

I split the text over two text elements, each with their font and size defined in the project layout so that I could use simpler code instead:

elm.text = mapName

and

elm.text ='{0} GEOLOGY'.format(geologyType)

Fixing the character before the degree symbol took a little more.

Once again I defined their font and size in the project layout and authored

degsº mins'

into the text element. I took care to get the degree symbol using the Windows Start Menu > All Programs > Accessories > System Tools > Character Map to choose the degree symbol from the same font that I set on the text element (Arial).

I then replaced the strings "degs" and "mins" with string values stored in variables of the same name from my script:

elm.text = elm.text.replace("degs",degs).replace("mins",mins)

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.