Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 8 down vote accepted


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
del mxd

Source: (Example 3)

share|improve this answer

Your Answer


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.