Select to view content in your preferred language

Customizing the title font using ArcPy

160
1
Jump to solution
2 weeks ago
YahyaMasri
New Contributor

Hello I was wondering if someone knows how to customize the title font using ArcPy. This is my current code which was given on ArcPy Documentation under TextElement:

 

txtStyleItem = p.listStyleItems('ArcGIS 2D', 'TEXT', 'Title (Serif)')[0]
ptTxt = p.createTextElement(lyt, arcpy.Point(11, 10), 'POINT', title_text, 6, style_item=txtStyleItem)
ptTxt.setAnchor('Center_Point')
ptTxt.elementPositionX = 8.5
ptTxt.elementPositionY = 10
ptTxt.textSize = 28

The issue is when I try to change 'Serif' to something else like 'Tahoma' I get an error:

In [10]:

Line 48: txtStyleItem = p.listStyleItems('ArcGIS 2D', 'TEXT', 'Title (Tahoma)' )[0]

IndexError: list index out of range

Does anyone know how to use ArcPy to change the font?

 

 

 

 

 

 

0 Kudos
1 Solution

Accepted Solutions
gpopulis
New Contributor II

I'm not 100% confident I understand your question but it looks to me like you're attempting to grab a style item that does not exist in this line:

    Line 48: txtStyleItem = p.listStyleItems('ArcGIS 2D', 'TEXT', 'Title (Tahoma)' )[0]

and then use the "applyStyleItem (style_item)" method to change the text.

If this is the case I'd double check that you have a StyleItem called 'Title (Tahoma)'

If you're just trying to change the font of that text element you can do the same thing by using this:

ptTxt.fontFamilyName = "Tahoma"

 

Systems Analyst II
City of Ventura

View solution in original post

0 Kudos
1 Reply
gpopulis
New Contributor II

I'm not 100% confident I understand your question but it looks to me like you're attempting to grab a style item that does not exist in this line:

    Line 48: txtStyleItem = p.listStyleItems('ArcGIS 2D', 'TEXT', 'Title (Tahoma)' )[0]

and then use the "applyStyleItem (style_item)" method to change the text.

If this is the case I'd double check that you have a StyleItem called 'Title (Tahoma)'

If you're just trying to change the font of that text element you can do the same thing by using this:

ptTxt.fontFamilyName = "Tahoma"

 

Systems Analyst II
City of Ventura
0 Kudos