I have the following textbox in a layout view:
Is it possible to modify the text through ArcPy?
I made that box as text, and it has no function added to it:
I just want to change the date so that later I can export it as PDF.
I have the following textbox in a layout view:
Is it possible to modify the text through ArcPy?
I made that box as text, and it has no function added to it:
I just want to change the date so that later I can export it as PDF.
It is possible to change the text. Use the ListLayoutElements to find the object you want. Get the text from the element. Find and replace the text, then push the changed text back to the element. Finally refresh the view and save the mxd.
If your textbox is tagged with a name, then finding the correct layout element is easier. I have attached an example where I am running a find and replace on an element names "iso9001"
def updateISO9001(find_text, replace_text):
# create map document object instance
mxd = arcpy.mapping.MapDocument("CURRENT")
mxd.activeView = "PAGE_LAYOUT"
# Build a dictionary of just the TEXT_ELEMENTS
element_dict = {}
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
element_dict[elm.name] = elm
# Is the expected tagged elemnt found
if "iso9001" in element_dict:
# Replace the string
theString = element_dict["iso9001"].text
theString = theString.replace(find_text, replace_text)
element_dict["iso9001"].text = theString
# Refresh the layout so the changes show
arcpy.RefreshActiveView()
# remove map document object instance
del mxd