1

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

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Dec 24, 2018 at 7:09

1 Answer 1

1

You have set TEname to a list of text element objects when you do this:

TEname = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","Name")

To get a single text element object from that list use an index of 0 on that list:

TEname = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","Name")[0]
answered Dec 24, 2018 at 8:09
0

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.