adgriffith

Data Driven Page Text Element

Discussion created by adgriffith on Mar 20, 2013
Latest reply on Mar 23, 2013 by adgriffith
I'm using a combination of data driven pages and a python script to populate text elements on a layout. I have a project set up with an index layer, and a mask layer.  I also have a third layer (permits), which I have set up as a page definition query, to match the index layer selected (they both have a map_number field). This works as I scroll through the pages, the permits layer updates to show only those permits within the active page.  I would like for those queried permits to then populate a table made up of two text elements.

Now, when I run though the script, the text elements are populated but not with correct information.  As I change pages, and the queried permits change, I cannot get the related text elements to change/update.  All the rows will show in the text element(s), and not the queried ones only. What am I missing here?  I'm not sure if it is a definition query problem or a cursor problem (or neither of these)? 

Code:

import arcpy

# get the reference to the map document
mxd = arcpy.mapping.MapDocument("Current")

#Reference appropriate data frames
operationsDF = arcpy.mapping.ListDataFrames(mxd, "Operations")[0]
locatorDF = arcpy.mapping.ListDataFrames (mxd, "Locator Map")[0]

#Reference appropriate data layers
mapLyr = arcpy.mapping.ListLayers(mxd, "Permits_final", operationsDF)[0]

# get the reference to the text elements in the map document.
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
    if elm.name == "FacNameelem": FacNameelem = elm
    if elm.name == "Stateelem": Stateelem = elm

#Clear all text element values
FacNameelem.text = ' '
Stateelem.text = ' '

# create a cursor and grab the rows in the feature class for the layer specified above
rows = arcpy.SearchCursor(mapLyr.dataSource)
row = rows.next()
text1Value = ""
text2Value = ""
for row in rows:
    text1Value +=row.getValue("FACILITY") +"\n"   
    FacNameelem.text = text1Value
    text2Value +=row.getValue("State") +"\n"
    Stateelem.text = text2Value
            
#Refresh map
arcpy.RefreshActiveView()
 
# save the map document and delete the reference to the row, cursor and map object
mxd.save()
del mxd, row, rows

Outcomes