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
>>> 
  • The is a extra backslash in your mxd variable. And what if you add a print statement within the for loop? – GISGe Oct 13 '16 at 9:21
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.