I'm trying to change the properties of a text element in a page layout through an add-ins button (see the code below), but I get an error message in the Python window
import arcpy
import pythonaddins
class ButtonClass1(object):
"""Implementation for test_addin.button (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
mxd = arcpy.mapping.MapDocument('current')
Ll=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
for elm in Ll:
if elm.text="Text":
elm.text="Text1"
Thanks in advance for any help
Matteo
Please see Posting Code Blocks in the New GeoNet. Posting code blocks properly is especially crucial for indentation problems.
import arcpy import pythonaddins class ButtonClass1(object): """Implementation for test_addin.button (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): mxd = arcpy.mapping.MapDocument('current') Ll=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"): for elm in Ll: if elm.text="Text": elm.text="Text1"
Your error refers to indentation of the Ll line. You can see it's not at the same indentation level as the mxd line (mxd is two spaces ahead of Ll). Make it the same.