text property of the text element equal to the value from row in attribute field

Discussion created by ahreis on Dec 10, 2012
Latest reply on Dec 12, 2012 by curtvprice
In ArcMap 10.0, is it possible to access the attributes from a layer to populate the text property of text elements in the map document. Or do you have to be using data driven pages?

I'm trying to do just that. A portion of my code worked, but then I started to receive parsing errors including syntax and attribute errors. It might have to do with the whereclause under the SearchCursor. Perhaps I should set up a definition query based on the route number.

# import arcpy
import arcpy

#Get parameter as text
RtNum = arcpy.GetParameterAsText(0)

#set to current map document
mxd = arcpy.mapping.MapDocument("CURRENT")

# set dataframe to current
df1 = arcpy.mapping.ListDataFrames(mxd,"SurveyMap")[0]
df2 = arcpy.mapping.ListDataFrames(mxd,"InsetMap")[0]

#set current layer
lyr = arcpy.mapping.ListLayers(mxd, "Routes2010_NHigh_Alldata", df1)

# get the reference to the text elements in the map document. I have 14 text elements.
RtNumElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "RTNUM")[0]
CoElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "COUNTY")[0]
LocElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "LOCATION")[0]
DateElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "DATE")[0]
TimeStartElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "TimeStart")[0]
TimeEndElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "TimeStop")[0]
TempStartElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "TempStart")[0]
TempEndElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "TempStop")[0]
RHStartElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "RelHumStart")[0]
RHEndElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "RelHumstop")[0]
WStartElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "WindStart")[0]
WEndElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "WindStop")[0]
SurvElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "Surveyors")[0]
LengthElem = arcpy.mapping.ListLayoutElements (mxd, "TEXT_ELEMENT", "RouteLength")[0]

# create a cursor and or create definition query for SURVEYS All Text Elements
rows = arcpy.SearchCursor("Routes*", "RTNUM = ", "","","","")
row = rows.next()

RtNumElem.text = row.getValue("RTNUM")      
CoElem.text = row.getValue("County")
LocElem.text = row.getValue(???Location???)
DateElem.text = row.getValue(???Start_Date???)
TempStartElem.text = row.getValue(???Start_Temp???)
TempEndElem.text = row.getValue(???End_Temp???)
RHStartElem.text = row.getValue(???Start_Humi")
RHEndElem.text = row.getValue(???End_Humidi???)
WStartElem.text = row.getValue(???Start_Wind???)
WEndElem.text = row.getValue(???End_Wind???)
SurvElem.text = row.getValue(???Surveyor_s???)
LengthElem.text = row.getvalue("Length")

# refresh map

Very new to python, so any help would be greatly appreciated.