Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I need my script to change the font size of a text element if the string is too long to fit in the title section of the map. I've looked into it using Arcpy, but haven't had any luck. Does anyone know how to do this?

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

Code:

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
elmWidth = 4.0
elmText = '<dyn type="document" property="title"/>'
elm = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MapTitle")[0]
x = 100
elm.text = '<FNT name="Arial" size="' + str(x) + '">' + elmText + '</FNT>'
while elm.elementWidth > float(elmWidth):
    elm.text = '<FNT name="Arial" size="' + str(x) + '">' + elmText + '</FNT>'
    x = x - 1
arcpy.RefreshActiveView()
del mxd

Source: (Example 3) http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s30000000m000000.htm

share|improve this answer
    
Thank you so much. Your answer is much better than I was hoping to find. It is exactly what I needed. –  Tanner Sep 5 '10 at 20:33
    
This is great but it is to bad that arcpy does not allow us to actually change the font style just add an html wrapper around it. It could be so much easier if an mxd was plain text like a mapinfo wor file where this kind of edit is easy...i still prefer ArcGIS though :-) –  GeorgeC Nov 6 '11 at 22:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.