# 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))
Solved! Go to Solution.
var = "OWNER1|OWNER2|MAIL1|MAIL2|CITY_STATE_ZIP5_ZIP4 \r\nDave_Jordan|Page1| | | \r\n|||\r\nBAYVIEW LOAN SERVICING LLC| |895 SW 30 AVE STE 202| |POMPANO BCH FL 33064 0\r\nBUCKSHIN, ROBERT| |4052 FOUNTAIN PALM RD| |COCOA FL 32926 311" elm.text = var
var = "OWNER1|OWNER2|MAIL1|MAIL2|CITY_STATE_ZIP5_ZIP4 \r\nDave_Jordan|Page1| | | \r\n|||\r\nBAYVIEW LOAN SERVICING LLC| |895 SW 30 AVE STE 202| |POMPANO BCH FL 33064 0\r\nBUCKSHIN, ROBERT| |4052 FOUNTAIN PALM RD| |COCOA FL 32926 311" elm.text = var
for line in lines: for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"): if elm.name == "lbl"+str(cnt): elm.text = line.replace('|','\r\n') cnt = cnt + 1