I would like to create a geoprocessing tool to replace text in Layout view. I have the following code which works fine from within Arcgis Python. However, I need users to input Text, i.e all replacement value should be parameter.
e.g
if ele.text == "Text1":
ele.text = "Parameter set by user"
Here is the code which I got from the net:
import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
eleList = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT")
for ele in eleList:
if ele.text == "Text1":
ele.text = " Vuci"
if ele.text == "Text2":
ele.text = "co100-xxxx"
if ele.text == "Text3":
ele.text = "Viti"
if ele.text == "Text5":
ele.text = "Tai"
arcpy.RefreshActiveView()
print "Script completed"
To add user-defined parameters, you should use the arcpy.GetParameterAsText() function in your code and define parameters in the interface of your script tool. See Setting script tool parameters for a detailed explanation.