Is there a way, using ArcPy, to read a field from an attribute table and write the contents of that field into a text element?
I have a point feature class with a field name called "Cities". I will make separate MXDs for different subsections of cities but I would like the contents of the cities field to write into a text element.

Using the following blog, I can write the values to a notepad. But rather than a notepad, can I write them to a text element in the MXD?

  • Are you familiar with the cursor functions? you can use either insert cursor to write directly into a gdb, or you can just easily import the notepad into Arcmap. Just make sure that you use the separator ',' when you write your output to your notepad, as ArcGIS understands CSV's not tab delimited files or space delim files. (from memory I might be wrong) – yanes Jan 28 '16 at 22:55

Yes - you would use an ArcPy Search Cursor to read the value from the attribute table, and then get a TextElement object from the layout in your map so that you can update its text property with that value.

The TextElement object provides access to properties that enable its repositioning on the page layout as well as modifying the text string and font size.


Are you sure you need to code this? It sounds like a great opportunity to use data-driven pages and dynamic text. More specifically, after you follow the instructions on ESRI's site to set up your data-driven map, you can simply insert into any text element: <dyn type="page" property="FieldOfInterest"/>, as seen here.

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.