1

I work with several maps (in folder named "aa") and the text boxes in the layout view are:

enter image description here

I try to delete,using Arcpy, the empty line in the this text properties box

enter image description here

so my result will be one line only:

enter image description here

By the way, i have also an empty line in this text box:

enter image description here

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
>>> 
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Oct 13, 2016 at 9:12
1
  • The is a extra backslash in your mxd variable. And what if you add a print statement within the for loop? Commented Oct 13, 2016 at 9:21

1 Answer 1

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.

answered Oct 13, 2016 at 9:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.