Change font in current mxd using python

Discussion created by corea on May 18, 2011
Latest reply on May 20, 2011 by flederfauz

I want to change all the font styles in a number of mxd's from "Lucinda Sans" or whatever the current one is to "Arial" without changing the font size.

I wrote a simple script to find/replace text but can't figure out how to change the font except by adding html code as in the example below (see image as well). But this doesn't change the root font and also I want it to change the font of all text strings in the Text and Legend elements. No need to search/replace any text.

Thanks in advance. Screen capture and Code are below.

N.B. I was also trying to get it export to pdf if the option was on, but this was giving me an index error (code is commented out, the while loop gives the error but the export to pdf works fine).

![enter image description here][1]

    import os, arcpy, arcpy.mapping
    oldText = arcpy.GetParameterAsText(0)
    newText = arcpy.GetParameterAsText(1)
    pdf = arcpy.GetParameterAsText(2)
    # Loop through each text element in the map document
    for textElement in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
        # Check if the text element contains the out of date text
        if textElement.text == oldText:
     # If out of date text is found, replace it with the new text
            textElement.text = '<FNT name="Arial">' + newText + '</FNT>'
    #while PDF = 1:
    # Export the updated map to a PDF
    #path = r'P:\2011\Job_031_TownPlanning_SeriesProduction\Working\draft_output\esri\2\wetland\'
    #arcpy.mapping.ExportToPDF(mxd, newText + "-TownPlanning_Wetlands_Overlay_Ver2.pdf")
    #arcpy.mapping.ExportToJPEG(mxd, outFile)
    #outFile = newText + + ".pdf"
    # Clean up the MapDocument object by deleting it
    del mxd