Hello,
I have just started using Python and I'm trying to create a dynamic table using Data Driven Pages and Python. I'm using data driven pages and have a page definiton query set to display only the points that are within the page index, and only shows those records in the attribute table. I'd like to create a table in my layout that dynamically updates a text element with certain fields from the queried attribute table. So far this is what I have:
import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
rows = arcpy.SearchCursor("DAMS")
row = rows.next()
while row:
stateValue = row.getValue("DAM_NAME")
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if elm.text == "LayoutLegend":
elm.text = (str(stateValue) + "\n")
row = rows.next()
arcpy.mapping.ExportToPDF(mxd, r"C:\Documents and Settings\jquinn\Desktop\Dam Map\trial.pdf")
del mxd
In replaces "LayoutLegend" with the dam name, but it adds the first record in the feature class instead of the records in the queried attribute table. It also doesn't iterate through, adding each record to the text element.
Clearly, the code needs a bit of work, so any help would be greatly appreciated.
Thanks,
Jon