Wednesday 23 November 2016

pdf - Debugging unexpected characters placed by ArcPy Python script tool in text element of ArcGIS Pro layout?


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 = '{0}
\n{1} GEOLOGY'.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



Answer



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 = '{0}\n\n{1} GEOLOGY'.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)

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...