0

I am new in Python scripting. I have a geodatabase with layer Test and this layer has field Name and Text element on layout named TEname. I am trying to show selected feature attribute Name value in Text element, but I could not do it. I can print the value for selected feature, but can't show it in Text element.

Here is the code I use:

import arcpy


mxd = arcpy.mapping.MapDocument("current")
TEname = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","Name")[0]

for row in arcpy.da.SearchCursor("Test","name")
     print row

...
(u'Land plot 1',)

for row in arcpy.da.SearchCursor("Test","name"):
    TEname.text = row

...

        TEname.text = row

Runtime error Traceback (most recent call last): File "", line 1, in File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\arcobjects_base.py", line 89, in _set return setattr(self._arc_object, attr_name, cval(val)) RuntimeError: TextElementObject: Error in setting text

0

2 Answers 2

3

You are trying to assign the row array to the text element, but you want to grab the first (only, in this case) element from the array:

TEname.text = row[0]

-2

As per your description the text element name is "TEname". So, arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","Name")[0] in this line try to replace "Name" by "TEname".

Also for row in arcpy.da.SearchCursor("Test","name"): TEname.text = row
In this try by replacing TEname.text = row to TEname.text=row.getValue("name")

1
  • No, when using DA cursors (which everyone should be at this point), row is an array
    – Vince
    Dec 24, 2018 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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