Changing the properties of a text element in the page layout

3753
1
10-06-2014 08:44 AM
MatteoAlesi
New Contributor

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

0 Kudos
1 Reply
DarrenWiens2
MVP Honored Contributor

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.

0 Kudos