6

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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Sep 4, 2010 at 23:54

1 Answer 1

8

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

answered Sep 5, 2010 at 2:51
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.