AnsweredAssumed Answered

Write multiple lines to a text element

Question asked by DaveJordan on Aug 29, 2012
Latest reply on Aug 30, 2012 by DaveJordan
I am writing a script that will produce mailing labels in a layout.  Basiclally, I have 30 text elements (3x10) on a page that I want to populate with the contents from a text file, which is pipe delimited.  For each line in the text file I am breaking out each line for the label using string.split('|').  Now I am stumped on how to write multiple lines of text to a text element in the layout. 

My Question: How can I create new lines to a text element without overwriting the previous line of text?

here is a sample of the first 5 lines of the text file.  The first line is the header, so it gets ignored, the next two lines aren't actual labels but they get printed as if they are.  the last two lines are the actual label material.

OWNER1|OWNER2|MAIL1|MAIL2|CITY_STATE_ZIP5_ZIP4
Dave_Jordan|Page1| | |
|||
BAYVIEW LOAN SERVICING LLC| |895 SW 30 AVE STE 202| |POMPANO BCH FL 33064 0
BUCKSHIN, ROBERT| |4052 FOUNTAIN PALM RD| |COCOA FL 32926 311

# Import arcpy module import arcpy  #Get user supplied parameters fName = arcpy.GetParameterAsText(0) #Dist = arcpy.GetParameterAsText(1) #AppName = arcpy.GetParameterAsText(2)  # Local variables: mxd = arcpy.mapping.MapDocument("Current") mxd.activeView='PAGE_LAYOUT'  arcpy.RefreshActiveView() # Process: arcpy.AddMessage("==============================================") arcpy.AddMessage("Generating mailing labels from "+fName) #if arcpy.Exists(fName): try:  arcpy.AddMessage("Processing file...")  f1 = open(fName,'r')  lines = f1.readlines()  cnt = 0  #Start the count at zero to skip the header line in the text file  for line in lines:   arcpy.AddMessage("----Label "+str(cnt))   for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):    if elm.name == "lbl"+str(cnt):     for val in line.split('|'):      if val != ' ': #Here is where I get stumped.  The AddMessage will print to the screen the way I want to brint to the label...       elm.text = ?????       #arcpy.AddMessage(val)     #elm.text = line   cnt = cnt + 1  f1.close()  arcpy.RefreshActiveView() except Exception, e:  import traceback  f1.close()  map(arcpy.AddError, traceback.format_exc().split("\n"))  arcpy.AddError(str(e))

Outcomes