There is a workaround possible, if you already have got a textbox in your layout.
You can use the .clone()
- function to copy and paste a textbox in your layout.
Now you can change the content with .text
and use .elementPositionX
and .elementPositionY
to move the Textbox to you desired place.
If you need to alter font, font size or else you can use formating tags to do so.
In the example below I also cloned a graphic rectangle and placed it around the new cloned textbox.
import arcpy
inputMap = r"D:\Textboxes.mxd"
outputMap = r"D:\Textboxes2.mxd"
mxd = arcpy.mapping.MapDocument(inputMap)
# get elemets according to element-name
Textorig = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT","Textorig")[0]
Frame = arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT","Frame")[0]
# clone elements
Textorig.clone("_copy")
Frame.clone("_copy")
# alter elements
Textorigcopy = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT","Textorig_copy")[0]
Textorigcopy.text = '<FNT size = "36"><CLR red = "255"><BOL><ITA>New Text</ITA></BOL></CLR></FNT>'
Textorigcopy.elementPositionX = 6.8883
Textorigcopy.elementPositionY = 21.6488
Framecopy = arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT","Frame_copy")[0]
Framecopy.elementPositionX = 6.7135
Framecopy.elementPositionY = 21.5169
Framecopy.elementWidth = 6.1354
Framecopy.elementHeight = 1.7808
mxd.saveACopy(outputMap)
del mxd
