I work with several maps (in folder named "aa") and the text boxes in the layout view are:
I try to delete,using Arcpy, the empty line in the this text properties box
so my result will be one line only:
By the way, i have also an empty line in this text box:
this is my python code:
import arcpy
from arcpy import env
env.workspace = r"G:\desktop\Project\aa"
for mxdname in arcpy.ListFiles("*.mxd"):
print mxdname
mxd = arcpy.mapping.MapDocument(r"G:\desktop\Project\aa\\" + mxdname)
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
elm.text = elm.text.replace(' ', 'free zn space')
print 'done'
mxd.save()
del mxd
but there no changes in the maps and i get this result:
>>>
landUse.mxd
done
1
>>>
1 Answer 1
What is the name of the text element?
The script you have written does not identify what element needs changing.
I would insert this line to find out what the element names are:
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
print elm.name
Then I would use that to identify which element needs the changing, and then use:
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if elm.name == inset_element_name:
elm.text == elm.text.strip.lstrip()
Please see python text formatting to find out more on how to remove the blank spaces.
mxd
variable. And what if you add a print statement within thefor
loop?