inserting text in map layout

1141
2
Jump to solution
12-05-2012 06:47 AM
DanielAbera
New Contributor III
Hi Guys,

I was wondering if it is possible to insert all possible values of a loop into map layout as a text element. The script I have prints only one value or line. Here is part of my code. Thanks for your help !!

Daniel A.

arcpy.AddMessage('Adding Text Elements...')  arcpy.AddMessage('*************************')  # search input feature rows=arcpy.SearchCursor(inputFc)  # Retrieve the first record from the list row=rows.next()  # set field value list FieldValList = []  # loop through the field ATS while row:       feat=row.shape             total=total+feat.area       ATS = row.getValue("ATS")                             # make sure its unique       if not ATS in FieldValList:                     FieldValList.append(ATS)                                                                                                                                   # next field       row=rows.next()                                                                      # add text elemets to the map layout        for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):           if elm.name == "ATSList":                 elm.elementPositionX = 6.5                 elm.elementPositionY = 1.0                 for ATS in FieldValList:                                elm.text = "Within Theoretical: " + "\n" + ATS
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MathewCoyle
Frequent Contributor
I know there is a better way to do this, I just can't remember what it is. Something like this should get the result you want I believe.

    for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):         if elm.name == "ATSList":             elm.elementPositionX = 6.5             elm.elementPositionY = 1.0             entry = "\r\n".join(FieldValList)             elm.text = "Within Theoretical:\r\n{0}".format(entry)


Edit: Maybe that is better

Edit2: If they are not string values in your list try this.
"\r\n".join(map(str, FieldValList))

View solution in original post

0 Kudos
2 Replies
MathewCoyle
Frequent Contributor
I know there is a better way to do this, I just can't remember what it is. Something like this should get the result you want I believe.

    for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):         if elm.name == "ATSList":             elm.elementPositionX = 6.5             elm.elementPositionY = 1.0             entry = "\r\n".join(FieldValList)             elm.text = "Within Theoretical:\r\n{0}".format(entry)


Edit: Maybe that is better

Edit2: If they are not string values in your list try this.
"\r\n".join(map(str, FieldValList))
0 Kudos
DanielAbera
New Contributor III
Perfect !!!!! This is exactly what I was looking for.

Thanks Mathew.
0 Kudos