I have created a set of maps using data driven pages that are driven by a layer named "map_frame". I am trying to add text elements that will automatically update based on the attributes of a layer named "Boundaries" that are present within each data driven page. I understand that I can do dynamic text using data driven page attributes, but I need to pull attribute for the text from layers that are not driving the the data driven pages.
I followed the example in this Q/A posted in the community: Extending Dynamic Text
I was able to get the code to work, but the text elements did not update when I would navigate to the next data driven page in the series. I think this is due to the code pulling from the first attribute in the layer's table, but I don't know how to change the given code to adjust for my desired outcome. I'm new to Python and the arcpy.mapping module. Does anyone have any guidance?
# get the reference to the map document and the layer named "Boundaries" in the map document
mxd = arcpy.mapping.MapDocument("CURRENT")
mapLyr = arcpy.mapping.ListLayers(mxd, "Boundaries")
# get the reference to the text elements in the map document. I have 2 text elements with the name ID and county
idElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "ID")
countyElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "County")
# create a cursor and grab the first row in the feature class for the layer specified above
rows = arcpy.SearchCursor(mapLyr.dataSource)
row = rows.next()
# set the text property of the text element equal to the value from the fields named "ID" and "County"
idElem.text = row.getValue("ID")
countyElem.text = row.getValue("County")
# save the map document and delete the reference to the row, cursor and map object
del mxd, row, rows,
@HayleySmith have you looked into setting a "page query" on your data? You'd need a field in the data where the dynamic text is taken from, and identify the pages that those features occur in. Then when you assign dynamic text, it will only display the value of the feature inside each map series.