Select to view content in your preferred language

Change font in layout with arcpy?

878
1
Jump to solution
10-11-2022 08:25 AM
MKF62
by
Frequent Contributor

I have an older script where I set the font of some text on my map layout:

titleItem.text = '<FNT name="Arial" size="' + str(fontSize) + '">' + newTitle + '</FNT>'

 

The code runs fine, all looks good. Now I want to publish it to my server to use as a geoprocessing tool for printing semi-customized maps. I get an error when publishing saying

" Data: <FNT name="Arial" size=", used by Script PrintHabitatMap cannot be copied to the server"

I don't know how to circumvent this error and my searches have revealed nothing about changing the font of dynamic text in a map document. I was able to publish this service back when I was using an earlier version of Server (10.7 I think) and publishing with ArcMap, but now we're on 10.9.1 and using Pro.

I do not allow copying of data to my server (and I'm not going to), but that shouldn't really be the issue here considering that what it is considering to be data isn't actually data.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MKF62
by
Frequent Contributor

ESRI doesn't make it obvious in their documentation (yet) but there are special characters that ArcGIS picks up on and interprets as "data"... in this case it is the '<' character and I also used a placeholder for the '/' character just in case in the end FNT tag ('</FNT>'). Once I used placeholders for these characters, I was able to publish my script successfully. 

The ASCII character code for '<' is 60, so in the script you replace '<' with chr(60). Python has a built-in function called chr() that can interpret this to the correct symbol. I then also used the replace() function to use a placeholder character instead of '/' in my terminating FNT tag. The final code looks like this:

titleItem.text = chr(60) + 'FNT name="Arial" size="' + str(fontSize) + '">' + newTitle + chr(60) + 'xFNT>'.replace('x','/')

 

View solution in original post

0 Kudos
1 Reply
MKF62
by
Frequent Contributor

ESRI doesn't make it obvious in their documentation (yet) but there are special characters that ArcGIS picks up on and interprets as "data"... in this case it is the '<' character and I also used a placeholder for the '/' character just in case in the end FNT tag ('</FNT>'). Once I used placeholders for these characters, I was able to publish my script successfully. 

The ASCII character code for '<' is 60, so in the script you replace '<' with chr(60). Python has a built-in function called chr() that can interpret this to the correct symbol. I then also used the replace() function to use a placeholder character instead of '/' in my terminating FNT tag. The final code looks like this:

titleItem.text = chr(60) + 'FNT name="Arial" size="' + str(fontSize) + '">' + newTitle + chr(60) + 'xFNT>'.replace('x','/')

 

0 Kudos